Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get rsync to exclude any directory named cache?

I'm new to rsync and have read a bit about excluding files and directories but I don't fully understand and can't seem to get it working.

I'm simply trying to run a backup of all the websites in a server's webroot but don't want any of the CMS's cache files.

Is there away to exclude any directory named cache?

I've tried a lot of things over the weeks (that I don't remember), but more recently I've been trying these sorts of things:

sudo rsync -avzO -e --exclude *cache ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

and this:

sudo rsync -avzO -e --exclude cache/ ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

and this:

sudo rsync -avzO -e --exclude */cache/ ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

and this:

sudo rsync -avzO -e --exclude *cache/ ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

Sorry if this is easy, I just haven't been able to find info that I understand because they all talk about a path to exclude.

It's just that I don't have a specific path I want to exclude - just a directory name if that makes sense.

like image 301
CMSCSS Avatar asked Oct 16 '11 23:10

CMSCSS


People also ask

How do I exclude in rsync?

Exclude Files and Directories from a List. When you need to exclude a large number of different files and directories, you can use the rsync --exclude-from flag. To do so, create a text file with the name of the files and directories you want to exclude. Then, pass the name of the file to the --exlude-from option.

How does rsync exclude work?

The --exclude-from rsync option allows us to specify a file that contains a list of directories to be excluded. The file should be plaintext, so a simple . txt file will do. List one directory per line as you're compiling the list of directories that you want to exclude.

Does rsync use Gitignore?

gitignore files happen to use a syntax compatible with rsync .

Does rsync Skip existing files?

Rsync with --ignore-existing-files: We can also skip the already existing files on the destination. This can generally be used when we are performing backups using the –link-dest option, while continuing a backup run that got interrupted. So any files that do not exist on the destination will be copied over.


1 Answers

rsync --exclude cache/ ....

should work like peaches. I think you might be confusing some things since -e requires an option (like -e "ssh -l ssh-user"). Edit on looking at your command lines a little closer, it turns out this is exactly your problem. You should have said

--exclude cache/ -e ssh

although you could just drop -e ssh since ssh is the default.


I'd also recommend that you look at the filter rules:

rsync -FF ....

That way you can include .rsync-filter files throughout your directory tree, containing things like

-cache/

This makes things way more flexible, make command lines more readable and you can make exceptions inside specific subtrees.

like image 141
sehe Avatar answered Sep 22 '22 13:09

sehe