2

I have a backup routine that runs for Wordpress sites. There are folders created which are dynamic per installation of Wordpress. I cannot, for the life of me, figure out how to exclude the dynamic folder.

The convention for the dynamic folders are as follows:

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

The dynamic portions are backupwordpress-aaa1b23456-backups and backupwordpress-ccc7d89012-backups.

I have tired all of the following combinations, and none of them exclude the backupwordpress-*-backups folder.

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

Here is my version:

tar (GNU tar) 1.29

What am I doing wrong? Thanks!

  • Maybe just --exclude="backupwordpress-*-backups"? If those are the only directories with that sort of name, that ought to match. This would be easier than trying to get the path right. Also, I would put --exclude before the pathname of the directory you're archiving (although since you're using GNU tar, I suppose it doesn't matter since GNU utilities tend to reorder the command line arguments, for convenience). – Kusalananda Nov 19 '19 at 17:01
  • The exclusion works for me (on an older tar version) when I use either --exclude='*/backupwordpress-*-backups' or a relative path --exclude='var/www/client1/public_html/wp-content/backupwordpress-*-backups'; I wonder if, when tar strips the leading /, it stops matching your fully-qualified exclusion pattern? – Jeff Schaller Nov 19 '19 at 17:02
  • Related: unix.stackexchange.com/a/450154/117549: "It seems that the --exclude option only applies to paths listed after it on the command line" – Jeff Schaller Nov 19 '19 at 17:02
  • @JeffSchaller Both of these variations work. I must have made a typo or failed to test since this example was covered in my description. The position of the exclude was important. tar zcpf client1.tgz --exclude="/var/www/client1/public_html/wp-content/backupwordpress-*-backups" /var/www/client1 or tar zcpf client1.tgz --exclude="var/www/client1/public_html/wp-content/backupwordpress-*-backups" /var/www/client1 – BrianJM Nov 19 '19 at 18:25
  • @Kusalananda You were right about the position of the --exclude. See my comment immediately above. – BrianJM Nov 19 '19 at 18:27
0

I must have made a typo or failed to test completely, since the example/note that @JeffSchaller provided was covered in my description. The position of the exclude is important.

These two variations work for me in 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.