9

I want to rsync with the delete option so that the folders remain identical copies, also after I have deleted files and folders from the source.

The problem is there might be something on the destination folder that isn't meant to be deleted. In that case, what I would like to happen is that rsync deletion proceeds but the files that are to be removed actually get stored in some garbage folder instead of being removed from the filesystem.

That way I could maintain identical folders without the fear of accidentally overwriting something.

How would it be best to go about achieving such a functionality?

0

1 Answer 1

15

You want the -b option (which causes rsync to backup deleted stuff) combined with the --backup-dir option, which will let you direct WHERE rsync backs things up.

4
  • I am trying to get this to work. For some reason the deletion doesnt go into the rsync_garbage directory. Can you see whats wrong with it? rsync -az --backup-dir='/media/somefolder_a/rsync_garbage' --delete /home/username/a user@ip_address:/media/somefolder_a/
    – john-jones
    Nov 13, 2017 at 13:00
  • 5
    I don't see the -b option in there. --backup-dir is used to modify the behavior of -b, it doesn't turn -b on by itself. Try -abz. Nov 13, 2017 at 13:09
  • --backup-dir with a specified backup directory will preserve deleted files in the backup directory. The manual says --backup-dir implies the -b option, so -b doesn't need to be present. I'm using rsync 3.1.3.
    – user258532
    Dec 1, 2019 at 17:54
  • 1
    It would be worth noting that the --backup-dir path is with respect to the destination folder and not the current directory.
    – Noah May
    Jan 25, 2022 at 22:53

You must log in to answer this question.

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