Antonio Bonifati's Home Page

Farmer, Italian language teacher, Lisp functional programmer, sysadmin and free-software fellow

Installation

A bash(1) script named setup is provided for easy installation. The simplest way to use it is:

# ./setup -i 

This assumes bash(1) is installed in /bin/bash as in Linux. If it is installed somewhere else, e.g. /usr/local/bin/bash as in FreeBSD, you will have to explicity invoke it:

# bash setup -i 

Please see the INSTALL file included with the tarball if you need more control over the installation paths.

When installation completes, a message showing the location of configuration file will be printed:

Please check configuration file
        /usr/local/etc/bak.conf
before using bak. 

Configuration

Using any plain text editor modify configuration file as suggested below before launching bak for the first time. I embedded many comments in the file to help you.

The most important variable is source which is the list of files and directories to backup. Each path must be separated by whitespace characters and newlines must be preceded with a backslash. An example:

source=(/etc/{asound.state,ppp/ip-up} \
        /home/*/{bin,.bashrc,.profile} \
        /usr/local/{bin,sbin,etc/bak.conf})

Here I used brace and wildcard expansion ("globbing") to avoid repetition of common prefixes in paths and the annoyance of listing the users of the system one by one.

When parsed by the shell, the previous list will expand to something close to the following, assuming there are only two users, joe and bud:

source=(/etc/asound.state /etc/ppp/ip-up \
        /home/bud/.bashrc /home/bud/.profile /home/bud/bin \
        /home/joe/.bashrc /home/joe/.profile /home/joe/bin \
        /usr/local/bin /usr/local/sbin /usr/local/etc/bak.conf)

When you don't want pathname expansion to take place, you have to quote with a single or double quote each element of the list that contains special pattern characters such as * ? [ ] { }.

As a system administrator, I also got into the habit of making a backup copy of each configuration file I needed to modify. This allows me to quickly use diff(1) to discover the changes I made at a later time. This proves useful especially when I'm about to upgrade a package and I have to manually merge the new and old configuration files. It also simplifies backup of configuration files: if you are consistent and always use the same extension for default versions of configuration files, find(1) or locate(1) can be used to automatically make backup copies of both default and modified files.

This is supported by bak through the use of two directives: default and mode. The first defines the extension used for default files:

default="\.bak-default"

You can also have multiple extensions if you like, but this is probably less convenient and requires default to be a more complicated regular expression -- see comments in the config file for an example.

The latter directive states whether to use locate(1) or find(1) to search for configuration files to backup:

mode="locate"

I usually prefer locate(1) because it is faster than find(1). Since I keep the locate database updated every day using crond(8) or anacron(8), I know locate(1) will find all modified configuration files, except for those created the same day the backup is taken. If this is a concern to you, you can use the -u command line option when invoking bak to force a locate database update before backing up. This can be made the default behaviour by changing the mode variable to update.

If you don't want to use this auto-locate feature and prefer listing configuration files to backup manually in the source list, just set the default mode to off.

Usage

Once correctly configured, using bak is a snap :-) With no options at all an archive will be createad with the name and path established by the variable outfile in the config file. By default the archive will be written to the current directory and named bak.tgz. You can override outfile value at runtime using the -o <file> option.