Prevent rsync from deleting destination files that match a given pattern
You can exclude files/directories with --exclude. This will prevent the somedir directory from being synced/deleted:
rsync -avrc --delete --exclude somedir source destination
As mentioned in a similar question, this can be accomplished by using the --filter
option with protect
rule:
$ rsync ... --filter 'protect /remote-directory-to-keep/' ...
Unlike the currently accepted answer, using --filter
is useful, for instance, if you also wish to use --exclude
with --delete-excluded
.