Share Files and Collaborate With Subversion

488

Have you ever wondered how can you share and collaborate on files with your colleagues/team-members in an easy and secure way?

One possibility is to use Subversion, a small version control server and client, which you can find in most Linux distributions.

Subversion enables you to keep your files (and changes on them) synchronized with your colleagues by storing the folder-tree in a so called repository.

Additionally, Subversion keeps a history of file-changes, giving the chance to roll back to an older version whenever you think it’s necessary (e.g., you have deleted some content from a file by accident)

How it Works?

You will create a repository on the server (a storage for your files), where you will store your uploaded files and changes, and from where you will download the files submitted by others, or the changes made on your files.

In the Subversion’s context:

  • A commit means “upload all new and changed files to the repository”
  • An update means “download all new and changed files”
  • An add means “add this new file to the list of managed/synchronized files”

    (There are many more commands, but now we are getting familiarized with the basics).

    The Workflow

    In order to share your files and changes on them you will do the following:

    1. Create a new file (an OpenOffice.org document for example)
    2. Issue svn add myfile.odt
    3. Issue svn commit

    When you would like to download the new files created by your team members, or the files which were changed by them you will issue:

    svn update

    This command will download all the changes in the repository (including deletions)

    That’s It, Let’s Take Action!

    Install the subversion server and tools on the server:

    (Please note: the examples are valid for Debian/Ubuntu, although if you know how to install with the package manager of your distro, the configuration may work for you too)

    sudo apt-get install subversion subversion-tools

    On Red Hat/Fedora/CentOS the command would be:

    yum install subversion subversion-tools

    Create a user named “svn”:

    useradd svn

    Now let’s create the folder structure for the repository:

    svnadmin create /path/to/repository

    this may look like:

    svnadmin create /opt/repository

    Now you should add to the rc.local file the svn server launching line in order to start the server automatically, whenever the system starts. Open with a text editor the /etc/rc.local file (don’t forget you need to sudo if you’re not root):

    sudo mcedit /etc/rc.local

    And add the following line before the last line (exit 0):

    /usr/bin/sudo -u svn /usr/bin/svnserve -d -r /path/to/repository

    Now we finished the server part in the first run, let’s change to the client (your desktop computer for example) and create the folder structure:

    mkdir ~/MySyncedDocuments

    …and import it, to the repository:

    svn import mysynceddocs svn://host_name/repository/ /MySyncedDocuments -m "First Import"

    Now, let’s create a file named test.txt in the ~/MySyncedDocuments folder, than change to this directory and issue:

    svn add test.txt
    svn commit -m "Adding test document"

    Congratulations: you added the first document to the repository.

    Now change to the computer which is used by your peer, with whom you’d like to share the files, and create the same directory:

    mkdir ~/MySyncedDocuments
    cd ~/MySyncedDocuments
    svn checkout svn://host_name/repository/ mysynceddocs

    Now, you should have in this folder the document named test.txt. Let’s open it and make a change (add a new line for example, than save it.)

    Issue this command:

    svn commit

    Let’s go back to your computer and issue:

    svn update

    You should have the newest version of the test.txt document, which contains the new line at the end of the file.

    You may still need to poke around with the security settings, creating users and passwords, by editing the following files on the server:

    /path/to/repository/auth/authz

    and

    /path/to/repository/auth/passwd

    For Heavy Desktop Users

    I know, you’re a desktop user, and you need easier acces to these features. There are multiple possibilities, for example you can use as a client:

    Rapidsvn:

    apt-get install rapidsvn

    or Subcommander:

    apt-get install subcommander

    There’s also a Nautilus (GNOME’s file browser) script, called nautilussvn (while promising, is still a big resource-hog):

    http://code.google.com/p/nautilussvn/

    Stay tuned; in my next tutorial I’ll show to you some bash scripts which will help heavy desktop users to make file synchronization in a hassle-free manner.

    Cheers