I'd like to do a backup with the following structure

/source # the source directory which should be backed up

/backup/initial/... # the first initial copy/backup of the source
/backup/snapshots/YYYYmmDDHHmmss/... # (1)
/backup/changed/YYYYmmDDHHmmss/... # (2)

(1) is the "default" behavior of rsync I guess. Make a snapshot with hard links back to the initial backup. I would do this via rsync -avuP --link-dest=$initial_backup $directory_to_backup $destination

(2) I get the rsync outputs for this via rsync -riv --ignore-existing "$directory_to_backup"/ "$last_backup"/ and rsync -riv --existing "$directory_to_backup"/ "$last_backup"/

but now I would like to hard link the output of these two scripts into the changed directory.

My goal is to have both, full snapshots of the directory I'd like to backup but also a changed directory containing only new and modified files. Everything with hard links to avoid taking too much space.

  • Right after an rsync command to create a snapshot, any regular file in the snapshot with hardlink count = 1 will be new. I don't believe rsync preserves harlinks on the source (though you should double check). It might be possible to use this to build up the "changed" directory immediately after the rsync. Commented Jun 30, 2020 at 9:32
  • I thought about something like using the n flag and generate a list of new/updated files and afterwards use that list to hard link them to the changed directory - but I don't know how...
    – swalkner
    Commented Jun 30, 2020 at 9:54

1 Answer 1


If I have understood you correctly, you just need to change the order a little. You can use --compare-dest to create the directory of new and changed files, then use two --link-dest args to link back this changed directory, and the previous snapshot. Here's an example test script:

cd /tmp/
rm -fr src backup
mkdir -p src/a/b backup
date >src/a/b/unchanged
date >src/a/b/c
rsync -a src/ backup/i
rsync -a --link-dest=../i/ src/ backup/s1
sleep 1
date >src/a/b/c
date >src/a/b/c2
rsync -av --compare-dest=../s1 src/ backup/ch
rsync -av --link-dest=../s1 --link-dest=../ch src/ backup/s2
ls -li backup/*/*/*/*

which gave me this output:

919 -rw-r--r-- 2  backup/i/a/b/c
920 -rw-r--r-- 3  backup/i/a/b/unchanged
919 -rw-r--r-- 2  backup/s1/a/b/c
920 -rw-r--r-- 3  backup/s1/a/b/unchanged
472 -rw-r--r-- 2  backup/ch/a/b/c
473 -rw-r--r-- 2  backup/ch/a/b/c2
472 -rw-r--r-- 2  backup/s2/a/b/c
473 -rw-r--r-- 2  backup/s2/a/b/c2
920 -rw-r--r-- 3  backup/s2/a/b/unchanged

Here, directory i is the initial backup, s1 snapshot1, s2 snapshot2, and ch the changes corresponding to snapshot2. The first column is the inode number, and the 3rd is the hard link count. It shows that changed file c is hard-linked to ch, new file c2 is hard-linked to ch, and the unchanged file is hard-linked to s1 and i.

  • that's it, thank you VERY much!
    – swalkner
    Commented Jun 30, 2020 at 13:23

You must log in to answer this question.

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