[Home] [Blog] [Contact] - [Talks] [Bio] [Customers]
twitter linkedin youtube github rss

Patrick Debois

Rsync snapshots: seeing it work

Showing how rsync snapshots (--link-dest) work. This feature allows you to take incremental backups and still having a complete directory to copy over without taking additional diskspace for storing a copy of each file. It uses the notion of hardlinks off the filesystem. (having the same inodes ls -i).
#create a datadirectory, with data
$ mkdir data
$ > data/file1

#make the first backup
$ rsync -aP data/ backup-1
building file list ...
2 files to consider
created directory backup-1
./
file1

#do the second backup with nothing changed
$ rsync -aP --delete --link-dest=../backup-1 data/ backup-2
building file list ...
2 files to consider
created directory backup-2
./

#verify that file1 in backup-1 is linked with file1 in backup-2
$ ls -li backup-1
9651639 -rw-r--r--  2 patrick  staff  0 Nov  7 16:52 file1

$ ls -li backup-2 9651639 -rw-r--r--  2 patrick  staff  0 Nov  7 16:52 file1 #change file 1, but base ourselves on the previous (backup-2) snapshot $ echo "change1" > data/file1 #backup the directory again $ rsync -aP --delete --link-dest=../backup-2 data/ backup-3 building file list ... 2 files to consider created directory backup-3 ./ file1 #Verify inode has changed $ ls -li backup-3/ total 8 9651657 -rw-r--r--  1 patrick  staff  8 Nov  7 16:53 file1 #backup again with nothing changed $ rsync -aP --link-dest=../backup-3 data/ backup-4 building file list ... 2 files to consider created directory backup-4 ./ #Verify that inode is the same $ ls -li backup-4 9651657 -rw-r--r--  2 patrick  staff  8 Nov  7 16:53 file1 #Change the permissions $ chmod 777 data/file1 #backup again on previous snapshot $ rsync -aP --delete --link-dest=../backup-4 data/ backup-5 building file list ... 2 files to consider created directory backup-5 ./ file1
#verify that change of permission triggered a new file $ ls -li backup-5/file1 9651699 -rwxrwxrwx 1 patrick  staff  8 Nov  7 16:53 backup-5/file1 $ ls -li backup-4/file1 9651657 -rw-r--r-- 2 patrick  staff  8 Nov  7 16:53 backup-4/file1