tar is widely considered the most portable of the backup and restore programs. You will find that many applications are shipped on tar tapes and many UNIX files downloaded from the Internet are in tar format. This is the most widely used format for exchanging data with other UNIX systems. tar is the oldest UNIX backup method and therefore runs on all UNIX systems. You can append files to the end of a tar tape, which you can't do with many other programs. When sending files to another UNIX user, I would strongly recommend tar. tar is as slow as molasses, so you won't want to use it for your full or incremental backups if you have a lot of data to back up. One highly desirable aspect of tar is that when you load files onto a tape with tar and then restore them onto another system, the original users and groups are retained. We'll use several tar commands in the upcoming examples, including the following: # tar cf /dev/rmt/0m /var ;use tar to create (c) an archive of the directory /var and put it on tape /dev/rmt/0m. # tar tvf /dev/rmt/0m ;obtain table of contents (t) from tape /dev/rmt/0m and produce produce verbose (v) output. # tar xvf /dev/rmt/0m ;extract (x) the entire contents of the archive on tape /dev/rmt/0m to default destination. # tar xvf /dev/rmt/0m file1 ;extract (x) only file1 from the archive on tape /dev/rmt/0m to default destination. You'll notice when you view the man pages for tar that options are preceded by a hyphen. The command works without the hyphen, so most tar examples, including those in this chapter, omit the hyphen. Let's take a look at some examples using tar. Let's begin by performing a tar backup (usually called creating an archive) of the directory /var to tape device /dev/rmt/0m. We use the c option to create a backup and the f option to specify the file of the tape drive /dev/rmt/0m: # tar cf /dev/rmt/0m /var tar: /var/opt/dce/rpc/local/01060/reaper is not a file. Not dumped tar: /var/opt/dce/rpc/local/00997/reaper is not a file. Not dumped tar: /var/opt/dce/rpc/local/00997/c-3/7000 is not a file. Not dumped tar: /var/opt/dce/rpc/local/00997/c-3/shared is not a file. Not dumped tar: /var/opt/dce/rpc/local/00997/c-3/7002 is not a file. Not dumped tar: /var/opt/dce/rpc/local/s-0/135 is not a file. Not dumped tar: /var/opt/dce/rpc/local/s-0/2121 is not a file. Not dumped tar: /var/opt/dce/rpc/local/s-3/135 is not a file. Not dumped tar: /var/opt/dce/rpc/local/s-3/2121 is not a file. Not dumped tar: /var/spool/sockets/pwgr/client933 is not a file. Not dumped tar: /var/spool/sockets/pwgr/client1028 is not a file. Not dumped tar: /var/spool/sockets/pwgr/client1152 is not a file. Not dumped tar: /var/spool/sockets/pwgr/client1172 is not a file. Not dumped tar: /var/spool/sockets/pwgr/client1173 is not a file. Not dumped tar: /var/spool/sockets/pwgr/client1139 is not a file. Not dumped tar: /var/spool/sockets/pwgr/client2500 is not a file. Not dumped tar: /var/spool/sockets/pwgr/client2592 is not a file. Not dumped tar: /var/spool/sockets/pwgr/client2490 is not a file. Not dumped tar: /var/spool/sockets/pwgr/client2593 is not a file. Not dumped tar: /var/spool/pwgr/daemon is not a file. Not dumped # The result of this command printed only problem-related messages to standard output. You will often see the v option used with tar to produce verbose output, which would have listed both the messages above and those related to files that were successfully written to the tape archive. Next let's take a look at only the files on the tape with the string eaaa in them. To produce a table of contents, we will use the t option. The following example also uses v for verbose output: # tar tvf /dev/rmt/0m | grep eaaa rw-rw-rw- 0/3 28 Jul 11 15:37 2000 /var/tmp/eaaa01299 rw-rw-rw- 0/3 28 Jul 11 15:37 2000 /var/tmp/eaaa01333 rw-rw-rw- 0/3 28 Jul 11 15:38 2000 /var/tmp/eaaa01354 rw-rw-rw- 0/3 28 Jul 11 15:40 2000 /var/tmp/eaaa01380 rw-rw-rw- 0/3 28 Jul 11 15:40 2000 /var/tmp/eaaa01405 rw-rw-rw- 0/3 28 Jul 11 15:45 2000 /var/tmp/eaaa01487 # This output shows several files that begin with eaaa on the tape. We'll delete the last of these files from the computer and restore it from tape using the x option to extract the file from the tar archive. We'll then list the direc-tory on the system to confirm that the file we deleted has been restored to the directory from tape. # rm /var/tmp/eaaa01487 # # tar xvf /dev/rmt/0m /var/tmp/eaaa01487 x /var/tmp/eaaa01487, 28 bytes, 1 tape blocks # # ls -l /var/tmp/eaaa* -rw-rw-rw- 1 root sys 28 Jul 11 15:37 /var/tmp/eaaa01299 -rw-rw-rw- 1 root sys 28 Jul 11 15:37 /var/tmp/eaaa01333 -rw-rw-rw- 1 root sys 28 Jul 11 15:38 /var/tmp/eaaa01354 -rw-rw-rw- 1 root sys 28 Jul 11 15:40 /var/tmp/eaaa01380 -rw-rw-rw- 1 root sys 28 Jul 11 15:40 /var/tmp/eaaa01405 -rw-rw-rw- 1 root sys 28 Jul 11 15:45 /var/tmp/eaaa01487 # This backup and restore using tar is simple and gets the job done. A common use for tar is to back up files from one directory and restore them to another directory. We'll backup the contents of /var/tmp and restore them to the directory /tmp/puttarfileshere. In the following example, we will create a tar backup archive to a file rather than to tape. The file is called tartest. We will then move this file to the destination directory and extract it there. We don't use a tape at all in this example. # cd /var/tmp # ls -l total 72 -rw------- 1 root sys 0 Jul 11 15:57 OBAMFEAa01630 -rw------- 1 root sys 0 Jul 11 15:20 OBAMHBAa01020 -rw------- 1 root sys 0 Jul 11 15:50 OBAMHBAa01540 -rw-rw-rw- 1 root sys 102 Jul 11 15:20 aaaa01112 -rw-rw-rw- 1 root sys 102 Jul 11 15:37 aaaa01299 -rw-rw-rw- 1 root sys 102 Jul 11 15:37 aaaa01333 -rw-rw-rw- 1 root sys 102 Jul 11 15:38 aaaa01354 -rw-rw-rw- 1 root sys 102 Jul 11 15:40 aaaa01380 -rw-rw-rw- 1 root sys 99 Jul 11 15:40 aaaa01405 . . . 1 root sys 28 Jul 11 15:37 eaaa01333 -rw-rw-rw- 1 root sys 28 Jul 11 15:38 eaaa01354 -rw-rw-rw- 1 root sys 28 Jul 11 15:40 eaaa01380 -rw-rw-rw- 1 root sys 28 Jul 11 15:40 eaaa01405 -rw-rw-rw- 1 root sys 28 Jul 11 15:45 eaaa01487 -rwxr--r-- 1 root root 28 Jul 11 16:04 envd.action2 -rwxr--r-- 1 root root 28 Jul 11 16:04 envd.action5 dr-xr-xr-x 2 bin bin 96 Jul 11 13:50 ntp -rw-r--r-- 1 root sys 600 Jul 11 15:27 swagent.log # # tar cvf /tmp/tartest 'ls' a OBAMFEAa01630 0 blocks a OBAMHBAa01020 0 blocks a OBAMHBAa01540 0 blocks a aaaa01112 1 blocks a aaaa01299 1 blocks a aaaa01333 1 blocks a aaaa01354 1 locks a aaaa01380 1 blocks a aaaa01405 1 blocks . . . a eaaa01354 1 blocks a eaaa01380 1 blocks a eaaa01405 1 blocks a eaaa01487 1 blocks a envd.action2 1 blocks a envd.action5 1 blocks a swagent.log 2 blocks # # cd /tmp # mkdir puttarfileshere # cp tartest puttarfileshere # cd puttarfileshere # ls -l total 80 -rw-rw-rw- 1 root sys 40960 Jul 11 17:09 tartest # # tar xvf tartest x OBAMFEAa01630, 0 bytes, 0 tape blocks x OBAMHBAa01020, 0 bytes, 0 tape blocks x OBAMHBAa01540, 0 bytes, 0 tape blocks x aaaa01112, 102 bytes, 1 tape blocks x aaaa01299, 102 bytes, 1 tape blocks x aaaa01333, 102 bytes, 1 tape blocks x aaaa01354, 102 bytes, 1 tape blocks x aaaa01380, 102 bytes, 1 tape blocks x aaaa01405, 99 bytes, 1 tape blocks . . . x daaa01405, 28 bytes, 1 tape blocks x daaa01487, 28 bytes, 1 tape blocks x eaaa01299, 28 bytes, 1 tape blocks x eaaa01333, 28 bytes, 1 tape blocks x eaaa01354, 28 bytes, 1 tape blocks x eaaa01380, 28 bytes, 1 tape blocks x eaaa01405, 28 bytes, 1 tape blocks x eaaa01487, 28 bytes, 1 tape blocks x envd.action2, 28 bytes, 1 tape blocks x envd.action5, 28 bytes, 1 tape blocks x swagent.log, 600 bytes, 2 tape blocks # When creating the tar backup, I first changed to the /var/tmp directory and then used the ls command (a grav or accent, which is near the upper left of most keyboards on the same key as a tilde, appears before and after the ls). This produced relative pathnames that I could easily restore to the /tmp/ puttarfileshere directory. Alternatively, I could also have just changed directory to /var and issued the command tar cf /dev/rmt/0m tmp to back up the entire contents of the /var/tmp directory. This entire process could have been done on a single command line. The following line is from the tar file man page and shows the procedure for producing an archive in the fromdir and restoring it to the todir: # cd fromdir ; tar cf-.|(cd todir ; tar xf -i ) The "-" in the tar cf command tells tar to send its data to standard output.The "-" in the tar xf command tells tar to look to standard input for data, which is the data produced by tar cf, issued earlier on the command line. cpio cpio is a powerful utility that is used in conjunction with find in order to perform full and incremental backups. cpio is an established UNIX utility that works similarly on most UNIX variants. We'll use several commands in the upcoming examples, including the following: # find . -print | cpio -oBv > /dev/rmt/0m ;find the contents of the current dir and write them to tape. # cpio -it < /dev/rmt/0m ;read table of contents (t) of tape. # cpio -icvBdum < /dev/rmt/0m ;restore (i) the contents of tape, this is the most widely used cpio command. # find . -print | cpio -oBv | (remsh tapesys dd of=/dev/rmt/0m) ;find the contents of the current dir and write (o) them to tape on remote machine tapesys. # remsh tapesys "dd if=/dev/rmt/0m bs=8k" | cpio -icvBdum ;restore the contents (i) of a tape on remote system tapesys to the local system. The first command we'll issue is to find the contents in /var/tmp and write them to our tape device /dev/rmt/0m. The options to cpio used in the following example are o for output mode, B for block output, and v for verbose reporting: # cd /var/tmp # find . -print | cpio -oBv > /dev/rmt/0m (Using tape drive with immediate report mode enabled (reel #1).) . envd.action2 envd.action5 swagent.log ntp OBAMHBAa01020 aaaa01558 aaaa01426 aaaa01112 OBAMHBAa01540 aaaa01299 . . . eaaa01487 OBAMFEAa01630 cmd_res8215 tmp_cfg_file cmd_res8708 exclude.temp arch.include.1 3570 blocks # In the example, we first changed the directory to /var/tmp, then issue the find command and pipe its output to cpio. cpio is almost always used in conjunction with find in the manner shown in the example. This produced a backup with relative pathnames because we changed to the directory /var/ tmp before issuing the backup commands. Next we'll view the contents of the tape to see the files we wrote to it with cpio. The i option is used for input, and the t option is used to get a table of contents in the following listing: # cpio -it < /dev/rmt/0m . envd.action2 envd.action5 swagent.log ntp OBAMHBAa01020 aaaa01558 aaaa01426 aaaa01112 OBAMHBAa01540 aaaa01299 . . . eaaa01487 OBAMFEAa01630 cmd_res8215 tmp_cfg_file cmd_res8708 exclude.temp arch.include.1 3570 blocks # Now that we have written to the tape and viewed its table of contents, we'll restore the contents of /var/tmp. In the following example we use several options to cpio, including i for input mode, c for ASCII header format, v for verbose, B for block output, d for directories, u for unconditional write over existing files, and m to restore the original modification times: # cpio -icvBdum < /dev/rmt/0m . envd.action2 envd.action5 swagent.log ntp OBAMHBAa01020 aaaa01558 aaaa01426 aaaa01112 OBAMHBAa01540 aaaa01299 . . . eaaa01487 OBAMFEAa01630 cmd_res8215 tmp_cfg_file cmd_res8708 exclude.temp arch.include.1 3570 blocks # The cpio command produces a list of files that will be read from the tape and restored to the system. Since we included the verbose option, we'll see all the information related to the restore. Now that we've seen how to write a tape, produce a table of contents, and read the contents of a tape on a local system, let's work with a tape drive on a remote system. We'll perform a backup to a remote tape drive, view the table of contents on the tape, and then restore using the remote tape drive. First let's perform a backup to a remote tape drive. The local system, which does not have a tape drive attached to it, is or1. The remote system, which has a tape drive attached to it, is tapesys. We'll run cpio (using the same three options earlier described) on or1 and run a remote shell and dd on tapesys, which will store the contents of the backup. We'll run these commands from /var/tmp on or1 in the following example: # find . -print | cpio -oBv | (remsh tapesys dd of=/dev/rmt/0m) . envd.action2 envd.action5 swagent.log ntp OBAMHBAa01020 aaaa01558 aaaa01426 aaaa01112 OBAMHBAa01540 aaaa01299 . . . eaaa01487 OBAMFEAa01630 cmd_res8215 tmp_cfg_file cmd_res8708 exclude.temp arch.include.1 3570 blocks # Now let's come back to our local system without the tape drive and restore the contents of the cpio tape we just produced, but let's restore them to a different directory. The directory to which we'll restore the contents of the tape (originally in /var/tmp) is /tmp/remotecpiofiles. This is similar to the process we performed in the tar section earlier in this chapter, in which we restored tar files to a different location. In the following example, we issue a series of commands while on or1. The last of these commands is to issue a remsh to system tapesys, which has on it a tape drive with the cpio tape we just created. We dd the information and pipe it through cpio to restore the contents of the tape. In this example, we use the same restore options to cpio, including i for input mode, c for ASCII header format, v for verbose, B for block output, d for directories, u for unconditional write over existing files, and m to restore original modification times: # hostname or1 # cd /tmp # mkdir remotecpiofiles # cd remotecpiofiles # pwd /tmp/remotecpiofiles # remsh tapesys "dd if=/dev/rmt/0m bs=8k" | cpio -icvBdum . envd.action2 envd.action5 swagent.log ntp OBAMHBAa01020 aaaa01558 aaaa01426 aaaa01112 OBAMHBAa01540 aaaa01299 . . . eaaa01487 OBAMFEAa01630 cmd_res8215 tmp_cfg_file cmd_res8708 exclude.temp arch.include.1 3570 blocks # # pwd /tmp/remotecpiofiles # ls envd.action2 envd.action5 swagent.log ntp OBAMHBAa01020 aaaa01558 aaaa01426 aaaa01112 OBAMHBAa01540 aaaa01299 . . . eaaa01487 OBAMFEAa01630 cmd_res8215 tmp_cfg_file cmd_res8708 exclude.temp arch.include.1 # The ls we issued at the end of this example confirmed that we did indeed write the contents of the tape on the remote system to the new directory /tmp/remotecpiofiles. You may want to add the -a command to the ls option to ensure that the files have contents. You can build from the simple examples in this cpio section to develop backup and restore commands to meet your needs in a modest environment. fbackup and frecover fbackup and frecover are the preferred backup and restore programs on HPUX. Backups produced with fbackup are not portable to other UNIX variants. If you're working in a heterogeneous environment, you won't be able to take fbackup tapes produced on an HP-UX system and recover them to a system running a different UNIX variant. In this section I'll cover issuing fbackup and frecover at the command line. You can also manage backups using these commands with SAM (covered in Chapter 3). SAM helps you manage both Automated Backups and Interactive Backup and Recovery. Although fbackup and frecover are the most advanced programs bundled with your HP-UX system for backup and restore, your needs may go beyond these programs. There are also advanced backup programs that you can procure from both HP and third parties. In general, I find that the capabilities of fbackup and frecover are sufficient for new HP-UX installations. If, however, you have a highly distributed environment, or need to back up large amounts of data, perform backups on systems with a variety of operating systems, or need to use several backup devices simultaneously, you may want to consider a more advanced product. fbackup has the capability of performing backups at different levels. The levels define the amount of information to be included in the backup. A full backup, which is covered in this section, is backup level 0. The other levels define various degrees of incremental backups. I am a strong advocate of performing a full backup, and then performing incremental backups of every file that has changed since the last full backup. This means that to recover from a completely "hosed" (a technical term meaning destroyed) system, you would need your full backup tape and only one incremental tape (you would restore your root volume with a bootable Ignite-UX tape produced with make_recovery,which is covered in Chapter 10). If, for instance, you performed a full backup on Sunday and incremental backups on Monday through Friday, you would need to load only Sunday's full backup tape and Friday's incremental backup tape to completely restore your system. fbackup supports this scheme. Keep in mind that although we'll be issuing fbackup and frecovery commands at the command line in this chapter, these can be managed more easily through SAM. The following is an explanation of the fbackup command and some of its options: /usr/sbin/fbackup -f device [-0-9] [-u] [-i path] [-e path] [-g graph] -f device | The tape drive for the backup, such as /dev/rmt/ 0m for your local tape drive. | [-0-9] | This is the level of the backup. If you run a full backup on Sunday at level 0, then you would run an incremental backup at level 1 the other days of the week. An incremental backup will back up all information changed since a backup was made at a lower level. You could back up at 0 on Sunday, 1 on Monday, 2 on Tuesday, and so on. However, to recover your system, you would need to load Sunday's tape, then Monday's tape, then Tuesday's tape, and so on, to fully recover. | [-u] | This updates the database of past backups so that it contains such information as the backup level, time of the beginning and end of the backup session, and the graph file (described below) used for the backup session. This is valid only with the -g (graph) option. | [-i path] | The specified path is to be included in the backup. This can be issued any number of times. | [-e path] | The specified path is to be excluded from the backup. This can also be specified any number of times. | [-g graph] | The graph file contains the list of files and directories to be included or excluded from the backup. | Although fbackup is quite thorough and easy to use, it does not have embedded in it the day and time at which full and incremental backups will be run. You have to make a cron entry to run fbackup automatically. SAM will make a cron entry for you, thereby running fbackup whenever you like. (cron is covered in Chapter 11.) In its simplest form, we could run fbackup and specify only the tape drive with the f option and the directory to backup with the i option as shown in the following example: # fbackup -f /dev/rmt/0m -i /var/tmp fbackup(1004): session begins on Wed Jul 12 14:26:30 2000 fbackup(3205): WARNING: unable to read a volume header fbackup(3024): writing volume 1 to the output file /dev/rmt/0m fbackup(3055): total file blocks read for backup: 3606 fbackup(3056): total blocks written to output file /dev/rmt/0m: 3857 fbackup(1030): warnings encountered during backup # fbackup did not produce a list of files included in the backup since we did not include the v option for verbose. To view the contents of the tape, we run frecover with the options r for read, N to prevent the contents of the tape from being restored to the system, and v for verbose, as shown in the following command: # frecover -rNv -f /dev/rmt/0m drwxr-xr-x root root / dr-xr-xr-x bin bin /var drwxrwxrwx bin bin /var/tmp -rw------- root sys /var/tmp/OBAMFEAa01630 -rw------- root sys /var/tmp/OBAMHBAa01020 -rw------- root sys /var/tmp/OBAMHBAa01540 -rw------- root sys /var/tmp/OBAMHBAa07762 -rw-rw-rw- root sys /var/tmp/aaaa01112 . . . -rw-rw-rw- root sys /var/tmp/eaaa01487 -rwxr--r-- root root /var/tmp/envd.action2 -rwxr--r-- root root /var/tmp/envd.action5 -rw-rw-rw- root sys /var/tmp/exclude.temp dr-xr-xr-x bin bin /var/tmp/ntp -rw-r--r-- root sys /var/tmp/swagent.log -rw-rw-rw- root sys /var/tmp/tmp_cfg_file # Let's now delete a file from the system that was included as part of the fbackup. We'll then restore only the file we deleted. We'll use the x option for extract and the i option to specify the file to include with frecover as shown in the following example: # cd /var/tmp # ls -l aa* -rw-rw-rw- 1 root sys 102 Jul 11 15:20 aaaa01112 -rw-rw-rw- 1 root sys 102 Jul 11 15:37 aaaa01299 -rw-rw-rw- 1 root sys 102 Jul 11 15:37 aaaa01333 -rw-rw-rw- 1 root sys 102 Jul 11 15:38 aaaa01354 -rw-rw-rw- 1 root sys 102 Jul 11 15:40 aaaa01380 -rw-rw-rw- 1 root sys 99 Jul 11 15:40 aaaa01405 -rw-rw-rw- 1 root sys 102 Jul 11 15:57 aaaa01426 -rw-rw-rw- 1 root sys 99 Jul 11 15:45 aaaa01487 -rw-rw-rw- 1 root sys 102 Jul 11 15:20 aaaa01558 # rm aaaa01487 # cd / # frecover -x -i /var/tmp/aaaa01487 -f /dev/rmt/0m # cd /var/tmp # ls -l aaa* # -rw-rw-rw- 1 root sys 102 Jul 11 15:20 aaaa01112 -rw-rw-rw- 1 root sys 102 Jul 11 15:37 aaaa01299 -rw-rw-rw- 1 root sys 102 Jul 11 15:37 aaaa01333 -rw-rw-rw- 1 root sys 102 Jul 11 15:38 aaaa01354 -rw-rw-rw- 1 root sys 102 Jul 11 15:40 aaaa01380 -rw-rw-rw- 1 root sys 99 Jul 11 15:40 aaaa01405 -rw-rw-rw- 1 root sys 102 Jul 11 15:57 aaaa01426 -rw-rw-rw- 1 root sys 99 Jul 11 15:45 aaaa01487 -rw-rw-rw- 1 root sys 102 Jul 11 15:20 aaaa01558 In the previous example, we successfully restored the file /var/tmp/ aaa01487 from the tape using frestore. There are some powerful aspects to fbackup that we did not employ in our example. These include backup levels, graph files, and index files. fbackup supports backup levels 0-9. 0 is used for full backups and the other digits indicate various incremental backup levels. Graph files are used to specify the files to be included in the backup. Index files contain a list of files produced as part of the backup. Let's take a look at an example that employs all of these functions. First, we create a graph file that contains the files we wish to include (i) or exclude (e) as part of the backup. In our case the file will contain only the following line: i /var/tmp Let's now run fbackup with u to update the backup database, 0 for a full backup, f to specify the file to which we want to write the backup (we'll use a file rather than tape in this example), g to specify our graph file, I to specify the name of the index file, and finally, we'll redirect messages to a file that will contain the backup log. We'll add the date and time to the end of the index and backup log files. # fbackup -0u -f /tmp/testbackup -g /tmp/backupgraph -I /tmp/backupindex.`date '+%y%m%d.%H:%M'` 2> /tmp/backuplog.`date '+%y%m%d.%H:%M'` # Let's now see what files were produced as a result of having issued this command. First let's look at the backup index and backup logfiles: # ls /tmp/backup* backupgraph backupgraph000712.15.04 backupindex.000712.15:04 backuplog.000712.15:04 # # cat /tmp/backupindex000712.15:04 1024 1 / 1024 1 /var 2048 1 /var/tmp 0 1/var/tmp/OBAMFEAa01630 0 1/var/tmp/OBAMHBAa01020 0 1/var/tmp/OBAMHBAa01540 336 1 /var/tmp/OBAMHBAa07762 102 1 /var/tmp/aaaa01112 . . . 28 1 /var/tmp/eaaa01487 28 1 /var/tmp/envd.action2 28 1 /var/tmp/envd.action5 4608 1 /var/tmp/exclude.temp 96 1 /var/tmp/ntp 1595 1 /var/tmp/swagent.log 205 1 /var/tmp/tmp_cfg_file # # cat /tmp/backupgraph000712.15:04 i/var/tmp # # cat /tmp/backuplog000712.15:04 fbackup(1004): session begins on Wed Jul 12 14:56:19 2000 fbackup(3024): writing volume 1 to the output file /tmp/testbackup fbackup(1030): warnings encountered during backup fbackup(3055): total file blocks read for backup: 3614 fbackup(3056): total blocks written to output file /tmp/testbackup:3876 # The three files with the date appended (7/12/00 time 15:04) to the end of the filename were produced by the fbackup command issued earlier. The date appended to the end of the file can help in the organization of backup files. We could restore any or all of these files with frestore from the file that contains the backup information (/tmp/testbackup), as demonstrated earlier. We are not restricted to performing backups to a tape drive attached to the local system. We can backup to a remote tape with fbackup by specifying the system name and tape drive, or file, to which we want to store the files. The following example uses fbackup options covered earlier and also includes the name of the system with the tape drive: # fbackup -f tapesys:/dev/rmt/0m -i /var/tmp -v fbackup(1004): session begins on Wed Jul 12 15:56:22 2000 fbackup(3307): volume 1 has been used -1 time(s) (maximum: 100) fbackup(3024): writing vol 1 to output file tapesys:/dev/rmt/0m 1: / 2 2: /var 2 3: /var/tmp 4 4: /var/tmp/AAAa11812 0 5: /var/tmp/AAAa11992 0 6: /var/tmp/BEQ19522 19 7: /var/tmp/DCE19522 0 8: /var/tmp/DEC19522 0 9: /var/tmp/ISPX19522 0 . . . 73: /var/tmp/eaaa13306 1 74: /var/tmp/ems_inittab.old 2 75: /var/tmp/envd.action2 1 76: /var/tmp/envd.action5 1 77: /var/tmp/inetd.conf.old 9 78: /var/tmp/net19522 1799 79: /var/tmp/swagent.log 16 fbackup(1005): run time: 43 seconds fbackup(3055): total file blocks read for backup: 1974 fbackup(3056): total blocks written to output file or1:/dev/rmt/0m: 0 # This command performs the backup of /var/tmp on system or1 by sending the files to the tape drive on system tapesys. We could have used many additional options to fbackup as demonstrated in earlier examples, but I wanted to keep the example simple so that it would be easy to see the remote tape drive specification. dd dd is a utility for writing the contents of a device, such as a disk, to tape. You can also use dd to copy an image of a tape to a file on your system, and then you can look at the file. First, let's write the contents of a directory to tape using tar, then we'll use dd to copy the tape contents as a file. The only option to dd required in this example is if, which specifies the input file as the tape drive. # cd /var/tmp # tar cf /dev/rmt/0m `ls` # cd /tmp # dd if=/dev/rmt/0m > /tmp/tapecontents 183+0 records in 183+0 records out # tar tv /tmp/tapecontents rw------- 0/3 0 Jul 11 15:57 2000 OBAMFEAa01630 rw------- 0/3 0 Jul 11 15:20 2000 OBAMHBAa01020 rw------- 0/3 0 Jul 11 15:50 2000 OBAMHBAa01540 rw------- 0/3 336 Jul 12 13:18 2000 OBAMHBAa07762 rw------- 0/3 0 Jul 12 13:44 2000 OBAMHBAa08333 rw-rw-rw- 0/3 102 Jul 11 15:20 2000 aaaa01112 . . . rw-rw-rw- 0/3 28 Jul 11 15:45 2000 eaaa01487 rwxr--r-- 0/0 28 Jul 11 21:53 2000 envd.action2 rwxr--r-- 0/0 28 Jul 11 21:53 2000 envd.action5 rw-rw-rw- 0/3 2304 Jul 12 12:42 2000 exclude.temp r-xr-xr-x 2/2 0 Jul 11 13:50 2000 ntp/ rw-r--r-- 0/3 1595 Jul 12 12:23 2000 swagent.log rw-rw-rw- 0/3 205 Jul 12 12:39 2000 tmp_cfg_file # Now we can look at the contents of the file with tar, as shown in an earlier section, with the following command: # tar tv /tmp/tapecontents Another common use of dd is to extract a cpio archive from a tape drive on a remote system to a local system. In the following example the local system without a tape drive is or1 and the remote system with a tape drive is tapesys. We'll read the tape to a directory on or1 using dd and cpio (see the earlier cpio section for an explanation of the options) in the following example: # hostname or1 # pwd /tmp/remotecpiofiles # remsh tapesys "dd if=/dev/rmt/0m bs=8k" | cpio -icvBdum . envd.action2 envd.action5 swagent.log ntp OBAMHBAa01020 aaaa01558 . . . eaaa01487 OBAMFEAa01630 cmd_res8215 tmp_cfg_file cmd_res8708 OBAMHBAa07762 exclude.temp arch.include.1 3580 blocks 0+358 records in 0+358 records out # This command runs a remote shell (remsh) to run the dd command on tapesys. The output of this command is piped to cpio on our local system to extract the archive. In this example, only the if option was used to specify the input file. The of option, which specifies the output file was not needed. If you were to perform a dd of a disk device to a tape drive, the of would be the tape drive on your system, such as /dev/rmt/0m. dump and restore dump is similar to fbackup. If you use fbackup on HP-UX, you will see much similarity when you use dump. dump provides levels as part of the backup scheme and creates /var/adm/dumpdates, which lists the last time a filesystem was backed up. restore is used to read information backed up with dump. dump, however, works only with HFS filesystems, and not with VxFS, and it assumes that you are using a reel tape. vxdump and vxrestore are used for VxFS. Generally speaking, you will not find dump (and vxdump) and restore (and vxrestore) recommended as backup and restore programs on HP-UX. fbackup and cpio are the preferred backup programs on HP-UX. There is, however, no reason why you can't use dump and restore as long as you keep in mind the filesystem type limitation. Let's take a look at some examples using dump and restore. Our examples will actually use vxdump and vxrestore; however. Nearly the same usage applies to both the HFS and VxFS programs. We'll use several commands in the upcoming examples, including the following: # vxdump 0fu /dev/rmt/0m /var ;dump vxfs file system /var to tape /dev/rmt/0m using level 0 and update /var/adm/dumpdates. # vxrestore tf /dev/rmt/0m | grep eaaa ;obtain table of contents from tape /dev/rmt/0m and look for file name containing "eaaa" # vxrestore -x -f /dev/rmt/0m ./tmp/eaaa01487 ;restore file to current directory Let's take a look at some of these commands in more detail and I'll provide more explanation for what is taking place. Our first example runs vxdump to back up the directory /var with a backup level of 0 for full backup, the f option to specify the output file /dev/ rmt/0m, and u for a write to /var/adm/dumpdates: # vxdump 0fu /dev/rmt/0m /var vxdump: Date of this level 0 dump: Tue Jul 11 16:41:27 2000 vxdump: Date of last level 0 dump: the epoch vxdump: Dumping /dev/vg00/rlvol10 to /dev/rmt/0m vxdump: mapping (Pass I) [regular files] vxdump: mapping (Pass II) [directories] vxdump: estimated 428058 blocks (209.01MB). vxdump: dumping (Pass III) [directories] vxdump: dumping (Pass IV) [regular files] vxdump: vxdump: 214146 tape blocks on 1 volumes(s) vxdump: level 0 dump on Tue Jul 11 16:41:27 2000 vxdump: Closing /dev/rmt/0m vxdump: vxdump is done # vxdump provides information related to the backup to standard output. Next, let's view the table of contents on the tape using vxrestore, looking for files that begin with eaaa. We'll then delete one of these files from the system and use vxrestore to restore it from tape. To produce the table of contents, we use the t option, and to extract the file from tape, we use the x option to vxrestore as shown in the following listing: # # vxrestore tf /dev/rmt/0m | grep eaaa 404 ./tmp/eaaa01299 678 ./tmp/eaaa01333 700 ./tmp/eaaa01354 736 ./tmp/eaaa01380 741 ./tmp/eaaa01405 717 ./tmp/eaaa01487 # # # rm /var/tmp/eaaa01487 # # vxrestore -x -f /dev/rmt/0m ./tmp/eaaa01487 You have not read any tapes yet. Unless you know which volume your file(s) are on you should start with the last volume and work towards the first. Specify next volume #: 1 set owner/mode for '.'? [yn] y # cd /var/tmp # ls -l eaaa01487 total 2 -rw-rw-rw- 1 root sys 28 Jul 11 15:45 eaaa01487 # Notice that as part of restoring the file, we had to specify a volume number of 1 and whether or not we wanted to set the mode for the file. The examples in this section showed creating a backup tape with vxdump, producing a table of contents, and restoring with vxrestore. Although fbackup and cpio are the recommended backup solutions on HPUX, you can use dump and restore if you are familiar with these programs and would like to use them. Due to the portability of tar, it is often used for backup and restore as well. |