Introduction |
To safeguard your files and directories, you can create a copy, or archive of the files and directories on a removable medium, such as a cartridge tape. You can use the archived copies to retrieve lost, deleted, or damaged files. |
Archiving Techniques |
You can use several commands to store, locate, and retrieve files on a tape device or from an archive file. Two of the commands you can use are:
|
The tar Command |
The tar command archives files to and extracts files from a single file called a tar file. The default device for a tar file is a magnetic tape device. The syntax for the tar command is: tar functions archivefile filenames
The table shows the functions associated with the tar command.
|
|||||||||||||||
Creating an Archive |
You can use the tar command to create an archive file that contains multiple files or directories. You can then place the file on a tape or a diskette so that other users can share the file or attach it to email messages. Creating an Archive on a TapeTo create an archive on a tape, first verify that the system has a tape drive available. You can use the mt utility with the status option to print status information about the tape unit. You use the mt utility to send commands to a magnetic tape drive.
The following example shows you how to use the default tape device to archive your home directory. In this example, user1 creates a tape archive of the user1 home directory. $ cd $ mt -f /dev/rmt/0 status <output will be your local tape device info> $ tar cvf /dev/rmt/0 . a ./ 0 tape blocks a ./.rhosts 1 tape blocks a ./dante 3 tape blocks a ./fruit 1 tape blocks a ./dante_1 1 tape blocks a ./dir1/ 0 tape blocks a ./dir1/coffees/ 0 tape blocks a ./dir1/coffees/beans/ 0 tape blocks a ./dir1/coffees/beans/beans 24 tape blocks ... (output truncated) You can also use the tar command to create an archive file containing multiple files or directories. The following example shows you how to archive the file1, file2, and file3 files in an archive file called files.tar. $ cd $ tar cvf files.tar file1 file2 file3 a file1 2K a file2 1K a file3 1K Creating an Archive on a DisketteBefore you can create a file archive on a diskette, insert a diskette into the appropriate drive on the system, and run the volcheck command. This command informs the Volume Management program to check for media in a drive.
The volcheck command checks for all removable media managed by the Volume Management program. The volcheck command checks for all diskettes as a default. It instructs the Volume Management program to check each device path name in sequence and determine if a new diskette is in the diskette drive. The syntax for the volcheck command is: volcheck -v device_pathname If you use the volcheck -v command without a device path name, one of the following messages appears: media was found or no media was found
Performing the volcheck command creates the /floppy directory and its content when a diskette is present. You can use the cd command to access files on the diskette in the /floppy/floppy0 directory. You can also use the cp command to copy an archive into the /floppy/floppy0 directory on the diskette. The following example shows you how to use the cp command to copy an archive file from your home directory to a diskette. $ volcheck -v /dev/diskette $ cd /floppy/floppy0 $ ls $ $ cd $ cp files.tar /floppy/floppy0 $ ls /floppy/floppy0 files.tar
To eject a diskette from the diskette drive do one of the following:
$ cd
$ eject floppy After a few seconds, the diskette ejects from the diskette drive, or a message appears to instruct you to manually eject the diskette. You cannot eject removable devices while you are in the current working directory for the device. If you see an error message, such as Device busy, when trying to eject the diskette, you might still be in the working directory on the diskette. Perform the pwd command to see if you are in the /floppy/floppy0 directory. If you are in the /floppy/floppy0 directory, enter the cd command to return to your home directory. Then perform the eject command. |
Viewing an Archive |
You can view the names of all the files that have been written directly to a tape archive or a file archive. Viewing an Archive From a TapeTo view the contents of the user1 home directory on a tape, perform the command: $ tar tf /dev/rmt/0 /.rhosts ./dante ./fruit ./dante_1 ./dir1/ ./dir1/coffees/ ./dir1/coffees/beans/ ./dir1/coffees/beans/beans ./dir1/coffees/nuts ./dir1/coffees/brands ./dir1/fruit/ ./dir1/trees/ <directory list truncated> Viewing Files in an Archive FileTo view the contents of the files.tar archive file, perform the command: $ tar tf files.tar file1 file2 file3 |
Retrieving tar Archive Data |
You can retrieve or extract the contents of an archive that was written directly to a tape device or to a file. Retrieving a Directory From a TapeIf the contents of your home directory are deleted, you can extract the directory contents from an archive tape. To retrieve all the files from the tape archive, perform the commands: $ cd $ tar xvf /dev/rmt/0 x ., 0 bytes, 0 tape blocks x ./.rhosts, 2 bytes, 1 tape blocks x ./dante, 1319 bytes, 3 tape blocks x ./fruit, 57 bytes, 1 tape blocks x ./dante_1, 368 bytes, 1 tape blocks x ./dir1, 0 bytes, 0 tape blocks x ./dir1/coffees, 0 bytes, 0 tape blocks x ./dir1/coffees/beans, 0 bytes, 0 tape blocks x ./dir1/coffees/beans/beans, 12288 bytes, 24 tape blocks x ./dir1/coffees/nuts, 0 bytes, 0 tape blocks x ./dir1/coffees/brands, 0 bytes, 0 tape blocks x ./dir1/fruit, 0 bytes, 0 tape blocks x ./dir1/trees, 0 bytes, 0 tape blocks ... (output truncated) You can extract files from an archive file using the tar command. The following example shows you how to extract files from the files.tar archive file for placement into the current directory. $ tar xvf files.tar tar: blocksize = 11 x file1, 1610 bytes, 4 tape blocks x file2, 105 bytes, 1 tape blocks x file3, 218 bytes, 1 tape blocks Retrieving Files From a DisketteTo retrieve files archived to a diskette, you can follow the same process as you did for archiving to a diskette except that you copy files from the diskette back to your home directory. The following example shows you how to retrieve the archived file files.tar from a diskette. $ volcheck $ cd /floppy/floppy0 $ ls files.tar $ cp files.tar /export/home/user1 $ cd $ ls files.tar files.tar $ tar xvf files.tar |