Using Git as a Backup Tool

It had been a hellish week, and at this moment sleep was not an option for Phil. maybe it was the kimchee, maybe it was the realization that his blog almost shrugged off its digital coil as a result of The Great Blogtastrophe. Phil was tossing anxiously in his bed – visions of hard drives melted in his head and then…

Oh CRAP – his spine straightened in horror: “OMFG I don’t know if ROB HAS BACKED HIS BLOG UP!”. There was no time to waste – this has to be fixed. Phil raced to his machine, fear mounting as he visualized a world without Rob’s blog… horrifying… [diety] help us…

The Harsh Reality

The laptop hummed to life, bathing the room in deep red light from his Masters of the Universe desktop wallpaper. He quickly typed in his shortcut for Remote Desktop Connection, entering the address for Rob’s server in the Server Address box. And then froze. He didn’t know the login and password…

Relying on intuition and a deep dark secret he knows about Rob, Phil guessed at the login/password and nailed it the first shot. It couldn’t be that easy… is Rob such an amazing haack that he used THAT for his login? Oh no… this could be really, really ugly.

Phil was greeted with a sea of desktop icons – dlls and text files co-mingling in digital sin. Shortcuts to nowhere. He was tempted to kick up a game of minesweeper – but a glance at the clock made him realize time was running out. He pulled up SQL Server’s Management studio to analyze Rob’s backup plan and quickly saw he had none. The horror… the horror… the… horror….

“I can’t let this happen to the most awesome person I know… even if he is a complete hack” Phil thought, and his fingers went into action – creating the missing backup plan. He dropped open the Management directory and right-clicked on Maintenance Plans – selecting “New Maintenance Plan” (“Wizards are for CHUMPS” he thinks to himself). He quickly creates a backup plan and schedules it to go off 3 times a week:



He decides to be as tidy as possible – Rob needs some kind of role model here and while he’s tempted to throw the .BAK file onto the Desktop (oh delicious irony) he can’t bring himself to be that cruel. Well, he can but in this case he has a plan…

The Missing Backup Plan

Phil scanned Rob’s server in a panic, praying that his ISP had performed some type of Backup Intervention – instead all he saw were traces of tough love and Rob insisting on living life the hard way. Phil knew the hard way – knew it all too well. His blog was almost lost to his folly – he couldn’t let this happen to his most favorite person – he needed to make sure that all of his data as well as uploads was safe for all posterity!

DropBox, LiveMesh, X-Drive, SkyDrive, Mozy – the digital world is awash with people pushing backup space. Why in Fowler’s Name did Rob choose to live in this Geek Ghetto? There was no service available – nothing had ever been archived. Phil was stuck.

And then he remembered… “Didn’t Rob do some kind of post that I never read about deploying sites with Git and FTP? Hmmm, I wonder if he’s got Msysgit installed on this box. Would be weird if he did but… I wouldn’t rule it out…” Phil right clicked on a directory and was shocked and relieved to see the most wonderful prompt he’s ever seen in his life:

Git Bash Here

Setting Up The Remote

The pieces of the puzzle were starting to fall into place – he’d push Rob’s blog to a remote service! And then he’d set up a shell script using Scheduled Tasks to repeat the operation! Oh SHAZAAAM!

In a rush of inspiration Phil logged into his Unfuddle account, loading up a new Git repository just for Rob. “Happy Holidays you troll…” Phil thought. He could also have used Github since he paid for the service upgrade to have a private repository.

He added the entire directory, including the new database BAK file, to git:

git init

git add .

git commit -am "Saving Robz Assssss"

Once the initial setup was completed, he added in a remote:

git remote add backup git://

The final part was adding the script to a CMD file, with the recursive trick of adding this shell script to the archive itself:

git add . & git commit -am "Periodic backup %DATE%" & git push backup master

The only part left was to run the script to make sure it worked:


“Damn I’m good. No … no… I’m a frickin super star” Phil thought to himself. He thought these things a lot but in this case, in this one strange turn of fate, he was correct. It felt good to be correct and Phil sat back in his Aeron, savoring the moment.

The Scheduled Task

Phil opened the Task Scheduler wizard and created a basic task. He set the schedule to go off 3 times a week, and in the “Start a Program” dialog entered the path to the script he just created:


Surveying the summary, Phil felt the rush once again. He was the shine of the sun, a beacon of correctness and excellence in the dark of Rob’s world:








One Upping Rob

It was good to be right, and Phil couldn’t get enough of it. He decided that he needed to one-up Rob on his own turf, using Git and FTP to back up Rob’s blog to his own hard drive.

“I’ll show him that I’m awesome too.. ” Phil thought, “… and I’ll use his precious SubSonic to do it… yes… yes…”.

Phil headed over to SubSonic’s source at Github and grabbed the latest drop of SubSonic 2.2 – knowing that there was a handy tool called “SubCommander” that would not only script out the schema of a database, but the data as well.

He dropped the binary files to his C drive, into his SubSonic folder, and once again kicked up his text editor to create a shell script for Rob’s SQL Server Database:

C:\SubSonic\sonic.exe scriptschema /override  /out Z:\RobsBlog\ /server /userid cody /password ------- /db shwerko 

As he ran the script he wondered why Rob named his database “shwerko”, and also if he would ever be dumb enough to publish the real credentials on his blog in some ridiculous blog post. “No”, he thought, “not even Rob is capable of such silliness…”.

When he was done, he saw a SQL script file placed in the Z:\RobsBlog directory:


He added another command to the script to pull the data as well:

C:\SubSonic\sonic.exe scriptdata /override  /out Z:\RobsBlog\ /server /userid cody /password ------- /db shwerko

And this dropped another .sql file right under the first, full of INSERT statements. Perfect!

Now for the fun part…

Hooking Up FTP and Git to Pull Rob’s Blog To an External Flash Drive

Just in case Unfuddle explodes, Phil decides to be prudent and backup Rob’s blog to his 250g external flash USB drive that he got for last Christmas from Jeff Atwood after they got into an argument about who could do the worst job backing up their blogs. Phil recalls that perhaps Jeff won this argument:

One thing’s for sure: until you have a backup strategy of some kind, you’re screwed, you just don’t know it yet. If backing up your data sounds like a hassle, that’s because it is. Shut up. I know things. You will listen to me. Do it anyway.

Redundancy. That’s what Rob needs. Redundancy. That’s what Rob needs and I’m sure of it. Phil decides to map a drive to Rob’s FTP server so he can do some Git magic over FTP. Phil’s running 64-bit windows and knows that the only thing he can do is to purchase WebDrive since it’s the only reliable way (as of this crazy, stressful evening) to wire a hard drive to an FTP site. He used to run NetDrive happily on his 32-bit installation of Windows ME and it worked great.

He kicks up WebDrive and maps his W: drive to Rob’s site root, happy to see the “.git” folder in there. He knows that if it wasn’t in there he could easily put it there by using the following commands (since Git doesn’t see the FTP part – only another drive on the machine – WebDrive handles the plumbing):

git init

git add .

git commit -am "Loading up Robs sorry blog"

Phil creates a directory on his backup drive and calls it “BlogArchive” and then issues the simple clone command for Git – pulling down Rob’s blog – noting that WebDrive is acting as middleman here:




To complete his masterpiece of extraordinariness, Phil puts this all in a script which he can execute as needed, pulling down the data as well as all the assets at once, storing them on his flash drive:

git pull origin master && 

C:\SubSonic\sonic.exe scriptschema /override /out K:\BlogArchive\Hana\ /server /userid cody /password ------- /db shwerko && 

C:\SubSonic\sonic.exe scriptdata /override  /out K:\BlogArchive\Hana\ /server /userid cody /password ------- /db shwerko

In reviewing his work, Phil thought it was good. He felt a restfulness come over him as he realized he had just saved Rob’s blog from possible oblivion. Not only that, he could now look at Rob’s source code for Hana and maybe plug some of it in to Subtext…

The room stayed lit that night, bathed in the red glow of Phil’s desktop wallpaper… and his feeling of accomplishment.

“I wonder if Galloway has a backup plan…” thought Phil, and kicked up Remote Desktop Connection once again…

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

2 Responses to Using Git as a Backup Tool

  1. I like Chris Tavares comment! The story is awesome too!

  2. You know, none of this counts until you’ve done a restore.

Leave a Reply