I've got two backup directories that live on the same filesystem on my backup server. The first is called "clone" - it contains a clone of my laptop that is remotely updated nightly via rsync. The second is called "backup", which is a weekly rsync snapshot of only the important parts of clone. To save space, "backup" is created as hard links to clone instead of copies, using --link-dest:

rsync -avum --link-dest=/clone /clone/ /backup

Now I want to also use the --backup option to copy the old versions of changed files from backup to a holding area, in case I need them or accidentally delete something important. This works fine without --link-dest:

rsync -avumb --backup-dir=/holding/2016_10_22 /clone/ /backup

However, this creates copies of the changed files in backup, wasting space - I want hard links. But if I add the --link-dest parm back in:

rsync -avumb --backup-dir=/holding/2016_10_22 --link-dest=/clone /clone/ /backup

...then only deleted files are backed up. Changed files are silently hard linked. The reason (I believe) is that --link-dest shares the logic of --copy-dest. I.e., if the source file is unchanged relative to the copy-dest (or link-dest) file, then it is not transferred, but instead copied/linked from the copy/link-dest dir to the target dir. Because I'm using the source dir as the link-dest dir, all non-deleted files are "unchanged", and handled silently.

I could do this in two steps: first --backup without --link-dest, then again --link-dest without --backup. (Newer versions of rsync will replace identical files with hard links.) But I'd really prefer to do it all at once.

Is there a way of doing --backup while only creating hard links? (Really what I want is "regular" rsync with hard linking instead of file transfer. My use of --link-dest seems like a bit of a hack, given the intended logic of that option.)

Bonus question: the man page seems to indicate that using --link-dest only on empty targets is preferred:

This option works best when copying into an empty destination hierarchy, as existing files may get their attributes tweaked, and that can affect alternate destination files via hard-links. Also, itemizing of changes can get a bit muddled.

The bit about itemizing getting "muddled" is a bit vague. Is using --link-dest on a non-empty target really "dangerous", assuming I don't care too much about file attributes? Can anyone give an example?

  • Can't really help you, but if you don't get an answer, check out rsnapshots config and code, you might find inspiration there. – Jakob Lenfers Oct 23 '16 at 8:47
  • In case anyone finds it useful - I ended up writing my script to do it in two separate rsync calls, as mentioned above. – meeotch Nov 23 '16 at 7:18

Your Answer

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

Browse other questions tagged or ask your own question.