Projects >> Backup
Want more?
Rate This!
@ hotscripts.com
Backup adds instant version control to any file on a *nix system.

Synopsis

Create a backup of an Apache config file. This is the first backup of the file.

$ pwd /etc/httpd/conf $ ls httpd* httpd-std.conf httpd.conf $ backup httpd.conf A: /etc A: /etc/httpd A: /etc/httpd/conf A: /etc/httpd/conf/httpd.conf

Now make a change, and create a new backup.

$ vi httpd.conf $ backup -c "Enabled server-status" httpd.conf U: /etc/httpd/conf/httpd.conf

List the available backups.

$ backup -l httpd.conf Backups of /etc/httpd/conf/httpd.conf: 35: 01/23/06 13:26:37 - Enabled server-status 34: 01/23/06 13:25:53

Restore the backup from edition number 34.

$ backup -rv 34 httpd.conf R: /etc/httpd/conf/httpd.conf.v34 $ ls httpd* httpd-std.conf httpd.conf httpd.conf.v34

Are they really different?

$ diff httpd.conf httpd.conf.v34 1031,1036c1031,1036 < <Location /server-status> < SetHandler server-status < Order deny,allow < Deny from all < Allow from .example.com < </Location> --- > #<Location /server-status> > # SetHandler server-status > # Order deny,allow > # Deny from all > # Allow from .example.com > #</Location>

Description

Do you hate *.bak and *.20050101 and *.cjn (your initials here) and *.do.not.touch files as much as I do? They litter your filesystem any time someone (and we're all guilty of it) needs to back-up a file they're working on. But who ever comes back and cleans the mess up? At what point is an old backed-up file no longer needed? And what about when you need that backup file only to discover that it's missing, or you didn't capture one because you didn't want to add clutter? Backup is my answer to all that. It adds instantly available, reliable version control to every file in the filesystem.

Backup is a lightweight interface to the Subversion svn_fs library. It uses the powerful version control software as a backend to a simple and minimalistic (though effective) user interface. It is designed for use on Linux/Unix (including OS X) systems as a method of archiving configuration files that change semi-frequently, but do not necessarily warrent their own version control mechanism or repository. Things like "/etc/hosts" or "httpd.conf".

It can create a backup of any file without having to import it first, without worrying about setting up new repositories, and (because it speaks directly to the FS layer) without littering hidden ".svn" (or even worse, visable "CVS") directories all over the place. It does this by using a single global "archive," which contains a filesystem that mirrors your root as you add to it. You can view the archive and restore files, do diffs, and move things around as necessary. For more complex administration, the archive is a standard Subversion file system which can be administrated with any compatable client (including the 'svn' command line tools).

The current version is knocked together in Perl. It's alpha, but it is pretty functional... at least for a proof of concept. Eventually I plan to re-write it in C... but we all know about "the best laid plans." In the mean while, the Perl version does work... mostly. The only real trick is that you need to compile and install the Subversion bindings for it Perl. There are some other modules you may need as well, but they're all fairly standard.

Usage

You probably shouldn't if you you're doing mission-critical work. It's still alpha code after-all. But if you do decide to give it a spin, don't blame me for any breakage (the only thing that should damage existing files is the combination of '-r' and '-o', which will overwrite during a restore).

The Archive

Note that backup needs a Subversion repository (called the "archive") to store the files it makes backups of. To set the location of the archive, define the environment variable "BACKUP_PATH".

To create an archive from scratch:

$ ls -l /tmp/backup_path ls: /tmp/backup_path: No such file or directory $ export BACKUP_PATH=/tmp/backup_path $ backup -k M: /tmp/backup_path

Usage

I suggest throwing backup into a directory in your path (~/bin is usually a good choice), or creating an alias, as I do.

$ alias backup="~/bin/backup.pl" $ backup --version Version: backup v0.1a

For usage and documentation, you have two standard choices:

$ backup -h Usage: backup [-abcfiqsw] [FILE...] backup -d [-rsv] FILE backup -k [-s] PATH backup -l [-abcefinsvw] [FILE...] backup -m [-abcfipsw] [FILE...] PATH backup -r [-abefioqstvw] [FILE...] backup -z [-abcfiqsvw] [FILE...]

Or, to see the full man page:

$ backup --man