Linux – rsync –include-from & delete = extra files removed

linuxrsync

I have 2 dirs: src and dst. Src contains only 1 file "index.php". Dst contains "index.php" AND "readme.txt". I also have a list.txt file, which contains only one line: "index.php".

Now, being in the directory that contains both src and dst, I execute the following command:

rsync -av --include-from=list.txt src/ dst/ --del  

It updates the "index.php" file if it needs to, BUT it also deletes readme.txt.

Why does it delete it, if it's not in the list.txt file? Any simple way to "fix" this behavior?

What I basically want is to make rsync only care about the files from the list. They can either need updating or deleting (thus the –del option), but I don't want it to touch other files.
I can't use the "–files-from" option because it doesn't delete files in the destination.

EDIT:
"index.php" was just an example here – in fact too simple example, because src and dst may contain whole directory trees, so if list.txt has an entry like "abc/test.php" it should also work for this file.

Best Answer

The solution is to add --exclude=*:

 rsync --verbose  -r --del --include-from=list.txt --exclude=* src/ dst/

Will update only files from list.txt and delete from dst only if they are absent in src and are included in list.txt.