2

I've read several threads on this issue, but the commands stated there didn't work for me still.

I'm trying to rsync files from folder1 (containing sub-folder a ) to folder2 (containing a and b ) without having the folder b deleted. Yet the following command deletes it:

rsync -av --exclude folder2/b/ --delete folder1/ folder2/

Other variations like absolute paths or slashes, no slashes didn't work either. And that eventhough it should be basically the same command (except for the folder-names) as in this thread.

Anyone got an idea?

2 Answers 2

4

In the exclude option, just providing b is sufficient.

Could you try the following command which is working correctly for me.

rsync -av --exclude b --delete folder1/ folder2/

edit: To be safe the -n option is very helpful. It does a dry run of what would be added and deleted.

2
  • Yes, that was it! Thanks! I understand my mistake now. The 'root-directory' of rsyncing was not the folder-level where I issued the command but the level of the parameters (i.e. the '/' in of 'folder1/' and 'folder2/')? Thanks a ton! Though why didn't it work when issued absolute paths? Like 'rsync -nav --exclude /home/steff/folder2/b --delete /home/steff/folder1/ /home/steff/folder2/' also deletes 'b' again. Perhaps because rsync interprets the folder to be excluded as: '/home/steff/folder2/*/home/steff/folder2/b*' ?
    – Steff
    Sep 24, 2015 at 9:32
  • Yeah, tested it. The folder stated after '--exclude' is always relative to the folder to be rsynced.
    – Steff
    Sep 24, 2015 at 9:44
0

I would not try to avoid a delete in that way. Instead, I would rsync the child folders. So to copy a and avoid touching b, I would do something like:

rsync -av --delete folder1/a folder2/a

Repeat for all the necessary folders.

2
  • That would work, but since it's about migrating a huge root-directory, it's more convenient to state the folder on the destination-side which should be excluded. Thanks though!
    – Steff
    Sep 24, 2015 at 9:45
  • Yeah, with a script, you could generate all the lines when comment out those you don't want to copy. I just find the delete option of rsync rather dangerous, especially if you do not have another copy of the data... Sep 24, 2015 at 9:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .