Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent rsync from deleting destination files that match a given pattern

Tags:

unix

rsync

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?

like image 906
turtle Avatar asked Sep 26 '13 09:09

turtle


People also ask

How do I use rsync without deleting destination files?

In its simplest form, the rsync command will copy files from the file source to the file destination. It will not remove files on the destination side that aren't on the source and it won't recreate all of the metadata (e.g., ownership and group details) unless your rsync command includes just the right set of options.

Does rsync delete files at destination?

File Syncing and Mirror Backup To do that you want files on the target destination side to be deleted if they do not exist at the source. To do this you simply add the --delete option to rsync. Now any files under /target/dir/copy that are not also present under /source/dir/to/copy will be deleted.

How do I ignore files 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.


1 Answers

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

rsync -avrc --delete --exclude somedir source destination 
like image 56
kielni Avatar answered Oct 01 '22 13:10

kielni