One of the main principles that’s been hammered into me from lectures and experience over my 15+ years of computing is backup, backup, backup. It becomes even more crucial when you start hosting sites, especially sites for other people. On all the servers we run, we backup site and database files nightly, with automated syncs offsite to other servers/the cloud and to my laptop.
Every few days, I hook up one of my external hard drives and transfer over the offsite backups so they’re not cluttering up my working space.
The Bleepin’ Leadin’ Asterik
Yesterday was one of those days. After syncing my laptop’s backup folder to my external backup folder (via rsync), I wanted to drop the files from my laptop. Already being on the command line and knowing I wanted to drop everything inside my local offsite backups folder, I naturally ran this command:
rm -rf * /Users/Adam/offsitebackups/*
Usually this cleanup runs in under ten seconds, since it only contains a few days worth of backups.
After fifteen seconds I started wondering what was going on. After twenty seconds, I noticed the leading asterik and started pounding on
as fast as humanly possible.
After swearing very loudly, I ran:
to show me my working directory:
flashed on the screen and again I swore very loudly. To anyone not familiar with Unix, here’s a quick introduction. The
rm command stands for remove. the
rm stands for “recursive” and “force” and the
* stands for “all”. In short, I issued a command from my home folder that would go through and delete any files, folders, and sub-directories inside that folder. Since I keep almost all of my files inside /Users/Adam, you can understand the frustration.
My next step was crucial and brings us to our first lesson.
After realizing what I did, I walked away from my computer. If I had remained at the console, I probably would have furiously done some things that may or may not have made the situation worse. The damage had already been done so my next step was to calm down. After pouring myself a glass of water, I returned to the computer with a calm, clear mind ready to rationally recover as much as possible.
Internet Syncing is Wonderfully Convenient…
After sitting back down, I stared at the screen blankly for a few moments. Knowing that I periodically run Time Machine and that the damage had been contained to /Users/Adam gave me some relief, since at worst I would have to rebuild my home directory from a recent backup. But at least the core system would be intact.
Also knowing I sync some of my files with Dropbox and run version control on the important sites, left me with some peace of mind. With services like Dropbox and Subversion getting easier and easier to install and run, there’s really no excuse for not having wonderfully convenient backups of your important stuff up on the internet or your local network.
… and Deceptively Dangerous
Then I noticed Spanning Sync spinning up. Unsure if my local Address Book files were intact, I immediately shut off my wireless connection and yanked out my ethernet cord. No need to start updating my cloud files and deleting what shouldn’t be deleted. Of course Spanning Sync would ask me before syncing up the deleted entries, but without knowing off the top of my head what else might be planning a sync at any moment, I felt turning off access to the internet was the best way to ensure the damage stayed localized.
I also shut down Time Machine, since there was no need to run a massive backup to save my newly shrunken down system.
Get a Base Reading
After regaining my composure and severing my laptop’s connection to the network and other devices, it was time to start checking what was gone.
My first instinct was to:
which would show me all the files in /Users/Adam and provide a timestamp of the last modification date.
A sigh of relief at this point, as I noticed most of the structure was still intact and untouched. The only folder with a recent modification date was my Desktop. I have a very particular organization for my Desktop, which means I only keep two folders on the desktop.
My projects folder contains anything I’m currently working on. For instance any graphic files or copy for sites is stored inside Projects. Needless to say, it’s a crucial folder.
A catch all folder for anything else. I like to keep my desktop nice and tidy so anytime I go on a downloading spree or have random files cluttering up my desktop that don’t relate to any of the projects I’m working on, they get dropped into Stuff. Not as crucial as Projects, but because the nature of this folder means I really have no clue what was or wasn’t in here, I was hoping it wasn’t too badly damaged.
Well, a quick glance at my actual desktop showed me that Projects was completely gone.
At least I had double backups of the Projects folder to Time Machine and to Dropbox, but unfortunately both were a bit out of date.
Keep Timely Updates
For some reason, I’d shut down Dropbox at some point. Now, I let it start when my computer starts and leave it running at all times. This way, when I make changes to the Projects folder or any other folder synced to Dropbox, it gets updated automagically. All you have to do to get the same auto-magic is link the folder with dropbox.
ln -s ~/Desktop/Projects ~/Dropbox/Projects
That little trick will make sure there’s always a recent backup. Since Dropbox takes a little time to sync up, it might’ve started deleting some files but at least it’s another backup. The other key to keeping timely backups is to let Time Machine run off the network, rather than a hard drive I have to remember to plug in every few days.
Finally, the biggest and most important lesson is to take human error out of the equation. Now, instead of manually moving files over to my external, I’ve set up a script to automatically sync them over and then clean up the laptop hard drive after its done. It’s one of those things I should’ve done a while ago but kept putting off. Foolish indeed as scripting it the first time would’ve saved me time and files.