Backup with rsync a la time machine: a proof
I am struggling for backups since ever. I assume just like anybody. For my personal machines I used rsync in combination with my script taritdate.sh. Then I kept reading online about using rsync for incremental backups but I could not find any simple example. So I did this little script:
#! /bin/sh # # SETUP #TESTING: DIRRSYNC="${HOME}/tmp/rs/rsyncBackup" DIRRSYNC="/Volumes/ExtDisk/MacBackUp" DIRBACKUPS="${DIRRSYNC}-BP" #mydate=`date +%Y%m%d-%H%M` #FORMAT: 20130131-2226 / Windows SMB / Samba with --modify-window=1 mydate=`date +%Y%m%d-%H%M%S` #FORMAT: 20130131-222618 OPTRSYNC="-av --delete --backup" # if [ -z $1 ]; then echo "please give a dir name." exit 1; fi; PRJDIR=`basename ${1}` DIRBKPUP=" --backup-dir=${DIRBACKUPS}/${PRJDIR}/B-${mydate}" PRGDIRBACKUPS="${HOME}/tmp/rs/rsyncBackup-BP/${1}/" #rsync --dry-run ${OPTRSYNC} ${DIRBKPUP} $1 ${DIRRSYNC}/${PRJDIR} echo "Running: " rsync ${OPTRSYNC} ${DIRBKPUP} $1 ${DIRRSYNC}/${PRJDIR} rsync ${OPTRSYNC} ${DIRBKPUP} $1 ${DIRRSYNC}/${PRJDIR} # # # Create List Files if [ -d ${DIRBACKUPS}/${PRJDIR} ]; then cd ${DIRBACKUPS} find ${PRJDIR}/B-${mydate} > ${PRJDIR}/B-${mydate}.filelist fi; #
I have to admit that instead to google it for years, I could have just read the rsync manual page in details.
It is currently available also at: https://github.com/mariotti/mfsh-scripts.
How does it works? This is an extract of the current README:
===
In principle it works much alike the Mac OS time machine.
You need first to define a backup directory (which can be on a network disk, any which shows up as path on your system. For example I have a samba mounted on my macbook). This is this line in the script:
DIRRSYNC="/Volumes/ExtDisk/MacBackUp"
The rest is preconfigured, but check the script which is really few lines.
Then
backmeup.sh DirToBackUp
will create a directory ‘/Volumes/ExtDisk/MacBackUp/DirToBackUp’ which is a copy of your original dir, and eventually later a directory ‘/Volumes/ExtDisk/MacBackUp-BP/DirToBackUp/B-‘ which contains deleted and changed files old versions.
The script is in very beta but a starting point.
It creates also a file list for the ‘/Volumes/ExtDisk/MacBackUp-BP/DirToBackUp/B-‘ directory.
The idea is that if you look for a file, you know already which file on your current system, and you might need to look only on the old backups, like:
grep myfile /Volumes/ExtDisk/MacBackUp-BP/DirToBackUp/*.filelist
The backup destination is hardcoded. My idea is to use the script in the future as a templates and create scripts like: backmeup.dest01.sh, backmeup.dest02.sh and use them in a cron job with only the requested backup directory as parameter.
This because we might need different options depending on the destination. One option is already mentioned as comment in the script: ‘–modify-window=1’. This is used when for example you are working with Samba, SMB, or Windows destinations as you might end up on a file system which has only a 1 minute (+-1 implicit) time difference stored for file dates.
===
Now I can keep using ‘taritdate.sh’ to archive old incremental backups!
Please keep up to date on github for the future of this script. If you feel to participate, I will be very happy, backup is a problem which will probably never end.
One comment