2

I want rsync to:

  • Copy all files from source to destination
  • If a file does not exist anymore in the source, delete it from the destination, EXCEPT for some specific files

And I need to list the exceptions in a separate file, like I can do with the --exclude-from option.

Is this possible?

2 Answers 2

1

I'm not sure if you can have a file list in exclude option but you can try this:

$ rsync -avz --exclude delete_file_1.php --exclude dir_1/file4.txt \
     directory_source/ directory_destination/

or you can:

$ rsync -avz --exclude 'dir_1/dir_2/file_3.php' source/ destination/

or you can:

$ rsync -avz --exclude 'dir*' <-- wildcard match here

If I were you I'd create test folders to be synced to remote destination and see how it works out. As long as you have the exclude option correct you can manipulate it to exclude plenty of files.

1
  • If I understand correctly this will not sync the files passed to --exclude. I need it to always sync all the files, and delete files that were removed from the source, except if the file is specified in a list. In other words, always sync everything, but never delete some specific files from destination. Thanks. Commented Oct 2, 2014 at 1:22
0

Apparently this is only possible if we run rsync 2 times, like this:

rsync -a source/ dest
rsync -a --exclude-from=files.txt --delete source/ dest

Where files.txt contains the files we don't want to delete.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.