backup.pl -- Automated interface to create `dump/restore' or `dar' backups.
backup.pl [--test] [--verbose] [--usage|-?] [--help]
[--date=<string>] [--name-prefix=<string>]
[--file-name=<name>]
[--dump-program=<dump-prog>] [--[no]dar]
[--restore-program=<restore-prog>]
[--gzip | -z] [--bzip2 | -y]
[--dest-dir=<destination-dir>] [--dump-dir=<dest-dir>]
[--volsize=<max-vol-size>]
[--partition=<block-special-device> | <partition> ]
[--level=<digit> | <level>]
This script creates and verifies a backup dump using the `dump' and `restore' programs, or the `dar' program, both of which are linked below.
The product of this procedure is a set of dump files on disk somewhere
that has been verified against the backed-up partition. More than one
file may be required if the dump is to be written to offline media; in
that case, use the --volsize option to limit the maximum file size.
If not supplied, a suitable series of file names is chosen based on
the partition mount point, current date, and backup level.
Optionally, the file can be moved to somewhere else in the destination
file system after it has been verified; this makes it easy to use the
cd-dump.pl script to write the resulting dump file(s) to a CD. The
whole process is readily automatable via cron jobs.
[Writing to tape probably doesn't work; I have no tape on my system, so I don't know how to rewind it. -- rgr, 21-Oct-02.]
Each dump file name looks something like home-20021021-l9.dump or
home-20051102-l0a.dump, or home-20051102-l0.17.dar for DAR, and
consists of the following five components:
A prefix tag (e.g. home). This is normally the last component of
the directory where the partition is mounted, but can be specified via
the --name-prefix option. The tag is arbitrary and may consist of
multiple words, as in usr-local; its purpose is solely to group all
of the backups make for a given partition.
The date the backup was made. This is normally the current date in
``YYYYMMDD'' format, e.g. '20021021', but can be overridden via the
--date option.
The dump level as specified by --level, a digit from 0 to 9, with a
lowercase ``L'' prefix, as in l9.
An optional volume suffix. DAR creates them by appending .#.dar to
the stem, where ``#'' is a number starting from one; all DAR backups
always have an explicit volume suffix. If a dump backup requires
two or more volumes, then alphabetic volume designators are assigned
from 'a', as in home-20051102-l0a.dump, home-20051102-l0b.dump,
home-20051102-l0c.dump, etc. This is only necessary for large
backups that are later copied to physical media. [Note that
mkisofs imposes a limit of 2147483646 bytes (= 2^31-2) on files
burned to DVD-ROM; see the ``DVDs created with too large files'' thread
at
http://groups.google.com/group/mailing.comp.cdwrite/browse_thread/thread/423a083cc7ad8ee8/fecd18c0f8507901%23fecd18c0f8507901
for details. -- rgr, 4-Nov-05.]
A file suffix (extension), which is ``.dump'' for dump backups, and
(not surprisingly) ``.dar'' for DAR backups.
If the --file-name option is specified, then it overrides the first
three components. There is no way to override the volume suffix or
file suffix.
If specified, no commands will be executed. Instead, the commands will just be echoed to the standard error stream.
If specified, extra information messages are printed during the backup. Since the output of dump and restore are included unedited, the default output is pretty verbose even without this.
If specified, gives the name of the dump file excluding the directory.
The default looks something like home-20021021-l9.dump, and depends
on (a) the last component of the directory where the partition is
normally mounted, e.g. 'home', (b) the current date, e.g. '20021021',
and (c) the dump level, e.g. '9'. Suffixes of 'a', 'b', etc., will be
added after the dump level if needed for a multivolume dump.
If some of the default values are
not acceptable, you can either specify a specific file name, or use
the --name-prefix or --date parameters to override how the
default name is constructed. For example, if you had '/usr/local' and
'/seq/local' partitions and needed to make the resulting file names
distinct, you could say "--name-prefix=usr-local" for the first,
and "--name-prefix=seq-local" for the second.
Overrides the date value in the default dump file name; see the
description of the --file-name option.
Overrides the partition abbreviation (the last file name component of
the mount point) in the default dump file name; see the description of
the --file-name option.
Specifies the names of the dump and restore programs to use. The
defaults are '/sbin/dump' and '/sbin/restore', respectively, followed
by whatever it can find on $PATH.
If you specify a --dump-program that ends in ``dar'', backup.pl
will assume the use of --dar, and use '/usr/bin/dar' as the default
--dump-program. If --dar is specified or implied, then
--restore-program is ignored.
Use the DAR (Disk Archiver) program to create the dump. If you
specify a --dump-program that ends in ``dar'', backup.pl will
assume the use of --dar. In order for incrementals to work, you
must have a previous catalog or dump set in the same destination
directory. See dar for details.
If you specify a full (level 0) DAR dump, backup.pl will
automatically create a catalog of it using the base name of the dump
plus ``-cat'', e.g. home-20080521-l0-cat.1.dar for a
home-20080521-l0.*.dar full dump set. This is so that we can
create L1 dumps of everything since the full dump without having to
keep all of the full dump around, which DAR would otherwise require.
Specifies the bzip2 or gzip compression level; the default is no compression. The optional integer values are for the compression level, from 1 to 9; if omitted, a value of 9 (maximum compresssion) is used. Note that these options are only available for DAR.
If specified, names a directory to which we should move the dump file
after it has been verified successfully. This directory must exist
and be writable by the user running backup.pl The default is ``.''
(the current directory).
Specifies a temporary directory to which to write the dump file. If
the backup fails, any dump in progress is left in this directory to
aid debugging, without interfering with any vacuum.pl job that is
supposed to pick up completed dumps. The --dump-dir defaults to
tmp underneath --dest-dir, and must be on the same partition as
--dest-dir; it is created if it does not exist.
The name of a block-special device file for the ext2 or ext3 partition
that is to be backed up, e.g. /dev/hda12. There is no default;
this option must be specified. A positional partition argument is
also supported for backward compatibility.
A digit for the backup level. Level 0 is a full backup, level 9 is the least inclusive incremental backup. For more details, see dump(8), or my ``System backups'' page (http://www.rgrjr.com/linux/backup.html). The level defaults to 9. A positional level argument is also supported for backward compatibility.
Specifies the size of the largest dump file that the backup medium can
hold, in 1 kilobyte blocks. If the backup medium fills up before
this limit is reached,
then dump will pause and wait for you to ``change volumes'' (by renaming
the current dump file) before continuing, which will mess up the
'restore' phase of the operation. The default depends on the --cd
option.
If the dump requires multiple volumes, backup.pl will instruct
dump to write a series of files into the same directory (so the
directory must have enough space for all of them). This is ideal for
unattended creation of multiple backup files to be copied onto
multiple physical volumes at a later time. Just be sure to specify a
--volsize that fits on the ultimate storage medium.
Note that dump can do physical end-of-media (tape) and disk-full
detection on its own. This is only useful if (a) you are writing
directly to the end medium, and (b) you are around to change media
when they fill up.
[need some. -- rgr, 7-Jan-03.]
If this script used a backup.conf file, it could get per-site defaults,
plus instructions for doing a number of backups at once, This would
greatly simplify backup crontab entries; only one would be needed.
backup.pl should refuse to proceed if the size of the dumps it
produces are expected to be larger than the free space remaining on
the disk. If you can't finish, there's no point getting started.
Unfortunately, computing the likely size without actually doing the
dump is impossible if compression is used.
The --bzip2 and --gzip options should be supported for
dump/restore as well.
If you find any more, please let me know.
cd-dump.pl (http://www.rgrjr.com/linux/cd-dump.pl.html)
Copyright (C) 2000-2011 by Bob Rogers <rogers@rgrjr.dyndns.org>.
This script is free software; you may redistribute it
and/or modify it under the same terms as Perl itself.
$Id: backup.pl 245 2011-03-12 18:28:23Z rogers $
Bob Rogers <rogers@rgrjr.dyndns.org>