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


backup [options]


print this help and exit
print full documentation via less and exit
print version and exit
print intermediate messages for debugging
show the backup directory path and exit
use X as configuration file; if X is -, don’t read any
configuration file and use defaults

From here you must be root:

make a full backup
Show a listing of the current backups
Restore file X in current directory
make partial backup to


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


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.

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.
is an array of directories (including any subdirectories) to be searched.
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.
is an array of regexps matching extensions; files with those extensions are skipped.
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.
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)
 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:


prints help information and then exits
print full documentation via less and exit
prints version and then exits
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,, and so on. Similarly, partial backups are named,, and so on.
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.
        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.

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|.
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.
print debugging messages while running.


Wybo Dekker


Released under the GNU General Public License

Functions used:


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 fileglob
print the newest file matching the fileglob


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 or, where nnn is one higher than that of the reference file.
globals  set:
selector newbackup 
globals used:
full named


human number_of_bytes
prints the number in human-readable form


show the current backups


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


extract filename index withdate
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 filename
Restore the given filename in the current directory
globals  set:
globals used:
backupsfound REPLY workdir


Update archive listings where necessary


list archive
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 name_of_array_variable
echo the name of the variable plus a colon and the array
contents in two columns of width 15 and 50 respectively.
globals used:


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


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