Rsync Preserve / Copy Hard Links ( Backup Rsnapshot Directory Tree )

To preserve hard links when using rsync to backup a directory tree, you need to use the --link-dest option. The --link-dest option allows you to specify a source directory that rsync should compare to the destination directory to determine if hard links can be created.

For example, if you are using rsync to backup a directory tree using the rsnapshot utility, you would use the following command:

rsync -av --delete --link-dest=../previous/ /path/to/src/ /path/to/dest/

In this example, -av are the flags for archive mode and verbose output. --delete ensures that deleted files in the source directory are also deleted in the destination directory. The --link-dest=../previous/ option specifies the source directory to compare to the destination directory to determine if hard links can be created.

Note that in order for rsync to preserve hard links, the source and destination directories must have the same files in the same order. This is why the --link-dest option is often used in conjunction with a backup utility like rsnapshot, which takes snapshots of the directory tree at regular intervals and uses rsync to copy the changes from one snapshot to the next.

Leave a Comment