Posted on Feb 8, 2008

Using Subversion to safeguard my photos

During the backup project, I created a subversion repository for all of my installation media and installation files – anything I’d need to set up a new computer. The intention was to have a system that was a solid backup for these data, available for download from just about anywhere. Over the months, I’ve also added other stores to the repository, such as my useful windows standalone tools.

Recently, I thought it would be useful to have all of my digital photos in the repository, both for backup purposes as well as to allow me to, say, have all of my downloaded desktop wallpapers on my machines at work and at home. What better purpose, right? The biggest pain was keeping the repository up to date without constantly needing to issue pseudo-random svn add commands every time we take pictures. (I could use scplugin to make this easier, but as I found out, it kinda sucks.)

Instead, I turned to my love for shell scripting, and fairly quickly banged this out. I used the handy svn status command with impunity to help me handle recursive adds and deletes. Of note, yes, I wish SyntaxHighlighter worked here…

#!/bin/sh

store='/Users/shelton/Pictures'
date=`date`
message="Auto-Commit on ${date}"

# Update the local store
svn update ${store}

# Recursively delete all manually deleted files
svn status ${store} | sed -e '/^!/!d' -e 's/^!//' -e 's/^ *(.*)/1/' -e 's/ *$//' -e 's/ /\ /g' | xargs svn rm

# Recursively add all manually added files
svn status ${store} | sed -e '/^?/!d' -e 's/^?//' -e 's/^ *(.*)/1/' -e 's/ *$//' -e 's/ /\ /g' | xargs svn add

# Commit! Comment includes timestamp.
svn commit -m "${message}" ${store}

exit 0

It would be really nice if there were SyntaxHighlighter support for shell scripts. Maybe that’s worth working on myself, eh? Updated 2009-01-12: Sha-Zam!

This also required some modification to my rdiff-backup cronjob since, well, I didn’t want to back up every single .svn directory and included files as that would effectively double the backup requirements for that directory. So, I played a bit more with rdiff-backup’s options and ended up changing from this:

45 04 * * * rdiff-backup -v5 --print-statistics --exclude /Users/shelton/rdiff-backup.log --include /Users/shelton/Documents --include /Users/shelton/Pictures --include /Users/shelton/Music --exclude '**' /Users/shelton /Volumes/backup/BACKUP >> /Users/shelton/rdiff-backup.log

to this:

rdiff-backup -v5 --print-statistics --include-globbing-filelist /Users/shelton/cfg/rdiff-backup-files.txt /Users/shelton /Volumes/backup/BACKUP >> /Users/shelton/logs/rdiff-backup.log

This is obviously MUCH cleaner. rdiff-backup-files.txt looks like this:
- /Users/shelton/**/.svn
- /Users/shelton/logs
+ /Users/shelton/VM
+ /Users/shelton/Documents
+ /Users/shelton/Pictures
+ /Users/shelton/Music
+ /Users/shelton/Sites
+ /Users/shelton/bin
+ /Users/shelton/cfg
+ /Users/shelton/.tcshrc
+ /Users/shelton/.vimrc
+ /Users/shelton/.crontab
+ /Users/shelton/.ncftp
+ /Users/shelton/.screenrc
+ /Users/shelton/.htpasswd
- **
That first line, - /Users/shelton/**/.svn, is by far the most important, and took way too much trial and error to get right. Order of statements is, apparently, VERY important for rsync/rdiff-backup. Another note about the above list, I’m now backing up things that I wasn’t before, namely my VM directory, which contains my Parallels virtual machines. It started to make prudent sense, though currently the only VM in there is a very tiny cfg fileset to virtual-boot my BootCamp partition. I’ve started doing several things differently with regard to my home backup, which I’ll have to summarize at some point soon.

Posted on Oct 18, 2007

Home Backup Project – Part 3: Subversion Clients

As part of the ongoing home backup project, I’ve been testing various SVN clients to make sure I have a good working application for both home and work environments. At work I run WinXP Pro and therefore use TortoiseSVN because, well, it’s pretty much the best there is. I love the shell integration – it’s near seamless. I have local stores from multiple repositories – development code, cross-departmental tools and scripts, my home’s “tools” directory, and my home svn archive – all updated as I needed.

On the mac at home… well, that’s a different story. I tried SCPlugin, which seemed to be the Mac version of Tortoise. While it started out looking that way (the icons showed up for existing checked-out repos), it wouldn’t do a base PROPFIND for my local store, and then it crashed. Hard. And stopped working, even after a reboot. Why? I have no idea. That’s the great thing about a mac… software either works or it doesn’t, and SCPlugin doesn’t.

I then tried svnX, which had some promise, but after 15 minutes of poking, I had no idea how to add anything to repository. No clue at all. I’m sure it’s simple once someone tells you how.

Then SmartSVN. Same deal.. I couldn’t add a file, just a directory, and that seemed wonky. It’s probably me, not the software, but I wanted something usable enough that in a groggy stupor, I could update my local store and not need to think twice about what I was doing.

MacSVN also showed some promise, but it crashed on startup needing a newer version of Berkeley-DB than is available for the Mac. I want simple, and hacking up code I didn’t write in the first place to use a non-stable version of another software package falls slightly out of scope.

Then, I went back to the folks at tigris and poked around their site. I found RapidSVN, which is a GUI front-end for SVN with some additional bookmark support. That’s it… and somehow, this works so much better for me than any of the other options. You check out a local store and update it via finder (or any other file system tool, i.e. mv/cp/tar/etc.), then add/delete/commit as you need to through either RapidSVN or using the svn command line, and it all works together nicely.

This was my experience – I don’t plan on maintaining any source code in this repository (for now), so my uses are pretty one-dimensional – it’s a glorified password-protected file storage mechanism with an existing protocol for mirroring, versioning and access from anywhere.

After deciding on a method for utilizing SVN from anywhere, I was able to get my repository in good working order. The other major benefit to using SVN is that I can access the repository via a web interface, and when I need a file from anywhere, that sure is handy. The structure currently looks something like this at the top-most level(s):

  • Applications
    • Mac
    • Other
    • Windows
  • Disk Images

Of note, I plan to use svnsync locally on my svn server to keep a secondary mirror of the repository on an identical drive. There’s a great wiki article on on Mirroring a Subversion Repository over at the OpenDS wiki.


Previous Posts:

Home Backup Project – Part 1: Identify the Problem
Home Backup Project – Part 2: Plan!