Rocking mercurial on a Cloud Server
I’ve been using Rackspace cloud servers for a couple of months now. I’ve been very pleased with their 256MB Cloud Server. At 1.5ยข/hr, it’s a great place to test out new ideas without needing to come up with a chunk of cash up front. You might also be surprised at how much computing you can get out of a single 256MB Cloud Server. I’ve been using a 256MB Cloud Server (running Ubuntu) to host this blog and
a site for my wife. They get a modest amount of traffic, so
I’ve been looking for other ways to maximize my utilization of that
Cloud Server. I’ve started tracking all of my personal
projects (even my resume and other text documents) with mercurial.
These mercurial repositories have been living on my mac mini.
This works fine since I’m really the only person using them.
However, I’d like for these projects to be backed up offsite.
I’d also like to easily be able to work on these projects when I
switch between machines. To accomplish this, I moved my personal
mercurial repositories to this 256MB cloud server. Here’s what
I did to get that working:
First off, I’m using key-based ssh login.
You can read more about it here.
Combining the key-based login with a proper ~/.ssh/config like:
Host myssh_alias
HostName myhostname_or_IP
IdentityFile /Users/myusername/.ssh/mykeyname
PasswordAuthentication no
Port 22
User myusername
makes getting to your machine as easy as:
ssh myssh_alias
and with no username/password to remember.
(Rock the short command line!)
I point this out since I’ll be using ssh to access
my mercurial repositories on the cloud server.
Next up, install mercurial on the cloud server:
sudo apt-get install mercurial
To make backing up my repositories to cloud files (or S3…or wherever) easy, I also installed duplicity (and python-cloudfiles for cloud file access):
sudo apt-get install git-core
git clone git://github.com/rackspace/python-cloudfiles.git
cd python-cloudfiles
sudo python setup.py install
sudo apt-get install duplicity
With the necessary components now in place, I scp’ed my mercurial repositories to my cloud server. Something like this:
tar jcf myhgrepo1.tar.bz2 myhgrepo1
scp myhgrepo1.tar.bz2 myssh_alias:/repos/myhgrepo1.tar.bz2
ssh myssh_alias
cd /repos
tar jxvf myhgrepo1.tar.bz2
I put all of the repositories in /repos on the cloud server.
If you don’t put them in your home directory, you’ll need to make sure
to include an extra ‘/’ in the URL when using hg clone.
Like this:
hg clone ssh://myssh_alias//repos/myhgrepo1
If you put your repositories in your home directory, that command would look like:
hg clone ssh://myssh_alias/repos/myhgrepo1
With all of my repositories on the server now, I setup a cron job to back up the repos to cloud files using duplicity. Something like this shell script should work:
#!/bin/bash
UPLOAD_TO_CONTAINER="name_of_cloud_files_container"
export CLOUDFILES_USERNAME=cloudfiles_username
export CLOUDFILES_APIKEY=cloudfiles_api_key
export PASSPHRASE=password_for_backup
/usr/bin/duplicity /repos cf+http://${UPLOAD_TO_CONTAINER}
(Thanks to Chmouel Blog for the tips on rsync like backup with duplicity.) Now, you’ve got a central place for your personal mercurial repositories that includes periodic backup.
If you’re looking for a new computing toy (that’s not really a toy) and don’t want to drop bling on an iPad or (insert the name of the product you’re currently drooling over), a cloud server is a really cool (and useful) thing.