rsync home dirs but exclude sub paths

A 5 star hangout for overworked and underpaid system admins.
Post Reply
KernelOops
Posts: 61
Joined: 2013/12/18 15:04:03

rsync home dirs but exclude sub paths

Post by KernelOops » 2019/01/22 17:26:27

Hello everyone,

I'm using several CentOS 7 systems to backup home directories. Essentially, I use the following command:

Code: Select all

/usr/bin/rsync -tarlzvh -P --delete --exclude='tmp/*' /home/ 192.168.1.1::home
It works fine and the --delete parameter ensures the remote hasn't got any stale files left over from previous rsyncs. Unfortunately, that is also the problem, I want to exclude some specific directories from being part of the --delete parameter.

For example
/home/user/files/
/home/user/files/images (always keep remote files)
/home/user/data/
...etc..

How would I exclude /home/*/files/images/ from the --delete parameter?

I'd appreciate some help.

Thank you.

stevemowbray
Posts: 477
Joined: 2012/06/26 14:20:47

Re: rsync home dirs but exclude sub paths

Post by stevemowbray » 2019/01/23 11:13:26

Do one rsync without the --delete option, then another with the --delete option but this time use --exclude for the directories you want to exclude?

pjsr2
Posts: 433
Joined: 2014/03/27 20:11:07

Re: rsync home dirs but exclude sub paths

Post by pjsr2 » 2019/02/06 13:54:32

On the rsync command line, use the --include option to specify the directories that you want to include before the --exclude option to exclude the directories you do not want to rsync. When multiple rules are defined, rsync uses the first matching rule.

See the section on "Filter Rules" in man rsync.

Post Reply

Return to “CentOS Social”