Score:0

How to use rsync to backup local folders to an external hard drive with hard links for unchanged files

fr flag

I have two folders in my home directory that I need to backup to an external hard drive. Each folder has some files that should be excluded from the backup, and I have a file named "backup-exclude" in my home directory to specify these exclusions. Here is the directory structure:

Home Directory:
- Dir1/
- Dir2/
- backup-exclude

I want to use rsync to backup these folders to an external hard drive, and I would like to utilize hard links for unchanged files in order to save space. The external hard drive has the following structure:

External Hard Drive:
- Backup/
  - backup-2023-06-10/
    - Dir1/
    - Dir2/
  - backup-2023-06-03/
    - Dir1/
    - Dir2/

The file system format of the home directory is ext4, while the external hard drive is formatted as NTFS. The command I currently use to perform the backup is as follows:

rsync -av \
      --exclude-from=backup-exclude \
      --delete-excluded \
      --delete-after \
      ~/Dir1 ~/Dir2 \
      /external-hdd/Backup/backup-2023-06-10

However, I would like to modify this command to make use of hard links to previous backups on the external hard drive. I have attempted the following command, but it did not work as expected:

rsync -av \
      --exclude-from=backup-exclude \
      --delete-excluded \
      --delete-after \
      --link-dest=/external-hdd/Backup/backup-2023-06-03/ \
      ~/Dir1 ~/Dir2 \
      /external-hdd/Backup/backup-2023-06-10

Can someone please provide the correct command to achieve the desired behavior of hard linking to previous backups on the external hard drive?

24601 avatar
in flag
I would recommend you download `luckyBackup` from Ubuntu Software. It provides a graphical interface which makes the use of rsync a breeze.
waltinator avatar
it flag
Hard links cannot be used across volumes (from one disk to anotherl)
Xayden Rosario avatar
fr flag
@waltinator, what I mean is that the hard links I want to create should be within the external hard drive itself. When using `rsync`, it should compare the files between the EXT4 file system (the source) and the NTFS file system (the destination on the external hard drive). If there are no differences found, `rsync` should create a hard link from the NTFS file to another file within the same NTFS file system. This is my understanding of how it should work.
vanadium avatar
cn flag
To me, the command looks OK at first sight. Can you indicate what did not work as expected? Sure this will work on ntfs?
Xayden Rosario avatar
fr flag
@vanadium I expect that the unchanged files within the "backup-2023-06-10" directory should possess **identical inode numbers** to the files present in the "backup-2023-06-03" directory. However, this is not the observed behavior.
waltinator avatar
it flag
Read `man hardlink`. It will hard link identical files (and you get to configure what "identical" means), *after* the backup
vanadium avatar
cn flag
So you notice the files are not hardlinked. Then it remains to be seen if this feature of rsync is expected to work with ntfs. Hardlinks are a unix/linux feature whereas ntfs is a file system of MS Windows, which may not by default support linux hardlinks.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.