Friday, 29 November 2013

Versioning your /etc under Bazaar in Debian Wheezy

Suppose you've installed some packages on your Linux box, made some configurations and messed your system. Pretty bad! You would like to revert all changes to a previous working state, isn't it? This post explains how you can employ Bazaar in Debian boxes to do that.

The idea is pretty simple: put your /etc into some sort of source control system, like git, bzr, hg or darcs. There's a tool which does just that: etckeeper.

We will also create two other repositories, for high availability purposes: one in the same computer and another remotely.

Let's start: install etckeeper. You will see that /etc/.git is created, because git is the default choice for etckeeper.

Install etckeeper

    $ apt-get etckeeper -y
    $ ls -ald /etc/.git

I prefer Bazaar. So, let's get rid of this .git repository:

    $ etckeeper uninit
    $ ls -ald /etc/.git

Using bzr instead of git

Now it's time to reconfigure etckeeper so that it will user Bazaar instead. Simply edit /etc/etckeeper/etckeeper.conf in order to look like below:

    $ head -5 /etc/etckeeper/etckeeper.conf
    # The VCS to use.

Let's now install Bazaar and create the repository again, this time using Bazaar.

    $ apt-get install bzr -y
    $ etckeepet init
    $ ls -ald /etc/.bzr

Your first commit

Review what was done and perform your first commit.

    $ cd /etc
    $ bzr status | less
    $ bzr commit -m 'first commit'
    $ bzr status

Create a second repository on a separate hard drive

It's now time to create a copy on the same computer, preferably on a separate hard drive:

    $ cd /srv
    $ bzr init --no-tree etckeeper
    $ cd /etc
    $ bzr config push_location=/srv/etckeeper
    $ bzr push

Create a third repository on a server box

It's also a good idea to create a remote repository, like the example below:

    $ ssh myself@server
    $ COMPUTER=penguim
    $ mkdir -p /srv/bzr/etckeeper
    $ bzr init --no-tree /srv/bzr/etckeeper/${COMPUTER}
    $ exit

Back to your local computer, push a copy from your second repository (the one on your second hard drive) onto the remote server:

    $ cd /srv/etckeeper
    $ COMPUTER=$( hostname )
    $ bzr config push_location=bzr+ssh://myself@server/srv/bzr/etckeeper/${COMPUTER}
    $ bzr push

That's it :)

-- Richard Gomes

No comments:

Post a Comment