如何根据文件名tar个文件?

How to tar files based on the file name?

/var/log中有如下文件:

cron
cron-20200322
maillog-20200329
tallylog
bootscan.log
bootscan.log-20200115.gz
bootscan.log-20200116.gz

我想备份文件:cron;cron-20200322;bootscan.log;bootscan.log-20200115.gz;bootscan.log-20200116.gz单个文件/mnt/log_backup.tar
然后,我编写 bash shell 脚本如下:

#!/bin/bash
backup_dir='/mnt'
tar -cpf $backup_dir/log_backup.tar -C /var/log cron*
tar -cpfr $backup_dir/log_backup.tar -C /var/log boot*

遗憾的是,我收到如下错误:

tar: cron*: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
tar: Removing leading `/' from member names
tar: boot*: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

我的 shell 脚本有什么问题?

在将文件夹更改为 /var/log 之前评估 * 的通配符。

勾选How to make tar globbing work with the 'change directory' option

find . /var/log -maxdepth 1 -type f -name "boot*" -print0 | tar -cpf  $backup_dir/log_backup.tar --null -T -
find . /var/log -maxdepth 1 -type f -name "cron*" -print0 | tar -rpf  $backup_dir/log_backup.tar --null -T -

我认为这是正确答案,但可能不是最佳答案。
如果有更好的解决方案,请贡献你2美分,thks!