I use rsnapshot to make regular backups of my systems' filesystems to a remote server.(For those familiar with rsync but less used to rsnapshot here is a brief introduction to its workings. A backup is a file-by-file copy of a source file-system tree, much like cp -a would produce. The current backup is always hourly.0, and the previous one is hourly.1. These names are rotated each time a backup begins. Under the covers rsnapshot uses rsync --link-dest to hardlink unchanged files in hourly.0 to the corresponding entries in the previous backup tree, hourly.1.)If a backup fails, the previous backup is copied (linked) using cp -al to the current backup, so that a backup always appears to have been made.What I would like is to avoid making a backup if there have been no changes since the previous backup. This could include a backup failure or simply that the source filesystem was not modified since the last backup. (Making a backup can be rephrased to deleting an unnecessary backup if you would prefer.)I've considered looking in the hourly.0 tree for files that are not hard-linked elsewhere, and if there is none then simply deleting the backup tree. This does not handle a file that is validly linked elsewhere within its backup, and it also fails to consider changes to directories. I have also considered using rsync --dry-run to compare the two backup trees and looking at its output but this feels somewhat ugly.Is there a better solution?
Backup with rsnapshot only if there are changes
rsync;backup;rsnapshot
After the snapshot, you can use rsnapshot diff which calls rsnapshot-diff to note the differences between two snapshots. It just compares inode numbers so is fairly efficient.Alternatively, before each backup create a file outside the backup tree to note the time, touch timestamp. Then before a new backup, create a new timestamp, touch timestamp.new, and test if any files or directories have a newer time than the old timestampfind tree -newer timestampIf not, do not do the backup. In any case, mv timestamp.new timestamp for the next time. This assumes you don't have applications that manipulate the file and directory timestamps.