AIX Backup/Restore

Relative vs Absolute Paths

When restoring files backed up with the backup, cpio, or tar commands, find out FIRST whether RELATIVE or ABSOLUTE pathnames were used BEFORE the restore is initiated. We recommend using RELATIVE.

  • Relative pathnames will have a ./ pre-fixed to their path.  These files will be restored relative to the current directory.
  • Absolute pathnames won’t have the ., just the /. These are restored with the full pathname to the exact directory as specified on the archive device.

backup

Command typically used to backup files on an AIX platform. Distribution tapes for AIX are in this format. This command will span across multiple tapes.

Backup by INODE is not recommended because it eliminates the capability to selectively restore files by filename.

If you have more data to backup than can fit on one tape, you will probably want to perform INCREMENTAL backups for files that have been modified within the last 24 hours for each day of the work week, followed by making a complete backup of the system on the weekend.

The error message Volume on /dev/rfd0 is not in backup format is generated when an attempt is made to extract a file NOT created by the backup command:

If your backup was successful, the last item logged by ‘backup’ is the time the backup finished and the number of 512 byte block that were archived.

Example message of a successful backup:

Backup finished on Sat Aug 1 15:22:34 CDT 1992; there are 8700 blocks on 1 volumes.
Options What it does
-i Read standard input
-v List names of files being backed up
-f Name of output device (typically de/v/rmt0 for tape drive)
-e Won’t attempt to compress or pack files that are greater than 24MB.
-q Won’t prompt user to insert tape
-p Pack data. Backup images by default are NOT packed. If you wish to pack your data, use this option. The restore command has enough intelligence to determine if a backup image is packed or not and take appropriate action
Examples What it does
find /u -print | backup -ivf/dev/rmt0 Backup the file system /u to tape device using ABSOLUTE pathnames.
find . -print | backup -iepqvf/dev/rmt0 | tee /tmp/BACKUP.LOG Backup files and directories under current directory (.) using RELATIVE pathnames. The tee (|) will take as input the output of the backup command (filenames being copied) and write them to the log file ‘BACKUP.LOG’ for later review.
find /faxdata -mtime -1 -type f -print | backup -ivf/dev/rmt0.1 Find any REGULAR files (-type f) that have been modified within the past 24 hours (-mtime -1) and write them to the tape device but don’t rewind (/dev/rmt*.1) the tape after backup has finished.
backup -ivqf/dev/fd0 Backup files interactively. Select the file(s) to backup by typing in the file’s name. When done, press ^D to finish.
find / -print|backup -icvqf/dev/rmt0-1 If there is more than one tape drive attached to the system, then you
can specify a range of devices to the -f flag of the backup command. (/dev/rmt0-1)

top of page


compress, uncompress, pack, unpack, zcat

Utilities to compress or expand data. The compress command reduces the size of the named file(s) and renames it with a .Z extension. Compressed files can be restored to their original form using the uncompress command. This utility appears to have a more EFFICENT packing scheme than the PACK/UNPACK commands.

Examples What it does
compress -v /tmp/junk File /tmp/junk is compressed and gets renamed to /tmp/junk.Z. -v displays the percentage of file shrinkage
uncompress /tmp/junk.Z Restores file to original file type and file size and changes the name to /tmp/junk.
1)find . -print | backup -ivqpf /tmp/roger.bck2) compress /tmp/roger.bck

3) find /tmp/roger.bck.Z -print | backup -ivqf/dev/fd0

The 3 commands will backup the current directory and compress that backup image to a floppy diskette.
1) restore -xvf/dev/fd02) uncompress < /tmp/roger.Z | restore -xvf- Restore the files archived from a floppy diskette. (In this example assume restored file=roger.Z)  Uncompress the compressed image and restore this file back to the file system
zcat /tmp/junk.Z > /tmp/junk1 Uncompresses /tmp/junk.Z into /tmp/junk1
find /u/COMPANY -print | xargs pack -f Packs all the files under the specified directory (/u/COMPANY)
find /u/COMPANY -print | xargs unpack Unpacks all the files under the specified directory (u/COMPANY)

top of page


cpio

Copies files to/from an archive storage device. This command is often used to copy files from UNIX to AIX systems. This command will span across multiple tapes. cpio stands for CoPy Input to Output.

Options What it does
-c Writes header information in ascii format for portability across UNIX systems. The message Out of phase–get help is generated when an attempt is made to extract a file not in cpio format OR if the archive tape was written with the -c option. The cpio command doesn’t have this option specified when attemping to extract files from the media (eg., cpio -icdumpv < /dev/rmt0)
-r When restoring will prompt for new path/file to restore to
-v List the file name as it’s being copied
-i Read from standard input, i.e. keyboard
-u Copies unconditionally. Older file replaces a newer one. Files with older modification times will replace files with newer modification times.
-d Creates directories,  if applicable
-t For table of contents
-C1 Performs block I/O in 512 byte blocks, if the block size of the device that wrote the data on the tape was set to 512 bytes. Make sure you read with the same block size. If the block size that the data was written to and about to be read from are two different sizes, this message will be displayed: Cannot read from the specified device
Examples What it does
1) cd /u/roger2) find . -print | cpio -ocv > /dev/fd0 Reads file names using the find command and copies to the floppy drive (/dev/fd0).
find . -cpio /dev/fd0 -print Saves files in current directory and writes this info to floppy.
Same command as above except much faster.
1) cd /u/roger2) cpio -icuvd < /dev/fd0 Restore files and directories saved on the floppy device. These files are restored under the current directory (/u/roger) Only if relative pathnames (./<filename>) were used.
cpio -itvcC1 < /dev/rmt0 List the table of contents from a tape device.
1) cd /u/roger2) find . -print | cpio -dumpv /u/jerry Copies all files FROM one directory TO another WITHOUT changing the permissions, owner/group or modification date of the file.
Use the following command to verify that all files were copied:
find /u/roger -print | wcfind /u/jerry -print | wc If the number of files encountered is the same for both directories its safe to assume that the directories are identical. NOTE: that the number of blocks allocated to the SOURCE directory (/u/roger) may be larger than the DESTINATION directory (/u/jerry), since compaction of the directory structure will have occurred at the destination end.
cpio -imv /home/roger/.profile < /dev/fd0 Selectively restore the /home/roger/.profile file from floppy
cpio -i “*.f” “*.c” </dev/fd0 Selectively restore only the *.f and *.c files from floppy

top of page


dd

Converts/copies files to/from an output device. DD stands for Data Dump.This command will NOT span across multiple tapes. Common utility found on most versions of UNIX.

Examples What it does
dd if=/dev/rmt0 bs=512k | cpio -icdmv Reads the files off the tape device faster because of the blocking factor (bs=blocksize of 512K or cache upto 1/2 MB at a time)
dd if=rs6000.data of=/dev/rmt0.4 bs=1024 conv=ebcdic Copies the data from the input file (if=rs6000.dat) to the output tape device (/dev/rmt0). The rmt*.4 device extension means output is written in 1600 bpi format. This creates an EBCDIC low density tape, resulting in a 1024 byte blocked non-labeled file. To extract this file on the AS/400, create a physical file with a record length of 1024 bytes. Use the CPYFRMTAP command to copy the file. NOTE: When copying data from an EBCDIC machine, make sure your BLOCK SIZE is set to 0 on the tape device
dd if=unixfile.txt of=DOSFILE.TXT conv=ucase Copies the data from the input file (if=unixfile.txt) to output name
(of=DOSFILE.TXT) and converts the source data to UPPERCASE characters.
tar -cvf- /u/roger | dd of=/dev/rmt0 bs=1024k Copies the ABSOLUTE path /u/roger using the tar utility. To speed this process up, these files are piped to the dd utility using a cache buffer size of 1MB.
dd if=/dev/rhdisk0 of=/dev/rhdisk1 bs=5120b Copies the raw physical volume named hdisk0 to the raw physical volume named hdisk1. This represents a copy disk utility.
dd if=/dev/rmt0 of=/tmp/ascii_file conv=swab Copies the data from the tape device (if=/dev/rmt0) and creates an output file (/tmp/ascii_file) – which is BYTE swapped (conv=swab) as it is being written out. This needs to be done if your copying ascii files from a System V Unix machine (unisys to the RS/6000)
dd if=/dev/rmt0.1 of=/tmp/data1 cbs=242 ibs=3240 conv=sync,unblock Useful when reading an ASCII file that is NOT delimited by a NL character.
dd if=/dev/rmt0.1 of=/tmp/data1 cbs=147 ibs=2940 conv=ascii Will read a record size of 147 bytes, a block size of 2940 bytes, and convert the output to an ASCII file.

top of page


mksysb

High-level shell command for backing up mounted file systems in the rootvg volume group. mkszfile -f must be called prior to mksysb in order to create the /.fs.size file that mksysb uses to determine which files will be backed up.

8MM TAPE DEVICE
An 8mm tape drive is the preferred method of backing up your system because that tape can be used to recreate the rootvg image if one or more physical volumes fail. Each of the file systems MUST have at least 500 blocks free when the mksysb backup is made. The system will need some work space in each file system when it is installing from a mksysb backup.

To utilize the full 2.3 gb tape capacity…

  • Set the blocksize to 1024
  • Edit the /usr/lpp/bosinst/diskette/startup2 file
    • Change the following line from 512 to 1024. 
      /etc/methods/chggen -a rmt0 -a block_size=1024
  • Create a new install/maint diskette

MKSYSB can create a BOOTABLE tape. Further, the data is archived in TAR format. In order to look at the names of files backed up by this command, perform the following:

  • tctl -f/dev/rmt1.1 fsf 3
  • tar -tvf/devrmt1.1

Example: mkszfile -f && mksysb /dev/rmt0

-f forces extending the /usr or /tmp file system if not enough working space (8 MB) exists. This command should ALWAYS succeed unless a tape has not been inserted into the archive device (eg., rmt0), or the tape is either write-protected or has defective media.

top of page


restore

Retrieve information from archive device created with the backup command. Default device is /dev/fd0. This command will read a backup image spread across multiple tapes.

Examples What it does
restore -Tvf/dev/rmt0 -T=table of contents, -v=list the file name being copied, -f=name of output device. Will list the tape’s table of contents. If you forget to label the tape with the date that the tape was made, use this command to report back the date this archive was created.
restore -xvf/dev/rmt0 ./usr/tmp/My* Restores all files that start with “My” from the /usr/tmp directory
restore -xdvf/dev/rmt0 ./usr/tmp Restores the directory named /usr/tmp from tape device
restore -xvf/dev/rmt0 Restores all the files located on the tape device that were backed up using the backup command.
restore -xvf/dev/rmt0 ./tmp/TestFile -x=extract data from output device. Restores only the file named ./tmp/TestFile from the tape device. If the subdirectory /tmp doesn’t exist in the current directory, then that subdirectory will be made prior to restoring ‘TestFile’.
1)
tctl
-f/dev/rmt0 rewind
2) restore -s1 -Tvf/dev/rmt0.13) restore -s1 -Tvf/dev/rmt0.1
1. Rewind to the beginning of tape. 2. Review files on FIRST backup
image. 3. Review files on SECOND backup image)Displays the table of contents for multiple backup images. s1=specifies that multiple backups are on the tape and that the restore command skips to the backup specified by the number associated with the ‘s’ option. The 0.1 for the output device (-f flag) means that once the tape has been read, it will not rewind. If only the second backup image was needed, could have just typed in: restore -s2 -Tvf/dev/rmt0.1
1) tctl -f/dev/rmt0.1 fsf 32) restore -xvqf/dev/rmt0.1 ./unix If by chance the ./unix file was deleted, go back to your install tape and extract the file that needs to be restored. The first three images on the tape are BOSBOOT, INSTALL/MAINT, followed by the TOC (table of contents) image.
restbyname -xvqf/dev/fd0 -Z /tmp/DISK.LIST Selectively restore ONLY those files listed in file /tmp/DISK.LIS

top of page


tapechk

Performs consistency checks on a tape device. Primarily used to check tapes written in backup format.

Example: tapechk 2 ( Checks the first 2 files found on the tape device.)
top of page


tar

Probably the easiest command to use when transferring files from one UNIX system to another. This command will NOT span across multiple tapes. Tar stands for Tape ARchiver.

When using this command while performing a SELECTIVE restore from a tape device (eg;., tar -xvf/dev/rmt0 ./etc/motd), the tar command will continue to run until the end of tape is encountered, even after the file has been found. The error message tar: directory checksum error (0 != 12345) Tar is an older utility than cpio or backup/restore is generated when an attempt is made to extract a file that is NOT in tar format.

Options What it does
-c Writes (creates) files (appends to archive device)
-x Extract (read) files from archive device
-v Verbose mode (displays names)
-f Device name to use
Examples What it does
tar -cvf- * | dd of=/dev/rmt0 bs=128k Copies all the files and subdirectories from the current directory and pipes the output to the dd command for faster archiving.
dd if=/dev/rmt0 bs=128k | tar -xvf- Use the dd command to read the tape device for faster archiving and pipe the output to the tar command to restore the archived files.
tar -tvf/dev/rmt0 List the table of contents of the tape device.
tar -cvf/dev/rmt0 /u/jones Copies the jones account to the archive device named /dev/rmt0.
tar -xvf/dev/rmt0 tmp/newdata /tmp/olddata Selectively copies ONLY the newdata and olddata directories from the tape to the current directory.
tar -cvf- * | xargs compress -v > /tmp/tar.Z Copies all the files from the current directory and compresses
them into the file named tar.Z.

top of page


tcopy

Copies from one magnetic tape device to another. This command will work for copying multiple backup images from one media type to another. It will continue to copy until two end-of-tape marks are encountered.

Examples What it does
tcopy /dev/rmt0 Displays ALL the backup images and their size for the tape your currently viewing.
tcopy /dev/rmt0 /dev/rmt1 Copies all the data from one media type to another until two end of tape marks are encountered. In the example above, rmt0 could be a 8mm device and rmt1 may be a 1/4″ tape device. If the error message: tcopy: Cannot open /dev/rmt?’ is displayed, make sure the destination device is not write-protected.

top of page


tctl

Command used to fast forward a tape device (Tape ConTroL).

Examples What it does
tctl -f/dev/rmt0 rewind Rewind the tape device.
tctl -f/dev/rmt0.1 fsf Move tape forward to the second tape mark. The .1 on the rmt0 device instructs the device NOT to rewind after performing the command. Use this command to skip past unwanted tape images – assumming there are multiple archive images on the tape to skip past.
tctl -f/dev/rmt0 retension Moves the tape to the beginning, end, and back to the beginning again. Used to retension the tape when encountering multiple read errors on restore operations.

top of page


Backup files from a remote computer

The local host MUST be included in remote’s hosts /etc/hosts.equiv file. The local host and user name MUST be included in the $HOME/.rhosts file at the user account at the remote machine.

Examples What it does
rsh lanai -l roger “dd if=/dev/rmt0” | tar -xvf- Restores files FROM a remote tape drive on a host named ‘lanai’
tar -cvf- * | rsh lanai -l roger “dd of=/dev/rmt0 bs=64k conv=block” The tar command will write it’s output to the rsh command which pipes the data to the remote host (lanai) and the tape drive (/dev/rmt0). Specify -l <UserName> if the local user is different from the remote user.
tar -cvf- * | rexec lanai ” dd of=/dev/fd0 bs=4096″ Uses the floppy drive device on node lanai to store files in tar format.

top of page