Ubuntu – Using rsync with exclude/include

rsyncserver

I'm running 2 ubuntu 9.10 servers. I have to synchronize the changes between these two machines. The following are the directories I've to synchronize:

/usr, /etc, /var, /bin, /sbin, /lib

I'm using rsync like the below for replication:

rsync -avP 192.168.2.100:/usr/ /usr

rsync -avP 192.168.2.100:/etc/ /etc ——here I'll have to exclude many files like /etc/udev/*, /etc/hosts, /etc/hostname,…

I tried using rsync -avP --exclude '/etc/fstab' 192.168.2.100:/etc/ /etc but it overwritten entire /etc directory

Can any one edit and give me rsync to one line command which synchronizes specified directories and not which are excluded?. Need help!

Best Answer

The exclude pattern is relative to the source files, not the destination files. You're actually excluding 192.168.2.100:/etc/etc/fstab, which does not exist.

You should use:

rsync -avP --exclude '/fstab' 192.168.2.100:/etc/ /etc
Related Question