Tar:排除具有动态名称的文件夹(使用通配符)

Tar:排除具有动态名称的文件夹(使用通配符)

我有一个针对 Wordpress 站点运行的备份例程。每个 WordPress 安装都会创建动态的文件夹。我一生都无法弄清楚如何排除动态文件夹。

动态文件夹的约定如下:

/var/www/client1/public_html/wp-content/backupwordpress-aaa1b23456-backups
/var/www/client2/public_html/wp-content/backupwordpress-ccc7d89012-backups

动态部分是backupwordpress-aaa1b23456-backupsbackupwordpress-ccc7d89012-backups

我已经厌倦了以下所有组合,并且没有一个排除该backupwordpress-*-backups文件夹。

tar zcpf client1.tgz /var/www/client1 --exclude="./public_html/wp-content/backupwordpress-*"
tar zcpf client1.tgz /var/www/client1 --exclude="./public_html/wp-content/backupwordpress-*/"
tar zcpf client1.tgz /var/www/client1 --exclude="./public_html/wp-content/backupwordpress-*-backups"
tar zcpf client1.tgz /var/www/client1 --exclude="./public_html/wp-content/backupwordpress-*-backups/"
tar zcpf client1.tgz /var/www/client1 --exclude="./public_html/wp-content/backupwordpress-*/*"
tar zcpf client1.tgz /var/www/client1 --exclude="./public_html/wp-content/backupwordpress-*-backups/*"
tar zcpf client1.tgz /var/www/client1 --exclude="/var/www/client1/public_html/wp-content/backupwordpress-*"
tar zcpf client1.tgz /var/www/client1 --exclude="/var/www/client1/public_html/wp-content/backupwordpress-*/*"
tar zcpf client1.tgz /var/www/client1 --exclude="/var/www/client1/public_html/wp-content/backupwordpress-*-backups"
tar zcpf client1.tgz /var/www/client1 --exclude="/var/www/client1/public_html/wp-content/backupwordpress-*-backups/*"
tar zcpf client1.tgz --exclude="./public_html/wp-content/backupwordpress-*" /var/www/client1
tar zcpf client1.tgz --exclude="./public_html/wp-content/backupwordpress-*/" /var/www/client1
tar zcpf client1.tgz --exclude="./public_html/wp-content/backupwordpress-*-backups" /var/www/client1
tar zcpf client1.tgz --exclude="./public_html/wp-content/backupwordpress-*-backups/" /var/www/client1
tar zcpf client1.tgz --exclude="./public_html/wp-content/backupwordpress-*/*" /var/www/client1
tar zcpf client1.tgz --exclude="./public_html/wp-content/backupwordpress-*-backups/*" /var/www/client1
tar zcpf client1.tgz --exclude="/var/www/client1/public_html/wp-content/backupwordpress-*" /var/www/client1
tar zcpf client1.tgz --exclude="/var/www/client1/public_html/wp-content/backupwordpress-*/*" /var/www/client1
tar zcpf client1.tgz --exclude="/var/www/client1/public_html/wp-content/backupwordpress-*-backups" /var/www/client1
tar zcpf client1.tgz --exclude="/var/www/client1/public_html/wp-content/backupwordpress-*-backups/*" /var/www/client1

这是我的版本:

tar (GNU tar) 1.29

我究竟做错了什么?谢谢!

答案1

我一定是写错了或者没有完全测试,因为@JeffSchaller 提供的示例/注释我的描述中已涵盖。排除的位置很重要。

这两种变体对我有用tar (GNU tar) 1.29

tar zcpf client1.tgz --exclude="/var/www/client1/public_html/wp-content/backupwordpress-*-backups" /var/www/client1
tar zcpf client1.tgz --exclude="var/www/client1/public_html/wp-content/backupwordpress-*-backups" /var/www/client1

相关内容