Using Other Copy and Backup Utilities

The tar, cpio, and pax commands can also be used to perform backups of files and file systems. Generally speaking, these three utilities are intended for smaller file systems and are not often used to back up entire servers. If you want to copy or move individual files or portions of file systems, these three commands, along with dd, provide an alternative to using ufsdump and ufsrestore.

Making File System Copies With dd

If you want to copy individual files or file systems, the dd command can be used to make a block-level, physical copy of a file system to another file system or tape device. The dd command copies standard input to standard output by default, but the standard input and standard output can be replaced by keyword pairs if desired. The following is an example of using dd with standard input and standard output, followed by keyword pairs. Both commands accomplish the same task, copying the contents of a floppy disk into a file in the temporary directory:

 # dd < /floppy/floppy0 > /tmp/file1 # dd if=/floppy/floppy0 of=/tmp/file1 

If you are going to use keyword pairs with dd, the syntax is keyword=value. This differs from most other Solaris commands. In the example, if means input file (input path), and of means output file (output path). You can also specify input block sizes with ibs=n (n is in bytes), output block sizes with obs=n, and block sizes for both input and output with bs=n. Larger block sizes increase copying efficiency. The default block size is 512 bytes.

The dd command can also convert data with different formats, such as differing record lengths or block sizes.

Using cpio

The cpio (copy in and out) command is used to copy data from one place to another. Typically, this means copying data from a hard disk to a tape backup, or restoring data from a backup onto a hard disk. The cpio command provides flexible syntax and acts as a filter program, taking data from standard input and delivering it to standard output. This command can back up and restore individual files, is more efficient than tar in terms of disk space, and is capable of spanning multiple tapes. The syntax for cpio is as follows:

 # cpio mode options 

There are three modes for cpio: copy in (-i) for restoring from tape, copy out (-o) for archiving to tape, and pass mode (-p), which is used to copy files from one location to another on a hard disk.

Table 9.5 lists some of the common options for cpio.

Table 9.5: cpio Command-Line Options

Option

Description

-A

Appends files to a cpio archive. Requires the -O option to work.

-B

Uses blocks of 5120 bytes instead of the default 512 bytes, increasing transfer speed.

-c

Reads or writes header information in ASCII character form for portability between UNIX-based operating systems.

-d

Creates directories as needed.

-E file

Specifies an input file that contains a list of filenames to be extracted from the archive. Filenames should be listed one per line in the input file.

-I file

Specifies the contents of the file as the input archive, instead of standard input.

-k

Attempts to skip corrupted file headers and I/O errors.

-m

Retains previous file modification time, instead of updating it.

-O file

Directs the output of cpio to a file, instead of standard output.

-P

Preserves Access Control Lists.

-t

Prints a table of contents of the input.

-u

Unconditionally copies, regardless of file modification dates. Normally, older files will not replace newer files with the same name.

-v

Verbose mode; prints a list of files and their extended attributes.

-@

Includes extended attributes in the archive.

The most common way to use cpio is to use file commands such as ls or find to locate files and then pipe the output to cpio for archiving. For example, if you wanted to copy all files and subdirectories from a user's home directory to tape backup, you could use the following command from the user's home directory:

 # ls -R | cpio -oc > /dev/rmt/0 

Warning 

Executing this command from the root directory (/) will cause cpio to attempt to back up your entire directory structure.

Or, you could find the entire list of files created by a user (adocter in this case) and back them up to tape:

 # find . -user adocter | cpio -o > /dev/rmt/o 

And, after copying files to the tape device, you will want to make sure that the files were copied properly:

 # cpio -civt < /dev/rmt/0 

To import files from a cpio archive, you could use the following:

 # cpio -icvd < /dev/rmt/0 

For most backup jobs that don't require you to back up the entire file system, you will generally find cpio to be the most flexible command to use.

Using tar and pax

The tar (tape archiver) command is primarily used to copy file systems from hard disk to tape, or from tape to hard disk. The tar command is popular because it's widely available across UNIX platforms. However, it's limited to a single tape or floppy disk. Here is the syntax for tar:

 # tar options tarfile file_list 

When using tar to make a backup, the file you are creating is called a tarfile. The file_list is the list of files you want to back up. Table 9.6 lists some common tar options.

Table 9.6: tar Command-Line Options

Option

Description

c

Creates a tarfile.

f

Uses the tarfile argument as the name of the tarfile. If omitted, tar will use the name of the device indicated in the TAPE environment variable, if set, or else it will use the default values listed in /etc/default/tar.

r

Replaces existing files in the tarfile. The files named in file_list are added to the end of the tarfile.

t

Table of contents. Lists the names of the files located within the tarfile.

u

Updates the files named in file_list.

v

Enables verbose mode.

x

Extracts files from the tarfile.

To create a new tarfile on tape, backing up all files in the /export/home/ldocter directory, you could use:

 # tar cvf /dev/rmt/0 /export/home/ldocter 

To show the table of contents in the archive you just created, you would use:

 # tar tvf /dev/rmt/0 

And to restore the tape archive, you could use:

 # tar xvf /dev/rmt/0 /export/home/ldocter 

Warning 

If you use absolute paths to create tar backups, the original files will be overwritten during a restoration, regardless of the directory you restore to. Accordingly, most administrators use relative pathnames when backing up using tar.

Copying files to a floppy disk is nearly identical to copying files to a tape drive. In the previous example, the tape drive device name was used as the name for the tarfile. For a floppy disk, using the tape device name doesn't make sense:

 # tar cvf /vol/dev/aliases/floppy0/floppy.bkp /export/home/ldocter 

Note 

Floppy disks containing tarfiles are not mountable.

Because tar is limited to a single tape or single floppy disk, it's not usually used to make backups to a floppy disk.

Like the tar command, pax is used to create archives on tape or floppy disk. The pax command has the same disadvantages as tar, in that it's not aware of system boundaries, does not support full pathnames longer than 255 characters, and does not copy empty directories or special files (such as device files). However, unlike tar, pax can be used to create volumes that span multiple tapes or disks.

pax has four operational modes: read (-r), write (-w), copy (-rw), and list (neither -r nor -w). The -a command line argument can be used to append an existing pax archive, -v displays information in verbose mode, and -f archive is used to specify the archive name.

The syntax to create a pax archive is as follows:

 # pax -w -f /dev/rmt/0 file_list 

The pax command can also read and write tar and cpio archives.




Solaris 9. Sun Certified System Administrator Study Guide
Solaris 9 Sun Certified System Administrator Study Guide
ISBN: 0782141811
EAN: 2147483647
Year: 2003
Pages: 194

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net