2

I'm using Rsync as a backup tool. When I create a new backup, I would like it to look in all the existing backup folders for each file and if it already exists, create a hard link.

From the Rsync man page,

Beginning in version 2.6.4, multiple --link-dest directories may be provided, which will cause rsync to search the list in the order specified for an exact match.

I could create a list with all my backup folders and pass the list to --link-dest, however I suspect that there must be a better solution.

Can I use a wildcard in the DIR argument of --link-dest? (I tried * but it didn't work).

Can I make --link-dest search for files recursively? I tried setting DIR to my top backup folder and using --recursive, but it didn't find the files and it created a new file instead of a hard link.

1 Answer 1

4

I believe you need --link-dest=$item for each item of your list of backup directories.

If you want those --link-dest= arguments generated from a glob, you can do:

 printf ' --link-dest=%q ' *
3
  • Thanks, that command helps, but I cannot make it work when my link-dest folder is in a remote location.
    – Katu
    Commented Aug 13, 2016 at 20:51
  • 1
    @try can you do something like ssh remote sh -c ":; cd target_directory; printf ' --link-dest=%q ' *" to generate the the arguments? Commented Aug 13, 2016 at 21:13
  • It's worth noting that multiple --link-dest stops on the first found file. Imagine you backup a file, then modify the file, then backup again, then undo the modification and backup a third time so that the first an third backups are the same. You wll get three files, not two: the first and third won't be hard-linked even though they are the same.
    – starfry
    Commented Sep 20, 2016 at 15:01

You must log in to answer this question.

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