Mike Heins > Snapback2-1.001 > Backup::Snapback

Download:
Snapback2-1.001.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  6
Open  2
View/Report Bugs
Module Version: 1.001   Source  

NAME ^

Backup::Snapback - routines for support of rsync-based snapshot backup

SYNOPSIS ^

  use Backup::Snapback;
  my $backup = new Backup::Snapback %opts;

DESCRIPTION ^

Snapback2 does backup of systems via ssh and rsync. It creates rolling "snapshots" based on hourly, daily, weekly, and monthly rotations. When it runs for some period of time, you will end up with a target backup directory that looks like:

        drwx--x--x   81 106      staff    4096 Jan  1 05:54 daily.0
        drwx--x--x   81 106      staff    4096 Dec 31 05:55 daily.1
        drwx--x--x   81 106      staff    4096 Dec 30 05:55 daily.2
        drwx--x--x   81 106      staff    4096 Dec 29 05:54 daily.3
        drwx--x--x   81 106      staff    4096 Dec 28 05:53 daily.4
        drwx--x--x   81 106      staff    4096 Dec 27 05:53 daily.5
        drwx--x--x   81 106      staff    4096 Dec 26 05:53 daily.5
        drwx--x--x   81 106      staff    4096 Jan  1 05:54 hourly.0
        drwx--x--x   81 106      staff    4096 Dec 31 17:23 hourly.1
        drwx--x--x   81 106      staff    4096 Jan  1 05:54 monthly.0
        drwx--x--x   81 106      staff    4096 Dec  1 05:54 monthly.1
        drwx--x--x   81 106      staff    4096 Dec 28 05:53 weekly.0
        drwx--x--x   81 106      staff    4096 Dec 21 05:53 weekly.1
        drwx--x--x   81 106      staff    4096 Dec 14 05:53 weekly.2
        drwx--x--x   81 106      staff    4096 Dec  7 05:53 weekly.3

You might think this would take up lots of space. However, snapback2 hard-links the files to create the images. If the file doesn't change, only a link is necessary, taking very little space. It is possible to create a complete yearly backup in just over 2x the actual storage space consumed by the image.

METHODS ^

The Backup::Snapback module is designed to be front-ended by a script such as the included snapback2. Its methods are:

new

Constructs a new Backup::Snapback object. Accepts any Snapback config file option, plus the special option configfile, which supplies the configuration file to read. If the passed configfile is not set, the standard locations are scanned.

Standard locations are $HOME/.snapback/snapback.conf if not executing as root, otherwise always in order:

        /etc/snapback2.conf
        /etc/snapback/snapback2.conf
        /etc/snapback.conf
        /etc/snapback/snapback.conf

Returns the snapback object. If the constructor fails, undef will be returned and the error will be available as $Backup::Snapback::errstr.

Called as usual for a perl object:

        ## classic constructor
        my $snap = new Backup::Snapback configfile => '/tmp/snap.conf';

        ## standard constructor
        my $snap = Backup::Snapback->new( ChargeFile => '/tmp/snap.charges') ;
errstr

Called as either an object method:

        $self->errstr;

or as a class method:

        Backup::Snapback::errstr;

Returns the most recent error text.

config

Gets or sets configuration parameters. The base is set in hardcoded program defaults; it then is overlayed with the configuration file results. If a configuration block is entered, those settings override the parent configuration block. Finally, internal setting can be done, temporarily overriding configuration file settings (because of option dependencies).

    my $compress = $snap->config(-Compress);

        # turn off compression
        $snap->config( Compress => No);

Some options are boolean, and some accept the special value 'none' to set them empty.

Parameter names are not case-sensitive.

log_error

Logs an error message to the configured log file. If no log file is specified (default is /var/log/snapback or $HOME/.snapback/snapback.log depending on user ID), then no error is logged.

Formats messages with sprintf() if appropriate.

        $snap->log_error("Backup failed for client: %s.", $client);
file_handle

Returns the file handle of a file already opened with log_arbitrary or log_error. To open a new file, do $self->log_arbitrary($file);

get_tmpfile

Get a temporary file name which will be unlinked when the object is destroyed.

backups

Returns the name of all of the backup blocks active in the current configuration file.

If the file had:

        <Backup foo.perusion.org>
                Directory /home/foo
        </Backup>
        <Backup pseudo>
                BackupHost foo.perusion.org>
                Directory /home/baz
        </Backup>
        <Backup bar.perusion.org>
                Directory /home/bar
        </Backup>

The call $snap-backups()> would return:

        ('foo.perusion.org', 'pseudo', 'bar.perusion.org')

Returns a reference or list based on call context.

set_backup

Sets a particular block active as the current backup. Returns the passed parameter.

directories

Returns the name of all of the backup blocks active in the current configuration file.

Must be preceded by a $snap-set_backup($client)> call.

If the file had:

        <Backup foo.perusion.org>
                Directory /home/foo
                Directory /home/baz
                Directory /home/bar
                <Directory /home/buz>
                        Hourlies 2
                </Directory>
        </Backup>

The call sequence:

        $snap->set_backup('foo.perusion.org')
                or die "No backup configuration!";
        my @dirs = $snap->directories();

would return:

        ('/home/foo', '/home/baz', '/home/bar', '/home/buz')

Returns a reference or list based on call context.

set_directory

Sets a particular directory as active for backup. Must have set $snap->set_backup() previously, returns undef on error.

backup_directory

Performs a directory backup after set_backup and set_directory have been called.

backup_all

Iterates through all Backup blocks in turn, backing up all directories.

CONFIGURATION ^

See snapback2.

SEE ALSO ^

snapback2(1), snapback_loop(1), snap_charge(1)

See http://www.mikerubel.org/computers/rsync_snapshots/ for detailed information on the principles used.

syntax highlighting: