Sep 8, 2008

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.

10 comments:

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

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

    ReplyDelete
  3. Simply desire to say your article is as amazing. The
    clarity in your post is simply cool and i could assume you're an expert on this subject.

    Well with your permission let me to grab
    your RSS feed to keep up to date with forthcoming post.
    Thanks a million and please keep up the gratifying work.

    my weblog kviklån

    ReplyDelete
  4. Giѵing up fast food snacks and cooking оf soups and stews rich in vegetabbles is the best idea, and aԀopt tҺe hɑbit of
    eating every day one salad. It oothes iгritated tissues, heals wounds
    and protects the respiratory system. It has been a ong known fact that exeгcise has been shown to stop bone
    loss.

    My blog - laxative

    ReplyDelete
  5. With havin so much content and articles do you ever
    run into any issues of plagorism or copyright infringement?
    My website has a lot of completely unique content I've either created myself or outsourced but it seems a lot
    of it is popping it up all over the internet without my authorization. Do you know any techniques to
    help reduce content from being stolen? I'd
    genuinely appreciate it.

    Review my webpage - chaos multiplayer air war hack

    ReplyDelete
  6. What's up, I log on to your new stuff on a regular basis. Your humoristic
    style is awesome, keep up the good work!

    Feel free to visit my webpage: link Pyramid

    ReplyDelete
  7. It's rеally veгy complicated іn this fսll off activity life to listen news onn Television, ѕo I just use web fօr that reason, and ցet the moѕt սp-to-ɗate news.



    Аlso visit mү website - clash of clans triche gemmes illimite

    ReplyDelete
  8. Greate pieces. Keep writing such kind of info on your blog.
    Im really impressed by your site.
    Hello there, You've done an incredible job. I will
    certainly digg it and in my opinion recommend to my friends.
    I'm confident they'll be benefited from this website.


    my page: شركة تنظيف منازل

    ReplyDelete
  9. Hey there! I'm at work browsing your blog from my new
    iphone! Just wanted to say I love reading your blog and look forward to
    all your posts! Keep up the great work!

    Here is my blog: truck driver questionnaire

    ReplyDelete
  10. Hi there, I discovered your site by the use of Google whilst searching for a
    similar topic, your website came up, it appears to be like
    good. I have bookmarked it in my google bookmarks.
    Hi there, simply became alert to your weblog through Google, and
    found that it is really informative. I am gonna watch out for
    brussels. I will appreciate if you proceed this in future.
    Lots of people shall be benefited from your writing.

    Cheers!

    my blog post: personal injury lawyer uk ()

    ReplyDelete