Automated Backup using Subversion


Subversion is a software for version-control that allows you to store changes you make to files, so you can revert edits, restore deleted files, and much more. If you are new to subversion you might want to start with my introduction to subversion, where I explain how to use subversion (svn) for making incremental backups of your data to a repository and keeping track of different versions of your files. In this post I explain how to use svn to store automatic periodic updates of your repository.

The situation is the following: being a human you have a weak memory and you might forget committing changes to your repository. You want an automated commit every day to your repository. You have one or more machines where you edit your files and one remote server, where you have the repository (check the earlier blog entry for this).

We'll proceed in two steps: 1. creating password-less ssh access to the server. 2. using anacron to automate the svn commit.

Step 1: You'll need password-less access by ssh to the server from your computer. Our new way of accessing the server is actually harder to break than a password. It is straightforward.

You create a public key, either an RSA key [wikipedia] or a DSA key [wikipedia].
> ssh-keygen -t rsa
or
> ssh-keygen -t dsa

Accept the default locations for saving the public key (~/.ssh/id_rsa or ~/.ssh/id_dsa) and press enter twice for empty password.

Now we have to install the newly created public key on the server. This works by appending the public key to your ~/.ssh/authorized_keys (check the server's /etc/ssh/sshd_config if you are not sure about the file). Let's use the tool openssh provides us with.
> ssh-copy-id -i ~/.ssh/id_rsa.pub remoteserver

(substitute id_dsa.pub if you use DSA).

Now we should have password-less ssh access to the server.

Step 2: Automate subversion. Cron is a unix program which allows us to schedule execution of jobs at intervals specified in days. Anacron catches up on jobs that haven't run because the machine was switched off, so we are save if anacron is enabled (in ubuntu check under system -> administration -> services).

The configuration file for cron has the following format (column-separated by white spaces):
minute hour day_of_month day_of_week command

An asterisk (*) means every instance.

We edit our cron configuration by typing crontab -e and add a new line, e.g.
0 4 * * * svn commit localpath -m 'daily update'

This means we want to execute svn commit at 4:00 every day. localpath is the directory that you wish to have under regular version control.

That's it and it should work. See ubuntu community cron howto for more examples on the use of cron.

In another post I compare some commercial providers of remote backup servers.

2 Responses to "Automated Backup using Subversion"

Howdy! Would you mind if I share your blog wth my facebook
group? There's a lot of olks that I thiunk would really
enjoy your content. Please let me know. Many thanks

Also visit my blog post - heel pain relief orthotics

Hey there just wanted to give you a quick heads up.

The text in your post seem to be running off the screen
in Chrome. I'm not sure if this is a formatting issue or something to
do with browser compatibility but I thought I'd post to
let you know. The design look great though! Hope you get the issue resolved
soon. Kudos

My blog: free download

  Subscribe to replies to this post

 
This conversation is missing your voice. Your feedback is appreciated.
Post a Comment


You can use some HTML tags, such as <b>, <i>, <a>

If you see a message that says "your request could not be processed" press preview first and then post.
 
You can follow the discussion of this post by subscribing.


 
You are free to include information from this article on your own site if you provide a backlink. You can use the following markup:
<a href="http://www.myoutsourcedbrain.com/2008/09/automated-subversion.html">Automated Backup using Subversion</a>