Incremental backup script
Solution 1:
Depends on what you mean by incremental. One trick is to use hardlinks on an EXT4 drive. This means that if files don't change, they will appear in every snapshot, but will only exist (and be copied to the drive once). Here is script I've used before:
#!/bin/sh
NEW_FOLDER="$(date +%F\ %H-%M-%S)"
rsync --archive --human-readable --progress --link-dest /media/current "/etc/" "/media/incomplete/"
mv /media/incomplete /media/'$NEW_FOLDER'
rm -f /media/current
ln -s /media/'$NEW_FOLDER' /media/current
By using an incomplete folder, if the backup is stopped halfway through (very useful for large backups), it will pick up again when you next try. You can then browse each folder as a complete incremental backup. This is a similar approach to Apple Time Machine.
If you don't want to use hardlinks to save space, and don't mind file duplication, remove the --link-dest /media/current
setting.
Solution 2:
Rsync will perform incremental backups by default, but probably not with the result that you expect. The command
rsync -av /etc/ /mnt/
transfers only changed files. For that, it compares the content of /etc
and /tmp
. If you add a computed date, eg /tmp/$(date)
, the target folder is empty and therefore, all files will be transfered again.
The options --backup
and --backup-dir
are only useful, if you need a backup of the files, which would be deleted, if you start the rsync
command with the option --delete
.
Summary
To create true incremental backups, you will need another tool, eg. rsnapshot
.