backup backup and restore, full or partial
doc generated from the script with gendoc
bash script, version=3.20

Synopsis

backup [options]

Options

-h|--help
print this help and exit
-H|--Help
print full documentation via less and exit
-V|--version
print version and exit
-v|--verbose
print intermediate messages for debugging
-d|--dir
show the backup directory path and exit
-c|--conf=X
use X as configuration file; if X is -, don’t read any
configuration file and use defaults

From here you must be root:

-f|--full
make a full backup
-s|--show
Show a listing of the current backups
-r|--restore=X
Restore file X in current directory
-n|--named=X
make partial backup to X.zip

Description

Back up files into zip compressed archives, or restore files from those. Both full and partial backups are possible.

Configuration

The selection of files to be backed up is governed by 6 variables. The first two (BackupDir and DirsToSearch) tell where backups are stored and where files to be backed up are searched, respectively. The remaining variables are arrays of Bash regular expressions that act on the full pathnames of the file that are backup candidates.

Important note: the Bash regular expressions (*ReToSkip below) will be automatically adapted by escaping any dots (.) in them: dots occur frequently and in unescaped form they stand for one character, while in the current context it is more useful to mean a literal dot.

BackupDir
is the directory where archives are stored; For safety reasons you would normally make the backup directory a mount point for an other disk than the one(s) containing the information to be backed up.
DirsToSearch
is an array of directories (including any subdirectories) to be searched.
DirReToSkip
is an array of regexps matching directory names to be skipped; any directory for which the name matches one of these expressions will not be searched for files to backup; neither will any of its subdirectories.
ExtReToSkip
is an array of regexps matching extensions; files with those extensions are skipped.
BaseReToSkip
is an array of regexps matching basenames to be skipped; any file for which the basename matches any of these regexps will not be backed up.
FileReToSkip
is an array of regexps matching filenames to be skipped;

Here is an overview of the default settings for these variables:

    BackupDir=/backup/$(hostname -s)
 DirsToSearch=(/home /etc)
  DirReToSkip=(t temp tmp '[Cc]ache' .thumbnails)
  ExtReToSkip=(auk aux bak bku dep err 'lo[fgt]' msf old swp tmp toc tok)
 BaseReToSkip=(t)
 FileReToSkip=(~$ '#$')

Note that these defaults imply that the backups are produced in a directory on the root file system, which is unsafe, and results in a warning.

Configuration files

The default values for the variables described in the previous section can be changed by means of configuration files. backup looks for three configuration files, and uses the first it encounters:

1. a file specified with the --conf option; if --conf=-

   or |-c-| was specified, no configuration file will be
   read at all and the above defaults will be used.
2. ~/.backup.conf, if it exists 3. /etc/backup.conf, if it exists

Note that:

Options

-h,--help
prints help information and then exits
-H,--Help
print full documentation via less and exit
-V,--version
prints version and then exits
-f,--full
Generates a full backup. Without this option, a partial (incremental) backup is made, relative to the most recent backup in the backup directory, that is: in /backup/$(hostname␣-s) if you did not read a configuration file. Full backups will obtain filenames f001.zip, f002.zip, and so on. Similarly, partial backups are named p001.zip, p002.zip, and so on.
-c,--conf=X
Use the given X as configuration file; without this option, backup looks for ~/.backup.conf or, if that file does not exist, for /etc/backup.conf. If none of these is found, backup fails with an error message. See the section "Configuration files" above. The argument is optional; without it, backup reports the configuration file used, and exits.
-r,--restore=X
        Don’t back up, but restore X in current directory from old
        backups instead. Start backup with this option in the directory
        where the file to be restored existed when it was backed up. You
        will see a numbered listing of existing backups, from which you can
        select one by typing its number.
If a file of that name already exists, it will be renamed by adding a |.ver0| extension or, if that exists, |.ver1| or |.ver2| et cetera. You can select all backups by typing |a|; this results in restoring all files with a datetime string attached to the name. Or you can type |q| to cancel your restore request.

-n,--named=X
Set the name of the new backup file to X (instead of pxxx or fxxx). One application is to use this for an hourly backup by adding this entry to your crontab:

   1 * * * * backup --named=t0$(date +%H)

If the name has the format |txxx|, like in the above example, the backup will be relative to the most recent of all files |[fpt][0-9][0-9][0-9].zip|; otherwise it will be relative to the most recent of |p[0-9][0-9][0-9].zip|.
-s,--show
Shows a listing of current backups with the number of files, size of the backup in characters and in human readable form, date, and time.
-v,--verbose
print debugging messages while running.

Author

Wybo Dekker

Copyright

Released under the GNU General Public License

Functions used:


configure

description:
Sets the defaults, and then applies any changes defined in the
configuration file if it exists (/etc/backup.conf by default)
globals  set:
BackupDir DirsToSearch DirReToSkip ExtReToSkip
BaseReToSkip FileReToSkip conffile
globals used:
BackupDir conffile Myname

latestof

synopsis:
latestof fileglob
description:
print the newest file matching the fileglob

setselector

description:
Find the last full or (if the --full option was not used)
partial backup file: that file is the reference file: it's mtime will be used, by setting selector to -newer␣<file>. If it's a full backup, selector is made empty. If there aren't any backups yet, the backup must be full, or an error message is issued. Also, sets the name for the new backup file to pnnn.zip or fnnn.zip, where nnn is one higher than that of the reference file.
globals  set:
selector newbackup 
globals used:
full named

human

synopsis:
human number_of_bytes
description:
prints the number in human-readable form

showbackups

description:
show the current backups

backupsof

synopsis:
backupsof filename
description:
Find basenames, without extension, of all archives containing
the given filename. Store them, with the size and time information, in backupsfound.
globals  set:
backupsfound 
globals used:
workdir

extract

synopis:
extract filename index withdate
description:
extract $workdir/filename from the indexth element of
backupsfound appending the date of the element if withdate is true
globals used:
BackupDir backupsfound workdir

restore

synopsis:
restore filename
description:
Restore the given filename in the current directory
globals  set:
COLUMNS 
globals used:
backupsfound REPLY workdir

updatelistings

description:
Update archive listings where necessary

list

synopsis:
list archive
description:
Create a listing, sorted by decreasing size, of the contents of
the archive. Set the modification time of the archive and its listing to to the most recent regular file in the archive.

verbarr

synopsis:
verbarr name_of_array_variable
description:
echo the name of the variable plus a colon and the array
contents in two columns of width 15 and 50 respectively.
globals used:
verbose

excheck

synopsis:
excheck executable1 [executable2...]
description:
check if all needed execs are there and getopt is GNU

handle_options

synopsis:
handle_options "$@"
description:
Handle the options
globals used:
Myname Version full show restore conffile verbose named