I am using rsync to create backups of my website. I would like to use --link-dest to link to older backups and reduce the storage required, so duplicate unchanged files aren't stored multiple times.

I have tried several different path combinations, trying to make sense of the documentation. From what I can understand, the first path needs to be the full relative path from where the script file executes. The last path, is just the destination folder name without a path?

--link-dest=DIR This option behaves like --copy-dest, but unchanged files are hard linked from DIR to the destination directory. The files must be identical in all preserved attributes (e.g. permissions, possibly ownership) in order for the files to be linked together. An example: CW rsync -av --link-dest=$PWD/prior_dir host:src_dir/ new_dir/

I'm obviously not making sense of this correctly, as everything I try fails, with a full duplicate of the files being created.

Here is an example of what I have currently:

rsync -zavx -e 'ssh -p22' \
    --numeric-ids \
    --delete -r \
    --link-dest=../backups/websites/testsite.co.uk/17-06-2018/ [email protected]:~/public_html 18-06-2018/;

Is anyone able to clarify what the paths should be.

The script .sh file is located in on my computer at:


Then the full paths to my directories are:


Any help with direction would be appreciated.

  • 1
    from the man page: If DIR is a relative path, it is relative to the destination directory. Your dest dir is 18-06-2018 so ../ is testsite.co.uk, and there is no backups/... there. Use an absolute pathname in link-dest to avoid any ambiguity.
    – meuh
    Commented Jun 18, 2018 at 9:38
  • "Is anyone able to clarify what the paths should be. " - does that command work with your paths? What is the error? "The script .sh file is located in on my computer" - so probably there is no need in that. Let us discuss just the rsync command. Commented Mar 5, 2020 at 10:27

1 Answer 1

rsync -av --link-dest=/path/to/previous/backup/ source/ /path/to/this/backup/

In your case, change source/ to [email protected]:public_html/ (note that ~ is probably not needed and that there should be a / at the end), and then use the absolute paths on the local machine, if possible. Using absolute paths allows you to run the command without caring too much about from what directory you run it.

-e 'ssh -p22' is used by default, so you don't need it, and -r is included in the -a option.

  • Thank you. The rsync is now very fast, so it looks as if the files are just being copied from the old backup, but it is still making a duplicate copy of all files. Is this correct?
    – ccdavies
    Commented Jun 18, 2018 at 10:09
  • If you look in the target directory with ls -l, you will notice that the link count for the unchanged files will be greater than one. The link count is the number in the second field, before the username in the ls -l output. The files are hard linked, meaning you now have multiple pathnames for exactly the same data.
    – Kusalananda
    Commented Jun 18, 2018 at 10:18
  • The following is returned: drwxr-x--- 15 username staff 510 18 Jun 11:07 public_html. Does this mean only 15 are hard linked?
    – ccdavies
    Commented Jun 18, 2018 at 10:29
  • @ccdavies If you had used --copy-dest instead of --link-dest, then yes, the files would have been copied (not linked).
    – Kusalananda
    Commented Jun 18, 2018 at 10:29
  • @ccdavies No, look at the files on the destination. The link count on directories is not relevant here.
    – Kusalananda
    Commented Jun 18, 2018 at 10:30

You must log in to answer this question.

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