cd $HOME
Emulate a repository with rsync
I was working the other day on Dateslider, a fancy Javascript library to create sliding date pickers (see the demo here).
After having refactored 300 lines of Javascript and added two classes, I realized it was time to backup my work! Unfortunately, I have no access to the initial repository. I could have simply zipped it and sent it to an external hard drive but I wanted to keep an history of my changes. I could have created a personal repository but sending files to the upstream team would be painful with all the .svn/ subdirectories…
I finally decided to go with rsync and emulate a repository.
#!/bin/sh
# svn.sh
# Directory to backup
DIRECTORYTOBACKUP=${1%/} # Remove trailing slash
# The name of the backup machine
# Don't even try to hack this CNAME, it doesn't exist.
BACKUPSERVER=backups.mouraf.org
# Auto-generated directory containing modified files
INCREMENTALDIR=`date +%m_%d_%y-%H_%M_%S`
OPTS="--progress --force --ignore-errors --delete --backup --backup-dir=/BAK/$DIRECTORYTOBACKUP/$INCREMENTALDIR -a --compress"
rsync $OPTS $DIRECTORYTOBACKUP backups@$BACKUPSERVER:/BAK/$DIRECTORYTOBACKUP/current
Note: refer to the rsync man page for details about available options. Have a look to “delete-excluded” and “exclude-from” which are especially helpful to avoid transferring Virtual Machines ram disks for instance…
With the command ./svn.sh dateslider, you end up backuping the entire directory dateslider to /BAK/dateslider/ on $BACKUPSERVER (you don’t have to send it to another server, you may simply backup it to an external drive for example). The current up-to-date version is in the current directory.
Each time you modify a file and fire up the script, another directory is created ($INCREMENTALDIR) with the old version of the modified file and the new version is updated in current.
I have aliased this script to commit on my machine. Once in a while, I run it. Hence I always have a current copy of my data and all the diff I may need. Not as powerful as a real repository, but helpful and secure for small and/or temporary projects.





Comments