UNIX Unleashed, System Administrator's Edition
- 26 -
Backing up and Restoring Your System
by Chris Byers
In a perfect world, no one would ever lose data, disks would never fail, controllers would never go haywire, and every system would have the rm command aliased to ask you if you really want to delete all your data.
According to Murphy, there is no such thing as a perfect world. You will lose your data, your disks will fail, your controllers will go postal on you at some point, and you probably don't have any commands aliased, much less the rm command. The question really isn't if the worst will happen, it's when it will happen.
Fortunately, you have a way of protecting your data (and most likely your job). UNIX comes standard with a number of relatively flexible and rigorous archiving and tape backup systems that can fit into almost any hardware architecture. In addition to these standards, there are a number of proprietary commands for vendor specific operating systems and hardware that can provide a full system recovery solution.
In this chapter we will look at these backup solutions and how best to implement them, as well as the variations in solutions between UNIX variants that come standard with each operating system, as each one varies from the others in terms of implementation and backup strategy. These are the topics we'll be covering:
Finally, we will take a quick look at some third-party utilities for complete system (multiserver and workstation) backups and restores.
Using the tar command
One of the oldest and most often used commands for archiving and backing up files is the tar command. Because of its simplicity and ease of use, this is the most common format for tape and disk archives today, and probably for many years to come. This means that, for example, a tape from a Silicon Graphics workstation can be restored to a Hewlett Packard HP9000 server without any problems.
One of the best features of tar is the flexibility to save to any medium, since it treats file and tape (or other backup media) device targets the same.
You can also specify files and directories that you want to include or exclude. You can specify them on the command line, or you can specify a file containing a list of files to include or exclude.
The format of the tar command is:
tar (options) (tarfile name) (filenames to backup or restore)
Typically, the most common groups of options used are cvf for writing to a tarfile, xvf for extracting files and tvf for listing the contents of a tar archive.
As an example of writing to a tape archive, to archive all the directories in the /usr/local/datafiles directory to a typical 4mm tape drive on a Hewlett Packard machine, you would use the following command:
tar cvf /dev/rmt/0hc /usr/local/datafiles
Keep in mind that if you use the absolute path of the directory, you can only restore to that directory. A more flexible approach would be to get into the /usr/local directory and back up the directory, as follows:
cd /usr/local tar cvf /dev/rmt/0hc datafiles
This way, if you want to restore the datafiles subdirectory, archived in the last example, to a different location, you can first cd to the appropriate place and then restore. For example, if you want to restore the datafiles subdirectory to the /usr/contrib subdirectory, you would do the following:
cd /usr/contrib tar xvf /dev/rmt/0hc
If you are unsure what is on the tape, you can list the contents first. Since this can take just as long as restoring and the list of files usually scrolls off the screen, I usually redirect the output to a file, which I can then save as a record of backed up files:
tar tvf /dev/rmt/0hc > tarlist.txt
This is also a good way to get a printout of what is on a tape, since you can print off the tarlist.txt file directly. I try to keep this printout with the tape so I don't have to waste time when I need it.
If you know which specific files and subdirectories you want to restore, you can use an include file to only grab what you need. Let's say you copied the tarlist.txt file to a file called include, then edited out all the files except the ones you want to restore. The command would then look like this:
tar xvf /dev/rmt0 -I include
This will scroll through the tape and get just the files specified. You can also use an include file when archiving to tape and when looking for a list of specific files.
Using the dump command
The dump command essentially has the same functionality as the tar command, with the exception that it is somewhat more rigorous than tar. With dump, you can back up an entire file system or specified files and directories in a file system. In addition, you can specify a "dump level" (priority for saving files) to indicate the currency (last modification time) of the files to be backed up.
For example, if a level 2 dump is done on one day and a level 4 dump is done on the following day, only the files that have been modified or added since the level 2 dump will be backed up to the level 4 dump. The date and level of prior dumps are listed in the file /etc/dumpdates. Dump uses this file as a reference to decide which files to back up. If a dump command is not successful, it will not update this file.
Used in conjunction with the system scheduler (cron), this can be an effective solution for continuous system backups and archives.
In general, dump is used in the following format:
/usr/etc/dump [options [arguments]] filesystem
A typical example of this command would be:
/usr/etc/dump /dev/nrst0 /dev/sd0h
where /dev/nrst0 is the no-rewind tape device file and /dev/sd0h is the file system device file of the file system to be backed up. You must get the file system device filename from the output of df, cross-referenced with the appropriate directory. This example was taken from a Sun system.
In addition to dumping file systems, you can dump specific files. However, if you choose to do this, you can only back up files at level 0. As a matter of fact, the /etc/dumpdates file is never even used, even if you choose the -u option.
As an example, let's say we want to dump the files chapter1 and chapter2 to an 8mm tape drive. The command would look something like this:
dump fdsb /dev/rst0 5400 6000 126 chapter1 chapter2
Consult the man pages for more information on the options available for each particular tape drive.
One of the more popular generic backup utilities in use today is the cpio command. In large part, its popularity is due to its ability to append backup volumes and span tapes, allowing you to create incremental backup sets and full systems backups without losing data integrity.
Cpio allows you to copy files into and out of a cpio archive. If you use the -o option, it contains pathname and status information, as well as the contents of one or more archived files. Cpio stands for copy in/out.
The following is an example of using this command to back up the contents of a directory. The device file of the tape drive in this example is /dev/mt0:
ls | cpio -o > /dev/mt0
where the -o option copies out an archive.
Also, to read from a cpio archive on a tape drive, you can do something similar to the following example:
cpio -icdB < /dev/rmt0
where -i copies to an archive, c writes header information in ASCII character form, d creates directories as needed, and B blocks input to 512 bytes to the record.
You can also use the find command to see if a particular file is listed on your tape (or disk) archive:
find . -cpio /dev/rmt/0m
Once again, consult your man pages for a more complete explanation of all the options available.
Making Backups on HP-UX Systems
Although tar and cpio are versatile and generic tools for doing both system backups and simple file archives, they lack some features for convenience and ease of use, as well as logging and error recovery.
In the next few sections we will discuss the proprietary backup solutions that are available with some of the more popular UNIX variants.
Hewlett-Packard came out with their own version of a UNIX operating system based on Berkely's (BSD) UNIX OS code. Their systems are known as HP9000 systems; their servers are designated as S800 series machines; and their workstations are designated as S700 series machines. Also, they have various HP-UX operating system versions available, from the earliest release of HPUX 8.x to the latest release of HPUX 10.20 (at the time of writing).
On all HP9000 machines, the fbackup utility comes with the operating system as an effective system and file backup solution. fbackup combines the functionality of ftio (an extension of cpio) with the ease of use of the tar command, as well as a few extras.
fbackup gives you the option to include directories and files in your backup. On specifying a directory, all of the files and subdirectories in that directory are backed up. You can use the -i option with fbackup, or you can use a graph file, which I will cover later.
You can also exclude files from your backup set in a similar manner as the include files. Use the -e option to with the fbackup command to exclude files and/or directories and subdirectories.
Using graph files is a good way to get just what you want backed up or restored, without a ridiculously long command line. You can only have one entry per line in a graph file for files or directories, and they must be preceded by an i (for include) or an e (for exclude).
As an example, you can back up the /home directory and exclude the /home/joe directory with the following graph file:
i /home e /home/joe
fbackup uses the -g option to identify a graph file.
To use the fbackup command, follows these steps to ensure data integrity and stability:
The following is an example of an fbackup command:
fbackup -f /dev/rmt/0m -I /home
This will back up the entire contents of /home to the device file /dev/rmt/0m. The device file used in this example (/dev/rmt/0m) is commonly used for medium density 4mm DAT tapes used in DDS2 tape drives. To find the correct device file for your tape device, you might have to do some digging.
In order to restore from tape you must use the frecover command. Many of the options for fbackup are used in frecover as well.
To restore backup files from fbackup tapes using the frecover utility, you need to follow these steps:
If you wish to recover all files from a backup, you would use the -r option. By using the -x option, you can get individual files from tape. For all the options, check the man pages for frecover(1M).
If you are restoring files that are NFS mounted to your system, you may run into some problems. The frecover command can only restore files that have "other user" write permission. If you are going to do this, first log in as superuser on the NFS file server and use the root= option to the /usr/sbin/exportfs command (on 10.x systems) to export the permissions.
Following is an example of restoring files in the directory /home/joe from tape:
frecover -x -i /home/joe
This command will not overwrite newer files as long as the -o option is not specified.
If you want to restore files from all directories under /home/dave from a DAT tape to the /tmp directory, you would do the following:
cd /tmp frecover -x -oF -i /home/dave
So what happened here? The -F option removed the leading path names from all of the files on the tape that met the include criteria, causing them to be restored to the current directory without leading directories. All files were overwritten because of the -o option.
Again, all the options are explained in detail in the man pages for frecover.
Making Backups on AIX Systems
IBM's UNIX solution, AIX, comes with a very flexible and complete backup solution, known as the mksysb utility. With mksysb, you can backup up individual files, the root file system, or the entire system if this fits your need (and who wouldn't have that need!).
Specifically, AIX 3 only gives you the option of backing up the root volume group, But AIX 4 includes additional commands that give you the same functionality for other volume groups as well. By using mksysb as a system backup instead of a standard backup, you can get your system back much more quickly because you are skipping the step of first installing a system from scratch and then restoring data. This is a very effective solution for disaster recovery.
AIX 3.2 System Cloning
You can create clone images of the root volume group in two ways: either by using the command mkszfile && mksysb -f /dev/rmt0 (/dev/rmt0 being the backup device) or running smit mksysb. The mksysb image can be installed on different machines if need be. As a matter of fact, this is standard practice in disaster recovery testing.
Although you can restore to a different system, you may need to change other system configuration parameters to fit the new system, such as IP addresses. By configuring only the common settings for your systems, you avoid problems relating to machine specific issues, particularly IP addresses that could cause conflicts.
You can adapt the clone the first time it boots on the new machine through a simple script that can be executed only once on the first boot. The script is called /etc/firstboot, and it is executed by the cloned machine immediately after /etc/rc on bootup. This script will only be executed once if it exists, then it is renamed /etc/fb_hh_mm_MM_DD in accordance with the current date. The fbcheck entry in /etc/inittab handles this process.
When you clone an AIX 3.2 system, you also create a list of file systems to be created. The command that does this is the mkszfile command. This will create the /.fs.size file, which stores the sizes of the file systems for the clone. Typically, this file will follow a format similar to the following:
imageinstall rootvg 4 hd4 / 2 8 jfs rootvg 4 hd1 /home 31 84 jfs rootvg 4 hd3 /tmp 3 12 jfs rootvg 4 hd2 /usr 178 712 jfs rootvg 4 hd9var /var 3 12 jfs
Looking at the file you can see, from left to right, the volume group, the logical partition size, the name of the logical volume, the name of the file system, the size in physical partitions, the size in magabytes and the type of the file system (jfs stands for the journaled file system).
Restoring an AIX 3.2 System from mksysb
To completely restore an entire system from the tape, you need to have the tape in the primary tape drive (usually /dev/rmt0). You put the key in the service position (after you halt the system), double-click the reset button, and wait. The system reboots and displays a menu, giving you the option to restore from the mksysb tape, boot into a service kernel, or run system diagnostics. All you have to do is choose the restore option and go get some coffee for anywhere from 30 minutes to an hour (depending on the size of your rootvg).
A mksysb tape actually stores files in tar format. The image starts at the third file on the tape, so you have to position the tape at that file and restore using a non-rewinding tape device. This means you can get any file off a mksysb tape with a tar command.
For example, if you need to get the vi command back, just put the mksysb tape in the tape drive (in this case, /dev/rmt0) and do the following:
cd / # get to the root directory tctl -f /dev/rmt0 rewind # rewind the tape tctl -f /dev/rmt0.1 fsf 3 # move the tape to the third file, no rewind tar -xvf /dev/rmt0.1 ./usr/bin/vi # extract the vi binary, no rewind
You must cd to / first, since all files are stored relative to root.
AIX 4 System Cloning
In AIX 4 you can do more than just back up the root volume group. You can control file system sizes and placement through configuration files and different installation methods. Also, you can specify options as you need them.
Instead of creating the /.fs.size file, mkszfile in AIX 4 creates the /image.data file, which has much more sophistication than its predecessor. You can also give it more customization through the /bosinst.data file, which is automatically created by mksysb unless it has already been created manually. AIX comes with a default /bosinst.data file, located in /usr/lpp/bosinst/bosinst.template.
You can generate a system backup by using the following command:
mksysb -i /dev/rmt0
Using the -i option will cause mksysb to call the mkszfile command automatically. Specifying the -m will cause mkszfile to generate logical volume maps, which are included on the image. If you do this, you can also clone the exact location of the file systems on the new system. There is also a new option, -e, which will exclude the files from being backed up which can be defined in the file /etc/exclude.rootvg.
To contrast the two, the /bosinst.data file controls how a mksysb image is installed, and the /image.data file defines the characteristics of the root volume group and the file systems with- in it.
The following is a common bosints.data file:
control_flow: CONSOLE = INSTALL_METHOD = overwrite PROMPT = yes EXISTING_SYSTEM_OVERWRITE = yes INSTALL_X_IF_ADAPTER = yes RUN_STARTUP = yes ERROR_EXIT = CUSTOMIZATION_FILE = TCB = yes INSTALL_TYPE = full BUNDLES = target_disk_data: LOCATION = 00-00-0S-0,0 SIZE_MB = 1307 HDISKNAME = hdisk0 locale: BOSINST_LANG = en_US CULTURAL_CONVENTION = C MESSAGES = C
KEYBOARD = de_DE
These values can be changed as needed.
The CONSOLE value defines the console device. If you set the PROMPT value to no, you must set it, or the system will not know which device to use for the console. A couple of common examples are /dev/lft0 or /dev/tty0.
The INSTALL_METHOD value sets the installation method, most commonly set to overwrite, particularly for clone tapes. You can set the preserve and migrate options for updating systems, but you cannot use this for cloning.
The PROMPT value must be set to no for an automated install. Once you set it to no, however, you must define all the parameters needed for the other values.
The value for EXISTING_SYSTEM_OVERWRITE must be set to yes to automate the overwrite of systems that already are installed AIX systems.
If a system is cloned, INSTALL_X_IF_ADAPTER is not used. Otherwise, this value is used to specify the installation of AIXwindows, depending upon whether a graphics adapter is found on the system.
If you would like to start the install assistant after the first system boot, you should set the RUN_STARTUP value to yes.
The value for RM_INST_ROOTS should be set to yes to clean up the /usr/lpp/*/inst_roots directories once the system is installed. The only time you would set this value to no would be if you were going to run a server system for diskless machines.
The ERROR_EXIT value is used to define what you would like to run should the installation fail. Make sure that you specify a complete path and command name here, since you won't have any PATH variables set at the point where it fails.
The CUSTOMIZATION_FILE variable exists so that you can specify a file name to be executed as soon as the installation program has completed.
The TCB (Trusted Computing Base) variable has to be set to yes if you want the TCB to be active on your system. The TCB is a security measure ensuring that only the people that you want on your system can access only the programs you want them to access.
The INSTALL_TYPE variable will always be set to a full installation on a mksysb restore.
The BUNDLES variable is not used on mksysb tapes. This is only used for specifying which software bundles need to be installed initially from the medium.
The LOCATION variable is used to set the location code for the installation disk. If this variable is left undefined the program automatically finds a good installation disk without user intervention. As an example, the location of 00-00-0S-0,0 specifies the SCSI 0 disk with an integrated SCSI adapter.
The SIZE_MB value can be specified, but it is not necessary. Here you would specify a disk size in megabytes. To have the program automatically choose the largest disk, just use the keyword "largest" with no location code.
To specify the disk to restore to, you can use the HDISKNAME variable. An example of a common value to put in here is hdisk0.
The BOSINST_LANG variable lets you set the language that will be used during the installation of the system. Unless you speak a language other than English, you will always use en_US.
To specify the locale that is used for an installed system, you can set the CULTURAL_CONVENTION variable. On mksysb tapes, this will be left blank.
The system message language can be set with the MESSAGES variable. However, with a mksysb tape, this value is left blank.
And finally, the keyboard map you want installed can be set with the KEYBOARD variable. This should be left blank for mksysb tapes.
In the /image.data file, there are several lines that describe the root volume group and the logical volumes therein. There are some settings that can be changed to fit your needs.
In the logical_volume_policy, you can change the EXACT_FIT parameter to yes if you want the disk used to install the system to be exactly the same as the description in this file.
The SHRINK parameter defines whether or not the logical volumes should be shrunk to their minimal size at install time.
Next, the vg_data stanza defines parameters of the volume group. In here, you modify the PPSIZE parameter in order to set different default physical partition sizes. By default, this number is set to 4 MB.
Each logical volume will have one lv_data stanza. In here, all characteristics for logical volumes can be set. Should you want to define the disk location and maximum size parameters, you can do so here.
The final stanza in the /image.data file is the fs_data stanza. Each filesystem has an fs_data entry, which modifies the file system block size and activates compression for the file system.
As in AIX 3.2, AIX 4 also executes /etc/firstboot, if there is one, only on the first reboot after installation. The fbcheck entry in etc/inittab triggers this.
Restoring an AIX 4 System from mksysb
In AIX 4, to restore a system from a mksysb tape, you can do one of two things. As in AIX 3.2, you can simply boot from the mksysb tape, or you can use the restore command (instead of the tar command in 3.2).
If you use the restore command, you need to use the non-rewind tape device and specify the -s option. As with the tar format, mksysb in 3.2, you again need to start out in the third position on the tape. As an example of restoring the vi binary, you would do the following:
cd / tctl -f /dev/rmt0 rewind tctl -f /dev/rmt0.1 fsf 3 restore -xqf /dev/rmt0.1 -s 1 ./usr/bin/vi
For more detailed information on all of the options for restore, please consult the man page.
Backing Up Volume Groups with savevg on AIX 4
You can archive volume groups other than the root volume group by using the savevg command. As an example, if you want to back up the volume group homevg, you have a choice of either going through the smit savevg fastpath or the command
savevg -i -f/dev/rmt0 homevg
With the above command, the -I option also creates the file /tmp/vgdata/homevg/homevg.data, which is similar to the /image.data file that gets created with the mkszfile command. However, this file is actually created with the mkvgdata command, a softlink to the mkszfile command.
Other things in common with the mksysb command include the -m flag to create map file and the -e command to exclude whatever files are listed in the file (for this example, /etc/exclude.homevg).
Along with all the data for the volume group, the /tmp/vgdata/homevg/homevg.data and /tmp/vgdata/homevg/filesystems files are also backed up to tape for reference by the restvg command during volume group restoration. The /tmp/vgdata/homevg/filesystems file is simply a copy of the /etc/filesystems file.
Restoring Volume Groups with restvg on AIX 4
If you have a tape with archives created with the savevg command, you can restore from that tape with the restvg command. For example:
restvg -qf /dev/rmt0 -s
In this example, you would not only restore the homevg volume group on the physical volumes where it already resides, but the file system would also be shrunk to its minimum size.
You may not be able to easily restore a system with restvg to another machine unless the specific hard disks that the original volume group was on are available (not in use by another volume group) on the new system. If it is not available, then restvg will abort, unless you specify another set of hard disks that are available, with the following command:
restvg -qf /dev/rmt0 hdiskN
You can also restore individual files from a savevg tape using the standard restore command. For example:
cd / restore -xqf /dev/rmt0 ./home/joe/.profile
You can use the -T flag to list the contents of the tape. See the appropriate man pages for details.
If you want to make the homevg.data file manually, you can run the command mkvgdata homevg. You can then edit the characteristics of the volume group and its file systems simply by editing the homevg.data file. Some of the things you change in this file are the characteristics of the physical partition size or the block size and compression algorithm of the file systems in the volume group.
Using the backup and restore Commands
The backup and restore commands are actually the native AIX commands for doing backups. As a matter of fact, if you wish to save and restore your ACLs (Access Control List), this is the only backup command that will allow you to do so.
You can do two types of backups with these command. You can either back up your system by i-node or by file. If you choose to back them up by i-node, you are actually performing a file system dump, which is what mksysb in AIX 4 uses. Only the dump method has support for incremental backups, thus reducing the amount of time and tape used on system backups. This also has compatibility with the BSD dump command and the AIX rdump/rrestore commands.
By default, backup/restore will use the /dev/rd0 device.
If you use file mode, you won't be able to restore data to other UNIX variants aside from AIX. You would have to use another archiving command if this were the case.
A common way of using the backup command is in conjunction with the find command, where you run a find on the files you want to back up and pipe the output into the backup command. For example, if you would like to do a relative backup of the contents of the /home directory, along with its subdirectories, you would do the following:
cd / find ./home -print | backup -iqf /dev/rmt0
To restore the tape, use the following commands:
cd / restore -xqf /dev/rrmt0
If you would like to only get specific files from the tape, simply add the filenames to the end of the command line. If you would like to check the contents of a tape, simply use the -T option on the command line.
For incremental backups, the file /etc/dumpdates must exist. Use the touch command to create it if it doesn't. In order to do a full backup of the home filesystem, you would do the following:
backup -0uf /dev/rmt0.4 /home
What this does is create a level 0 (full) dump on the tape. This also places an entry in the /etc/dumpdates file as follows:
/dev/rhd1 0 Wed Apr 16 16:02:23 1997
You could also use the device name from the output of df instead of the filesystem name.
To restore an incremental backup to this tape, you would use the following command:
backup -1uf /dev/rmt0.4 /home
And into the /etc/dumpdates file goes another line under the first:
/dev/rhd1 1 Wed April 16 16:42:42 1997
Should your filesystem get crushed and you need to restore from this tape, first create a new /home filesystem, make this your current directory, and restore the data from the tapes.
The first tape must be the level 0 tape. The command to restore it would be:
restore -qrf /dev/rm0
Now you would insert the level 1 dump tape and use the same command to update the files to the most current setting. Should you wish to only restore individual files, first go the directory where you want to restore the file, and run the command:
restore -qxf /dev/rmt0x4 ./home/joe/.profile
to restore your personal profile.
The rdump and rrestore commands are simply remote versions of the backup utility in AIX. In other words, you can back up your system to a remote tape drive over the network.
In order to use this utility, you need to have a proper /.rhosts file on the target machine. This may not be possible should you have a high degree of security on your network.
Also, if you have not already done so, you will have to create at least one compatibility link if you are using AIX 4. You have to link the /usr/sbin/mnt directory with the /etc directory. To do this, you would use the following command:
ln -s /usr/sbin/mnt /etc
You also must have a /etc/dumpdates file available as well, just like with restore/backup.
An example of backing up the /home filesystem is as follows:
rdump -0uf fileserver:/dev/rmt0.4 /home
On certain tape drives, rdump needs certain extra parameters. For example, if you are using an 8mm 2.3 GB drive, you would have to use the parameters -d6250 -s33000. If you were to use a 5 GB tape drive in its compressed mode then you would have to use the value of 80000 for the -s parameter. Consult your AIX manuals for the specifications for your model of tape drive.
To restore from an rdump tape, you would use commands similar to the local restore command, such as in the following example:
rrestore -rf fileserver:/dev/rm0
pax is a neat little utility that handles both the tar and cpio formats. It defaults to tar format, but it also incorporated the error recovery features of cpio. As a matter of fact, when a mksysb tape runs across bad spots on a tape, it automatically calls the pax utility to try and recover from the error condition.
The following format is used with pax:
pax -wf (tape device) (filesystem)
To archive the /home filesystem to tape, you would do the following:
pax -wf /dev/rmt0 /home
To restore the filesystem, you would use the following command:
pax -r -pe -f /dev/rmt0
The -pe option in this restore command is used to preserve both the modification time and the ownership of the files. Also, you don't have to use relative pathnames, because they can be changed when you restore the files. For example, if you wand to restore the files from /home to /tmp/test, you would use this command:
pax -rpe -f /dev/rmt0 -s:^/home:/temp/test:g
The command to list the contents of the tape is:
pax -f /dev/rmt0
If you want to write out a tape to either cpio or tar format, you can make it do so explicitly by using the -x option, along with specifying either cpio or tar.
Making Backups on Sun Solaris systems
The default system backup utility for Sun Solaris systems is the ufsdump/ufsrestore utility. As you might expect, this utility is based on the dump/restore utility and carries with it much of its attributes.
To most effectively illustrate the use of ufsdump/ufsrestore, I will outline the steps involved in backing up a Sun workstation, along with an example system backup and restore.
First off, you need to log everyone out of the system and bring it down to the single-user mode state. The following steps should walk you through a full system backup (level 0 backup):
The following is a sample of possible screen output for the ufsdump command:
# init s # ufsdump 0cuf /dev/rmt/0 c0t0d0s7 DUMP: Date of this level 0 dump: Wed Mar 11 10:16:53 1992 DUMP: Date of the last level 0 dump: the epoch DUMP: Dumping /dev/rdsk/c0t3d0s7 (/export/home) to /dev/rmt/0 DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 956 blocks (478KB) DUMP: Writing 63 Kilobyte records DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: level 0 dump on Wed Mar 11 10:16:53 1992 DUMP: 956 blocks (478KB) on 1 volume DUMP: DUMP IS DONE #
Doing Incremental Backups
As with dump, you can specify different backup levels with ufsdump in order to back up only those files that were changed since a previous backup at a lower level.
In order to backup just the incremental changes on the system made since the last complete dump, you would follow the following steps:
Getting It Back with ufsrestore
The other side to the coin for ufsdump is ufsrestore, just as restore is the flip side of dump. ufsrestore copies files from backups created using the ufsdump command into the current working directory. You can use ufsrestore in one of two ways: you can use it to reload an entire file system hierarchy from a level 0 dump followed by any incremental dumps that follow it, or you can restore just one or more single files from any dump tape.
During restore, all files are restored with their original owner, last modification time, and mode.
This sounds easy enough, but before you begin restoring you need to know a few things:
After you've found the right tape or tapes to restore (you do have backup plans, don't you?), you can start restoring your system. Follow these guidelines and you should be okay:
If you want to get back only certain files, you will need to use the interactive options in ufsrestore. A good idea to practice when restoring interactively is to restore files into the /var/tmp directory. This way you stand less chance of overwriting files with older versions.
To do it interactively, you would do the following:
Making Backups on SVR4 Systems
By their nature, SVR4 systems are considered "raw" systems. By this, I mean that almost all UNIX systems are derived from one of two base, or raw, UNIX OS's: BSD or SVR4 (System 5 release 4).
As a raw system, SVR4 really doesn't have much to offer in the way of enhanced system backup and recovery utilities.
Just as most UNIX variants were derived from BSD and SVR4, so were most backup utilities derived from dump/restore and cpio/tar.
By default, BSD systems usually go to the cpio or tar utilities to handle their system backups. For more detail on these utilities, see the previous sections on cpio and tar.
Making Backups on Silicon Graphics IRIX Systems
In addition to the standard tar and cpio backup utilities, IRIX also comes with the BRU utility for system backup and recovery.
The BRU utility gives you the functionality to do a number of things, such as backing up the system, restoring the system, verifying a backup, estimating a backup, defining a tape drive, disk file, or floppy to back up to or restore from, and which filesystems or selection of files you wish to back up or restore.
To utilize this functionality, you would use one or more of the following options:
The command line for BRU is defined as follows:
bru -(mode) -options) -f(device) (path)
With all these basic modes and options, all of the basic backup and restore functions can be performed. As an example, if you wish to restore the contents of the entire system to a tape drive on an SGI box, you might use the following command:
bru -cvf /dev/rmt/tps0d6ns.8200
To look at what's on a tape, you might use this command:
bru -tvf /dev/rmt/tps0d6ns.8200
This will give you a complete listing of the contents of the tape. You could also redirect the output (>) to a file so that you can have a list of the tape contents for your records.
In order to restore the contents of the entire backup volume, you would use the following command:
bru -xvf /dev/rmt/tps0d6ns.8200
By default, this command restores all of the files to their original location (absolute paths).
If you wand to verify the contents of a BRU backup volume, you can do it one of two ways: the -i mode and -d mode. The first method is actually a preferable method because the mechanism requires only the tape drive and the BRU utility to run. The inspect mode (-i) gives you this functionality:
bru -ivf /dev/rmt/tps0d6ns.8200
What happens here is that this verification method rereads each buffer block written on the backup volume and recalculates the 32 bit CRC. The BRU utility then compares this calculated CRC with the CRC that was written in the buffer block header. If it gets an incorrect value, it warns you of the offending condition.
In reality, the other mechanism, the -d mode, is most commonly used. It requires both the backup volume and the original data. For example:
bru -dvf /dev/rmt/tps0d6ns.8200
If you use this mechanism, it reads the data from the tape and performs a bit-by-bit comparison with the original data from the file system. This method reports problems if the files have changed on the file system since the backup was made.
There are a number of options that are available to the BRU utility that go above and beyond the standard options that are available with its sister application, tar.
The following BRU utilities provide enhanced processing capabilities:
As an example, to add the description "Complete System Backup", you would do the following:
bru -cv -L "Complete System Backup" -f /dev/rmt/tps0d6sn.8200
If we look at the backup volume with bru -g we would see the following:
bru -gf /dev/rmt/tps0d6sn.8200
All this information is added when we use the -cv and -L options when backing up a tape. The most important elements are the label, creation date, volume, and command line.
You could also use bru for performing either Incremental or Differential backups. This can be done in conjunction with bru's -n option, because the -n option passes a standard date string. The best method is to create a reference file and pass the name of that file to bru, such as "/etc/LASTFULL".
The following script would perform full backups on Saturday morning and Differential backups on all other days:
#!/bin/sh DOW=`date +%w` if [ $DOW = 6 ] then bru -cvf /dev/rmt/tps0d6sn.8200 -L "Complete Backup 'date'" / touch /etc/LASTFULL else bru -cvf /dev/rmt/tps0d6sn.8200 -L "Daily Update 'date'" -n /etc/LAST fi
This script, if called by cron once a day, makes a full backup of your system on Saturday, followed by differential backups once a day.
Making Backups on BSD Systems
By their nature, BSD system are considered "raw" systems. By this, I mean that almost all UNIX systems are derived from one of two base, or raw, UNIX OS's: BSD or SVR4 (System 5 release 4).
As a raw system, BSD (just like SVR4) really doesn't have much to offer in the way of enhanced system backup and recovery utilities.
Again, just as most UNIX variants were derived from BSD and SVR4, so were the backup utilities derived from dump/restore and cpio/tar.
By default, BSD systems usually go to the dump/restore utilities to handle their system backups. For more detail on these utilities, see the previous sections on dump/restore.
Making Backups on Linux Systems
Although tar is distributed on all UNIX variants, LINUX comes with a somewhat more advanced version of tar. The LINUX tar command gives you the added feature of compression through the GNU gzip utility, as well as the compress utility.
These new switches are:
If, for example, you want to create a compressed backup of your /etc directory and put it into a file called etc_backup.tar, you would do the following:
tar czf etc_backup.tar /etc
This backs up all the subdirectories under /etc as well.
In order to add the contents of another directory, such as /usr/local/etc, you would do the following:
tar rzf etc_backup.tar /usr/ocal/etc
With the u option, you can make tar go through and append to the archive only those files that have been changed since the creation of the archive. The following command will let you do this:
tar uzf etc_backup.tar /etc/usr/local/etc
These examples so far have only shown you how to archive files to disk. In order to back up the archives to tape, you would simply add the device name to the command, instead of the directory name. Usually the tape drive device name is /dev/st0 for SCSI tape drives.
Restoring Files on LINUX
The x option enables you to extract files from archives. If you don't specify a filename to restore, tar restores the entire archive. Using the t option, you can get a table of contents for the archive.
To extract the contents of the backup archive in the previous example you would do the following:
tar xzf etc_backup.tar
Note that these files were compressed on backup and they must be restored using the z option.
Also notice that tar will not put the files back where they came from. It actually creates a new tree based on the current directory. Therefore, you must get to the original directory where you were when you backed up the tape in order to be able to restore to the same location.
In certain situations, you may want to consider restoring to a temporary directory first before moving files in place, because you may accidentally restore older files over existing files. Of course, if you do this, you need to check the space available to you in the directory to which you are restoring.
If you want to restore to individual files from an archive, all you have to do is specify the name after all the tar arguments. As an example, let's say you just want to get back your hosts and passwd files. You would do the following:
tar xzf etc_backup.tar etc/hosts etc/passwd
You should notice that the full pathname must be specified if you are going to do this.
Typically, these tared files are named (filename).tar.gz, so that you can tell they are tar archives, compressed with the GNU gzip utility.
Along with the z option, LINUX's version of tar also comes with some other neat little utilities. A few of the more notable ones are:
Getting Multiple Archives on a Tape with tar
After tar has written a backup to tape, it writes two EOF marks on the tape. You can move the tape to these marks by using the mt (move tape) command as follows:
mt -f /dev/nftape fsf 1
In this example, the tape device /dev/nftape is a non-rewinding device. You must use a non-rewinding tape device, or else once you have moved the tape in position, it will just rewind back to the beginning.
Now that you have the tape in the correct position, you can back up or restore the next archive on the tape.
taper is a neat little utility that gives you most of the same utilities as tar, but it also has a nice warm and fuzzy user interface.
You can get taper for Linux at any GNU ftp site on the Internet. In order to run taper, you need to have the most recent version of ncurses that supports "forms". The primary GNU ftp site is located at prep.ai.mit.edu.
taper is relatively easy to configure, build, and install for Linux. The installation instructions are included in the INSTALL file.
To build and install the latest ncurses, you should do the following as root:
cd /usr/local/sr tar xzf ncurses-(release #).tar.gz cd ncurses-(release #) ./configure -with-normal -with-shared \ --with--debug -disable-termcap make make install
In order to make a binary of taper, you need to do the following:
tar xzf taper-(release #).tar.gz
Next, you must edit the Makefile in order to get the proper tape drive specified for your site. Then you would type:
make clean make all make install
When you initially create an archive, the taper program stores all the information about files on that archive, such as filename, file size, backup time, and so on. This information gets stored into a file called an archive information file, which is usually stored in a file, usually called ~/.taper_info. When reading from an archived tape, taper reads this file, thus avoiding having to go through the entire tape to find the location of a particular file.
The biggest problem with this file is that you can't restore a tape to another machine until this file is loaded on to it. Therefore, you must save that file on a separate tape or floppy so that it can be loaded first. You must also ensure that you always have a current version of this file saved.
Each archive that gets created is given a unique archive ID, which can be used for future accessing of the archive if you don't have the tape at hand.
Making a Backup with taper
To start the taper utility, simply type the command taper on the command line. This brings up the main taper window. There are three main modules in taper: backup, restore, and mkinfo. These as well as the preference management options are presented here.
Select the backup option to back up a tape.
If the archive doesn't yet exist, you will be prompted for the archive title. Then it will prompt you for the volume title.
After that is squared away, you get a screen with three panels. The top left should show you the current directory on the hard disk, the top right shows what's currently on the archive, and the bottom panel shows you which files have been selected for backup. At the top of the screen is the archive ID and title.
In order to move around between the panels, just use the tab key. If you need to get help on keys, just press h.
At this point you must choose which files and directories you want to back up. You can use the cursor keys to move you around the directory. If you press enter when a particular directory is highlighted, you will move into that directory.
When you have found the file or directory you wish to back up, you can press the s key to select it. The size of the file or directory will then be shown in the bottom window.
Next, you will be asked whether or not to backup in incremental mode or full backup mode, as shown in the left hand box, which displays an I or an F. To toggle between the two, press s when the highlight is on the selected file or directory.
Note that when you select a directory, all subdirectories under it will automatically be recursively included in the backup list.
In order to deselect a file, just move the cursor to the bottom window with the tab and move the highlight to the file or directory you want to deselect. Then, just press d to deselect the file or directory.
Once you have finished selecting files and directories, press f. taper will now start the backup. If at any time you want to stop the backup, just press q.
Restoring Files with taper
Restoring from taper is just as easy (if not easier) than backing up. First, select the restore option from the taper main menu. You are then presented with a list of all the archives taper is aware of. These are sorted by archive ID order, and the archive title is displayed as well.
Move the highlight to the desired archive and press Enter. Now you are given three panels. The top left gives the files and directories currently on the archive, the top right gives you a summary of the whole archive, and the bottom panel will show the directories and files selected for restoring.
Once again, use the cursor keys to move the highlight to select which files you want to restore, and press s to select the files or directories you want to restore. Don't forget that subdirectories are recursively restored. Once you choose a file or directory it shows up in the bottom panel. If you have chosen a file or directory twice, square brackets will show up around the file or directory name.
Over in the select window, the volume number is printed after the filename. One of two things will show up here: either a volume number or an m. If an m appears, then taper is operating in "most recent restore" mode and you will only be able to restore the most recent copy of that file. You can toggle between modes by pressing the S key while in the select window.
If you wish to deselect a file or directory, just hit the d key while the appropriate one is highlighted.
Once you have chosen everything you want to restore, press f to start the taper restore. Once again, just press q if you wish to quit during the restore.
Should the archive information file get deleted or corrupted, you can create another one simply by using the mkinfo command. Just put the tape in the drive and select mkinfo from the main menu in taper.
On top of the standard UNIX backups that come bundled with the install packages, there are a number of commercially available packages out there.
The following are some of the more popular products used at many sites for complete network and system backups:
Each of the backup solutions is unique. You might have to do some serious homework to find out which one is best for your system, as there really isn't any one best total storage solution. You just have to find the best one for your system.
This may not be easy. There is a joke that goes (somewhat politically incorrectly): "the two greatest liars in the world are software vendors and teenage boys." So, just be on your guard when you go shopping.
In this chapter we have covered a large number of backup and restore topics. These were: using the tar command, using the dump command, using cpio, and making backups on HP-UX systems, Solaris Systems, SVR4 systems, IRIX systems, BSD systems and Linux systems.
Speaking from experience, there really is no substitute for good, up-to-date backups for saving your bacon. I can remember at least two times in my career that, had I not had the system backed up, I'd be out on the street.
So, a word to the wise. Remember the three best secrets to a good career in systems administration: backup, backup, and backup!