AIX's backup and restore Utilities
Bill Moraca
Introduction
Devising a backup strategy that balances the needs of
different user
communities, staff availability, and system recoverability
is not
easy, but it is one of the most important responsibilities
of the
system administrator. Finding and using the right tools
can simplify
the task and help ensure the robustness of the system.
This article
reviews the AIX backup and restore commands and presents
a set of scripts based on those commands. Most other
UNIX systems
support commands that work the same as the AIX commands
described
here, but the command name and/or switch syntax may
vary.
The AIX backup Command
Although the AIX operating system supports a number
of commands for
saving and restoring directory files to tape, including
tar
and cpio, the backup and restore utilities
offer the greatest flexibility and control. The backup
command
makes it easy to perform incremental backups (i.e.,
to copy files
created/modified since some past date), and to include
and exclude
files. These capabilities can affect both the number
of tapes required
for backups over the retention period and the time required
to actually
perform the backups.
The backup command supports filesystem backups (by inode)
in addition to regular file and directory backups (by
name). Backups
by inode are issued for a single filesystem and are
always incremental
based on the level parameter, an integer in the range
0-9. The value
0 specifies that the entire filesystem is copied. For
any
other level i, files modified since the most recent
level
i-1 (or lower) backup are copied. backup writes an
eof mark at the end of each fileset, so multiple filesystems
can be written to a single tape when a non-rewinding
device is specified.
If an error occurs on a tape during a restore operation,
data
from the other filesystems can still be recovered. backup
can read from unmounted filesystems, which makes it
possible to ensure
that files are not modified while the backup is in progress.
The backup command to do a level 0 of the /home
filesystem is:
backup -0 -f /dev/rmt0 -u /home
restore commands will be covered later, in the
script discussion.
Recognizing usefulness of backup and restore, one
of my customers had me develop shell scripts with those
commands to
automate backup and restore operations. The rest of
this article describes
those scripts.
Tape Format
As stated earlier, backup by inode is filesystem based.
This means
that a backup command must be issued for each filesystem
to be written
to tape. Each command creates a new backup set on the
tape. Use of
a non-rewinding tape device allows multiple backup sets
to be written
to a single tape. Within a backup set, the filenames
are relative
paths beneath the mount point. For example, the .profile
file
for user billm under filesystem /home would appear
on the tape as ./billm/.profile. If there is more than
one
backup set on a single tape, the sequence of the filesystems
on the
tape must be preserved independently of the filesystems
themselves,
since the mount point (e.g., /home) is not part of the
filename
on the tape. One solution is to use tar to write a header
file at the front of the tape. The header file would
contain the date,
hostname, and the list of filesystems in the order they
were backed
up. It could be read with tar to determine the order
in which
filesystems were written to the tape.
Following is a sample header file for a system with
hostname
"earth."
earth
Tue Aug 23 23:30:05 EST 1994
This is a level 0 backup.
1 /
2 /usr
3 /var
4 /home
5 /userfilesys1
6 /userfilesys2
The scripts described here use a header file named /tmp/!backuplist.
The filesystems are backed up in sequence after the
tar file.
Backup Script
The backup script (backup.scr) is in Listing 1. The
script
has two parameters. The first is the level of the backup
to be done
(0-9); the second is an optional tape device specification.
If the
tape device is not specified, the script uses the value
/dev/rmt0.1.
The checkparm function makes a lot of checks to allow
a variety
of specifications for the tape drive and to enforce
the non-rewind
requirement. If the device is an 8mm tape the set_blocksize
and reset_blocksize functions are used to ensure that
the
blocksize is set to 1024, the customer's preferred value.
The same
logic for checking the tape drive parameter, implementing
a default
tape device, and setting the blocksize appears in the
restore
scripts.
The site has a number of RS/6000 systems, each with
unique filesystems.
The script uses the lsfs (list filesystems) command
to construct
the list of filesystems to backup. Using the -v switch
on
lsfs makes it easy to exclude nfs and cdrom filesystems.
Certain jfs filesystems, such as /mnt and /blv,
should also be excluded. The complete ksh command to
create
the filesystem list is:
filesys=`lsfs -c -v jfs | tail +2 | \
grep -v -E "^/mnt:|^/blv:|^/tmp:"`
If you want to backup /tmp or exclude /usr,
just edit the -E switch on the grep command. The same
grep parameter can be changed to exclude other filesystems
from the backup.
Function make_header uses the variable filesys to
construct the header file and write it to tape. Function
doback
is then invoked once for each filesystem in the variable
filesys
to write the filesystem backup to tape.
Listing the Contents of a Backup Set
Listing backup sets from tape is a two-step operation.
First, the
header file is queried to determine the number of the
backup set from
which to list files. Second, a restore command is used
to
list the files in the selected backup set. The commands
to read the
header file from rmt0 (see Listing 2, gethdr.scr)
are:
tctl -f /dev/rmt0 rewind
tar -xf /dev/rmt0.1 /tmp/!backuplist
The file /tmp/!backuplist is interrogated to determine
the
sequence number for /home. In the list fileset command
which
follows, /home is assumed to be the fourth fileset:
tctl -f /dev/rmt0 rewind
tctl -f /dev/rmt0.1 fsf 1
restore -tqvf /dev/rmt0.1 -s4
The tctl command is used to rewind the tape and
skip over the header file. The -q parameter on the restore
command specifies that the tape is already positioned
at the start
of the backup sets. listfile.scr (Listing 3) implements
these
commands with appropriate parameter checking and error
handling.
Restoring All Files from a Fileset
The commands to restore all files for filesystem /home
(assuming
/home is the fourth fileset on the tape) are:
cd /home
tctl -f /dev/rmt0 rewind
tctl -f /dev/rmt0.1 fsf 1
restore -rqvf /dev/rmt0.1 -s4
Note that files are restored to the current directory.
This makes
it possible to restore to a temporary directory (e.g.,
/tmp)
and then move files to the correct location after inspection.
If multiple levels of the backup are used, for example,
level 0
on Saturday and level 1 on Monday through Friday, then
the
level 0 tape should be restored followed by the most
recent
level 1.
getfsys.scr (Listing 4) implements these commands with
appropriate
parameter checking and error handling.
Restoring One or More Files from a Fileset
The commands to restore the f1 and f2 files for user
billm in filesystem /home (assuming /home
is the fourth fileset on the tape) are:
cd /home
tctl -f /dev/rmt0 rewind
tctl -f /dev/rmt0.1 fsf 1
restore -qvf /dev/rmt0.1 -s4 \
-x "./billm/f1 ./billm/f2"
To restore all the files for user /billm, the
-x switch would be -x ./billm.
getfiles.scr (Listing 5) implements these commands with
appropriate
parameter checking and error handling.
Final Notes
backup and restore are specific to AIX, but other
UNIX systems implement commands that write a tape in
the same format
as the AIX backup command. The names and switch syntax
vary.
Sun (Berkeley) systems support the dump command and
system
V.4 has ufsbackup. For the sake of robust backups,
it would
be worth your while to become familiar with your system's
implementation.
About the Author
Bill Moraca is an IBM I/T Specialist on the AIX RS/6000
system.
He has helped many customers deal with RS/6000 system
administration
issues such as backup/restore, availability, and customized
interfaces.
You can contact Bill via email as wmoraca@wasvmic1.vnet.ibm.com.
|