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
> 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.