Prevent rsync from deleting destination files that match a given pattern

turtle picture turtle · Sep 26, 2013 · Viewed 30.6k times · Source

I'm using rsync to sync files from a source to a destination:

rsync -av --delete source destination

I have a single directory on the destination side which is not on the source side. I'd like to prevent rsync from deleting this directory. Is there an option I can pass to rsync to prevent this directory from being deleted upon sync?

Answer

kielni picture kielni · Sep 26, 2013

You can exclude files/directories with --exclude. This will prevent the somedir directory from being synced/deleted:

rsync -avrc --delete --exclude somedir source destination