Backup and Restore

These are two shell scripts for backing up and restoring files to/from magnetic tapes, or file archives. They extend the functionality of the Unix tar program to selective restoring.

fpbackup

Backs up files or entire directory trees.
Synopsis
fpbackup [-m <target>] [-i <timestamp>] File1 File2 ...
Parameter
-m <target>
sets the target of the backup, this means, where to store the created archive. There are three possibilities:
  1. A Unix character device, like a magnetic tape. This device must be writeable, and it is assumed it contains enough free space to hold the data.
  2. A single hyphen '-' as target sends output to the standard output. This allows piping of the program's output to other programs, like a compressor. This is the default.
  3. A filename to hold the data. This file must not exist.
-i <timestamp>
This option allows incremental backups. timestamp is a standard file; files are only backed up if they are more recent than this timestamp file. If you give a single hyphen '-' as timestamp file, '/tmp/lastbackup' is used. This default file is automatically refreshed for each backup.
You can create a timestamp file with the Unix touch utility.
File
names a single file or a directory. In the latter case, the complete directory tree is backed up. You can only back up files with absolute pathnames (with a leading slash) if you call the program from the root directory.
Return values
These are the values returned to the shell after the program has exited. All error cases (values > 0) also cause an error message.
0
The backup has completed successfully. An exception are errors within the tar subprocess which cannot be checked for (but they cause an error message on screen).
1
The file /tmp/backuplist exists. This can be caused by a simultaneously running backup. If you are sure there are no other backups in process, you can delete this file.
2
The program was called without parameter.
3
The target device does not exist, is not writeable, or the given archive filename exists or is not writeable.
4
The timestamp file for an incremental backup does not exist.
5
A file or directory scheduled for backup does not exist or is not readable.
6
No files to backup.
7
An incremental backup was requested, but no files more recent than the timestamp files were found.
8
An attempt was made to save a file with absolute pathname from elsewhere than the root directory.
Usage notes
All files are saved with relative pathnames. Files with absolute pathnames are automatically given a './' prefix, '/usr' becomes './usr'. This is the reason why you can only backup files with absolute paths from the root directory. This procedure allows for later non-destructive restoration of files.

It is checked whether the device might be a magnetic tape. If the device name contains

mt
then the 'mt' command is used to write an EOF mark behind the archive if the device is non-rewinding.
ct
then the 'tape' command is used to write a file mark at the end of the archive if the device is non-rewinding.
If you want to use this program to back up multiple directory trees, then you can simply copy the automatically created timestamp file '/tmp/lastbackup' to any location and later use it with the '-i' option.

If you give the '-i' option, then the given timestamp file's date is automatically set to now for future usage.

fprestore

Restores files or entire archives. If the archive was created by fpbackup, then you can selectively restore by using regular expressions.
Synopsis
fprestore [-m <source>] [Pattern1 Pattern2]
Parameter
-m <source>
sets the source of the backup, this means, where to read the archive from. There are three possibilities:
  1. A Unix character device, like a magnetic tape. This device must be readable.
  2. A single hyphen '-' means to read the archive from the standard input, e.g. from the output of an uncompressor. This option is the default.
  3. A filename to read from. The file must exist and be readable.
Pattern
A regular expression file pattern (see documentation of egrep or regexp). In its most simple case, this is only a substring. Remember that you must escape special characters like '*' to the shell.
Return values
These are the values returned to the shell after the program has exited. All error cases (values > 0) also cause an error message.
0
The restore has completed successfully. As with the backup, errors within the tar subprocess cannot be detected. They cause an on-screen error message, but do not alter this 'success' value.
1
The file /tmp/backuplist exists. This can be caused by a simultaneously running backup. If you are sure there are no backups in process, you can delete this file.
2
The program was called without parameters.
3
The medium or file does not exist or cannot be read.
4
The archive filelist, which was created by 'fpbackup' does not exist in the archive. You cannot selectively restore from this archive, but restore the complete contents by calling the program without file patterns.
5
An attempt was made to selectively restore files from standard input, which is not possible.
6
A file pattern to restore was give, but no fitting files were found.
Usage notes
All files are restored into the current directory or appropriate subdirectories, which are created as needed. If you want to overwrite the restored files, you must run fprestore from the same directory where you have previously called fpbackup from.

If you gave a non-rewinding tape device as restore medium, the tape is left at the end of the archive.

If you are restoring from tape, it is not possible to selectively restore files from an archive not at the beginning of the tape. You must first copy the full archive to disk with the 'dd' utility, and then you can selectively restore from disk.

When restoring from standard input, you cannot give file patterns, but must use explicit file names (including the complete pathname).

Usage examples

  1. Simple backup of the /usr directory tree to /dev/rmt/0 (the magnetic tape on the SUN)
    1. Backup:
      cd /
      fpbackup -m /dev/rmt/0 /usr
    2. Restoring the complete directory tree:
      cd /
      fprestore -m /dev/rmt/0
    3. Restoring all include-files:
      cd /
      fprestore -m /dev/rmt/0 "include/*.h"
    4. Restoring the program 'vi' without overwriting the original:
      cd /tmp
      fprestore -m /dev/rmt/0 vi
      This restored 'vi' to /tmp/usr/bin/vi

  2. Backup of a user's home directory to a file
    1. Backup:
      cd /u/frank
      fpbackup -m /tmp/backup .
    2. Restoring all C files
      cd /u/frank
      fprestore -m /tmp/backup "*.c"
    3. Reincarnating the user's home elsewhere
      mkdir /user/frank
      cd /user/frank
      fprestore -m /tmp/backup

  3. Incremental backup of the /usr directory tree. We assume that we have previously backed up the directory as in 1. and then copied the timestamp file to /usr/timestamp. We again use the SUN tape device.
    1. Backup:
      cd /
      fpbackup -i /usr/timestamp -m /dev/rmt/0 /usr
    2. Restoring the complete tree
      cd /
      fprestore -m /dev/rmt/0

  4. Advanced usage: Backing up a directory, using the compressor 'gzip' to compress the archive before writing it to the tape.
    1. Backup:
      cd /u/frank
      fpbackup -m - . | gzip -9 | dd of=/dev/rmt/0
    2. Completely restoring the archive
      cd /u/frank
      dd if=/dev/rmt/0 | gunzip | fprestore -m -
    3. Selectively restoring the file fpbackup from this archive. We know that this file is located in the subdirectory '1995'.
      cd /u/frank
      dd if=/dev/rmt/0 | gunzip | fprestore -m - ./1995/fpbackup
    4. Selectively restoring all C files. This is not directly possible, we must first uncompress the archive to disk.
      cd /u/frank
      dd if=/def/rmt/0 | gunzip > /tmp/backup
      fprestore -m /tmp/backup "*.c"
I hope these programs are of some use to you.


Frank Pilhofer <fp -AT- fpx.de> Back to the Homepage
Last modified: Wed Apr 12 20:48:59 1995