8

I use rsync to back up large hard drives on a remote machine. By default, rsync does not delete files on the remote machine when they no longer exist on the local machine. This is useful, because it makes it possible to recover, e.g., if I want to restore a file which was deleted by mistake, and it also means that I don't need to worry about rsync'ing an empty directory (if the hard drive dies or is not mounted). The problem is that it takes lots of disk space on the remote host, and also that if I need to restore a backup it will be polluted with these deleted files.

The alternative is rsync --delete, but then it means that files that have been deleted will also get deleted the first time I run the backup, and if the mountpoint ever becomes empty then I risk deleting the backup as well.

Ideally I would like to have a way to tell rsync to do like --delete, but instead of deleting files, it could move them to a different backup hierarchy. That way, I could still restore these files if I wanted, and I could clean up the larger files in that second hierarchy to save space, while the main backup hierarchy would be a clean back-up of my drive.

Is there a way to emulate this behavior? (or some similar behavior)

(I don't have enough disk space to maintain two complete backups on the remote host. Also, I know about the existence of incremental backup tools like Borg Backup, but I'd like a solution that doesn't rely on heavy tools with a custom storage format. I'm also a bit wary of solutions using hard links but I'm OK with them if it's the best option.)

5
  • Curious to know why you're worried about hard links. Also, have you looked at rsnapshot?
    – roaima
    Feb 14, 2017 at 21:55
  • 1
    I'm worried about hard links because when moving/copying files around (e.g., with cp, rsync, etc.) they sometimes get duplicated to different files. rsnapshot looks interesting -- I was just trying to see for now whether my rsync-based solution could be improved easily. Thanks for the suggestion!
    – a3nm
    Feb 14, 2017 at 23:05
  • Did you find something that works? I'm trying to find a way to create snapshots of my external drive. Jun 10, 2020 at 2:08
  • @SkeletonBow there's an answer below. In fact, I didn't end up testing it so I can't comment on its effectiveness.
    – a3nm
    Jun 10, 2020 at 7:38
  • My bad, I was talking about rsnapshot. I'm using the answer below but was hoping for something more "snapshot" like. But thanks! Jun 10, 2020 at 8:35

1 Answer 1

9

You can use --backup

-b, --backup With this option, preexisting destination files are renamed as each file is transferred or deleted.

in combination with --backup-dir

--backup-dir=DIR In combination with the --backup option, this tells rsync to store all backups in the specified directory on the receiving side. This can be used for incremental backups.

to keep a copy of any modified and removed files in a separate directory, on a receiving side.

If you want to only keep the deleted files in the backup, you can separately purge the updated files after the sync (e.g. like this).

1
  • Argh, I had looked at the manpage, but somehow I had missed that option... Thanks a lot!
    – a3nm
    Feb 14, 2017 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.