0

I have the following rsync command to create backup and I want to exclude cache folder from the website:

rsync -aAXv --delete --exclude-from='/usr/local/maxicron/rsync/conf/exclude.txt' /home/admin/domains/server.com/public_html /backup/rsync/local

To demonstrate, the content of the exclude.txt is just one line

/home/admin/domains/server.com/public_html/var/cache/*

The command works by creating the backup from public_html but I still get the cache folder created in the backup file at /backup/rsync/local. The expected result is the folder cache shouldn't have any contents in it.

I read somewhere that the exclude-from command would use the absolute path from the source backup. So I also changed this exclude line from

/home/admin/domains/server.com/public_html/var/cache/*

to this

/var/cache/*

or

var/cache/*

or

./var/cache/*

But none of them are working and I still get the cache folder created. Also there is no error. Any idea?

2 Answers 2

2

According to man pages two asterisks (/var/cache/**) might help you if the cache folder contains subfolders:

a * matches any path component, but it stops at slashes.

use ** to match anything, including slashes.

4
  • I tried both of this /var/cache/** and with the full path /home/admin/domains/server.com/public_html/var/cache/**, it still creating the cache folder with the contents. When I do ls /backup/rsync/local/public_html/var/cache/ I still see the cache contents here. Before running the rsync command, I removed the backup folder to test rm -rf /backup/rsync/local/*
    – MaXi32
    Jul 27, 2020 at 13:01
  • Ok. I solved this. I add another option called --relative and it solved the issue. Also it doesn't matter whether I use * or **. Both are working fine.
    – MaXi32
    Jul 27, 2020 at 13:42
  • I upvoted this answer not because it's working but because you mentioned about that asterisks thing
    – MaXi32
    Jul 27, 2020 at 14:33
  • and maybe that asterisks thing is useful in another cases but in this case I don't see any effects.
    – MaXi32
    Jul 30, 2020 at 7:48
1

I'm not sure why the absolute path declared in the text file doesn't work. So, I added another option called --relative to the rsync like this and I leave the path to be relative path inside that text file:

It works like this:

rsync -aAXv --relative --delete --exclude-from='/usr/local/maxicron/rsync/conf/exclude.txt' /home/admin/domains/server.com/public_html /backup/rsync/local
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .