How To Easily Backup Your Files Using Svn

28 Nov 2008 15:00

There are two kinds of people:

  • those who backup their files
  • and those who will

Today I will blog about backups.


There are many backup solutions, but actually the idea of backing data up is straight and simple. Backups are about periodically copying files to some other machine. This way we can access copied files even if the original files were lost.

There are two main causes for data loss:

  1. hardware failure
  2. human mistake

From my experience, the latter happens more often than the first.

My way of doing backups

I manage my documents backup using SVN (a.k.a. Subversion). SVN is used mostly by programmers to store the source code for their projects. What is Subversion cool about:

  • central repository stores files and their history
  • access to all historical version of every file
  • two-way synchronization with repository
    • update — get the changes from the repository and apply them to files on the local disk
    • commit — apply the changes made on the local disk to the repository
      • after a successful commit, repository files matches exactly files from your disk
  • WWW access to the newest version of every file

So what do we need to backup files using SVN?

  1. a repository
  2. we need to upload (commit) the first version of the directory that is to backed up every now and then
  3. we need to commit the directory changes (more or less) regularly
    • once we understand how this works, we can write an easy script and create a cronjob (if you're Linux/Mac user)

What we get?

  1. files are copied over the network to some other place than the local disk
  2. history of file changes — access to every file version (one version per backup)
  3. web access to our documents — in case we don't have our computer when we need a document
    • if the SVN repository is publicly accessible
  4. incremental backups — only files that changed are sent through the network (and if the files are textual only the differences are sent)


How to upload the initial version of files

# go to the directory
cd /dir/you/want/to/back/up
# next line is optional (in case the directory is system, like /etc)
sudo su -
svn co http://URL/to/the/public/repository
# supply the user and password when svn asks for them
svn add * .[^.]*
# you can skip the .[^.]* if you don't care about the hidden files or don't have any
svn commit -m 'initial backup'
# this will transfer all of your files to the server. You're done.

How to commit local changes to the repository

cd /dir/you/want/to/back/up
# next line is optional (in case the directory is system, like /etc)
sudo su -
svn commit -m 'another backup'
# this will transfer all of your files to the server

How to access the last version of some file

Just navigate your browser to the repository URL (it should start with http or https). Supply user and password… and your browsing your files!

How to access older version of files

You need to grab some SVN client, supply the repository URL, user and password and use the program interface to navigate through revisions (versions), directories and files.


Using SVN can greatly simplify backups of important documents. Additionally, with no effort, you get a browsable version of the directories you backup.

I recommend this solution to everyone. However you should know, that SVN creates .svn directory in every directory it backs up. This can be just OK or totally unacceptable for some directories (like system or application data). So use at your own risk.

Previous post: News From Piotr

Next post: Oszukańá

More posts on this topic


Add a New Comment
or Sign in as Wikidot user
(will not be published)
- +
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License