OK that’s probably not the best way of making #backups but it’s the only way I found that:
- Works in pull mode
- Only downloads changed files
- Does not require to install script interpreters on the server (such as python)
- Does not need to store backups on the #server
If you have a better idea on how to achieve that, please let me know. I’m open to all suggestions or enhancements.
Requirements
rsync
need to be installed on the server and on the client. For Debian based distros:
sudo apt-get install rsync
Then, create a snapshots
folder that will contain all backups.
Targets
Create a text file containing paths of files or directories you want to backups. For example:
/etc/apache2
/etc/logrotate.d
/etc/ssh/sshd_config
/var/www/html
/home/user/.zshrc
Let’s name this file targets.txt
.
The script
Here the #rsync wrapper script I use:
#!/bin/sh
set -e
LAST="$(pwd)/snapshots/latest"
date="$(date "+%Y-%b-%d_%T")"
rsync -rlptzh --delete --progress --stats --link-dest="$LAST" --files-from=targets.txt user@myserver.tld:/ "snapshots/$date"
rm -f "$LAST"
ln -s "$date" $LAST
Basically, it asks rsync to download changed files into a new folder named according to the current time and to #hardlink unchanged files from the last #backup. That way, we get incremental backups but only changed files will occupies space.
At the end, the latest
symlink is updated.
Drawbacks of this method
- Backups are not stored #compressed
- Renaming will result in duplicates (not handled by rsync)
- There is no #deduplication between similar files