Archive for August, 2007

Undoing changes and new files with Subversion

Update 8 Sept: Ryan Bates’ Railscast episode #36 shows you how to setup a new rails project in Subversion, including setting up trunk/tags/branches, and a number of tips to make using svn with rails easier. He doesn’t cover undoing new files, but it’s a great introduction that I wish I’d had when I started using Subversion with Rails. Highly recommended.

I’m new to subversion, so if there’s a better way to do this, please pass it along. I just worked this out, and I’m posting here as much for my own reference as anyone else’s.

Let’s say you’ve got made a bunch of changes in the working directory of a project managed with Subversion. These changes include new files added to the tree, possibly in new directories/subdirectories. As a concrete example, suppose you’ve just run a Rails generator (e.g. script/generate resource user), and changed your mind (e.g., you should have used scaffold_resource). You want to revert to the last check in, reverting existing files and removing any newly created files and/or directories that don’t exist in the repository. Of course, this whole use case assumes you’ve committed any previous changes before making the changes you don’t like. You do commit incrementally, early, and often, right?

My first instinct was this:

svn revert -R .

But that’s only half the answer. Files already existing the repository are reverted, but new files and directories still abound. A check of svn status reveals the remaining damage:

?      test/unit/user_test.rb
?      test/functional/users_controller_test.rb
?      test/fixtures/users.yml
?      app/helpers/users_helper.rb
?      app/models/user.rb
?      app/controllers/users_controller.rb
?      app/views/users
?      tmp/sessions/ruby_sess.5337b01cd2bbeca8
?      db/schema.rb
?      db/migrate

Assuming you’re on a Unix-like system (oh, say, OS X), the following will remove all of the offending files and directories:

rm -rf `svn st | sed 's/\? *//'`

A check of svn status should now be blessedly quiet.

Obligatory Nag/Warning: Use Caution! Any command line that begins rm -rf is likely to end in tears. Your Mileage May Vary. Caveat Emptor. No Warranty, Expressed or Implied. Want to double check what you’re about to trash? Run the bit inside the backticks (svn st | sed 's/\? *//') to see the file list. Finally, remember to run svn revert -R . first!

Hyphenated Forms of Procrastination

  1. Wool-gathering
  2. Yak-shaving
  3. Wikipedia-surfing
  4. Hand-wringing
  5. Blog-posting

Note: The pedantic reader may note that some of these phrases do not traditionally contain a hyphen. The pedantic reader is asked to note this quietly to him- or herself.


In my previous post, I mentioned the Drobo as a possible option for my plan to eventually move to RAIDed storage for my backups. I forgot to mention that I expected to see a review from Sean based on this teaser post a few days ago. It looks like he pulled the trigger, complete with 2 terrabytes of drive space. Money quote:

It took more time to open the packaging than actually doing the install.

I’m looking forward to some further impressions, especially with regard to transfer speed. As a professional photographer, he shuffles some serious tonnage of data around.

Makin’ Copies

Backups are the New Year’s Resolutions of computing. You start out with good intentions, and by the end of January you’re eating Twinkies and you haven’t backed up in weeks. Prior to my iMac’s premature death, by backup strategy was the electronic equivalent of keeping your savings under the mattress- I burned my iPhoto Library to DVDs, copied a few things to another machine when I thought of it, and mostly forgot about it. I kept meaning to do something about it, and then I kept not doing anything about it. I was also dragging my feet because I was waiting for the fancy new Time Machine feature in Leopard, originally due out in June. Nothing could possibly go wrong before Leopard comes out, right?

Of course, nothing leads to good backups like systems failure and data loss. This time I was lucky- my data loss was only loss of access to my data; once the iMac was fixed, all my data was right where I left it. Had my dead logic board been a dead hard drive, I would been up the proverbial creek, which empties into the Bay of Despair, where lies the Isle of Self Recrimination. And so it was, that after unpacking the Mac and confirming everything worked, and after a brief aside (read: reboot) for the latest Mac OS X security update, I started working on a backup plan.

My long term (say, 6 months tops) plan is to have automatic backups to some kind of RAID setup. Storage just keeps getting cheaper, and RAID is no longer requires rocket surgery to use. For USD 400.00 at my local Apple Store, I can get a terrabyte in box from Western Digital, usable as either RAID 0 (no protection, seen as one big drive) or RAID 1 (half the storage, but double the copies) via USB 2.0 and Firewire 400/800. For USD 500.00 I can buy a Drobo (be sure to watch the video), a USB 2.0 (sure wish it had Firewire 800) self managed RAID box that can sport 1 to 4 drives of any mix of sizes, and intelligently manage the RAID automatically. Of course, I’d still have to shell out for drive(s), but the beauty there is that you can only buy as much storage as you need (any brand SATA drive), allowing storage prices to continue to drop. Also, it’s a one-time investment; if you run out of room and free drive bays, you replace smaller drives with bigger drives, one at a time, as needed. Either of these solutions could be hung directly off my Mac for use with Time Machine, or attached to my Linux server or an NAS for a networked setup.

In the interim, I’ll settle for a nightly copy of the data I care about- In my case, that’s the /Users directory and everything in it. I have an old beige box in the basement running Linux as a headless server, among other uses it hosts 160GB of storage via Samba. Keeping my ~85GB of /Users data copied onto the 160GB drive should be good enough for now- if either machine goes, I’ll have one good copy.

To maintain my copy, I am using rsync (see also the Wikipedia entry). I recalled that there are some issues with rsync on OS X, including the fact the the HFS file system used by OS X supports resource forks, which most other file systems do not. A bit of the Google turned up this rsync on OS X Mini-HOWTO at that nicely sums up the issues and offers a patch for Apple’s version of rsync. I compiled a new rsync on both my Mac and the Linux server with no issues, and proceeded to make a full backup of /Users to the remote system. For the curious (and for my own future reference), the particular rsync incantation I used was:

sudo /usr/local/bin/rsync -aREx --delete /Users/ user@server:/var/local/sync/iMac/

Where of couse user and server are placeholders, and /var/local/sync/iMac/ is a directory I carved out to hold the backup. I already had SSH setup between the Mac and the server; any decent rsync guide can elaborate on that if you don’t know the dance. The next step is to automatically run this command nightly, which will require a little re-jiggering; my default SSH key is protected by passphrase. I found one way of automating rsync, but I plan to do a little more research. For the next day or three, I’ll run it manually before bedtime.

Happy Mac

Good news! Sherri tells me the Apple store called, and my iMac is ready to be picked up! I’m on the train home from NYC right now (iPhone!) but I’ll pick it up tonight.

Update: The iMac is back home and running again. After a week of using my 15″ Powerbook, this 20″ screen is HUGE. Next step is to setup automated backups to my Linux server, via rsync.