Using Backup and Restore Commands

The commands you use depend in part on how you re backing up your data. Generic backups commonly use the tar or cpio commands. Alternatively, you might dump and restore data to and from a tape drive. Backups to local CDs are associated with the mkisofs , cdrecord , and dvdrecord commands. Some variations are required to back up and restore data through the network to remote locations.

Generic Backup Commands

Let s look at the two generic Linux commands for backing up a group of files. The tar command was originally developed to archive files and directories to tape drives ; the cpio command also copies files and directories to and from an archive. With the right options, these commands can be used to back up files to most media.

Note  

You can also use the dd command to dump the contents of a directory directly to a device ”for example, a floppy drive device such as /dev/fd0 or a tape drive device such as /dev/st0 . For more information on dd , see Chapter 03 .

Archiving by tar

You examined the tar command for the first time in Chapter 10 . It s simple to use. The format is easily compressed and downloadable. This command is the main alternative to the RPM system for packaging programs and applications. With the right options, it s functionally similar to the .zip file system associated with Microsoft Windows.

The tar command is designed to copy a series of files into a single large file. If you want to back up the files in mj s home directory, you might run the following command:

 # tar cvzf mjbackup.tar.gz /home/mj 

This command creates ( c ) a backup, listing every filename in the archive ( v = verbose) in compressed format ( z = zip) in the file ( f ) named mjbackup.tar.gz . Files in subdirectories of /home/mj are also saved to this archive. You can then save this archived file to a backup area such as a network share or a tape drive.

Note  

Compressed tar archives often include the .tar.gz , .tgz , or .tar.bz2 extensions. The first two extensions are both tar archives compressed with the gzip command. The last extension, based on the bzip2 "Burrows-Wheeler block sorting compression algorithm," is slightly more efficient at data compression.

You can just as easily unarchive files with the following command:

 # tar tkvzf mjbackup.tar.gz 

This command lists ( t ) the files in your archive. When it restores , it does not overwrite your current files ( k = keep old files). In verbose ( v ) mode, you see everything that happens. If you stored files in a zipped format, you need to restore from the zipped ( z ) format. Also, it is restoring from the backup file named mjbackup.tar.gz .

You can review some of the available tar switches in Table 14.2. Note that the first switch in the tar command should start with a c , t , or an x .

Table 14.2: Command Options for tar

Option

Function

c

Creates an archive.

d

Compares files between an archive and a current directory.

f

Uses the following filename for the archive.

j

Compresses in bzip2 format to or from an archive.

k

Does not overwrite existing files.

r

Adds files to the end of an archive.

t

Lists files in a current archive.

v

Verbose; lists all files going in or coming out of an archive.

z

Zip. Compresses files to or from an archive in regular gzip format.

Note  

The tar command is path dependent. If you save the files in a directory using the absolute path (with a leading forward slash, such as /home/mj ), you can restore the files to that directory from any location on that computer. Alternatively, if you use the relative path (without a leading forward slash, such as home/mj ), files may not be restored to their original locations; it depends on the present working directory.

You can use a number of tar commands to create and extract archives. Some typical commands include the following. Read them over using the descriptions in Table 14.2.

 # tar xzvf download.tar.gz   # tar czvf backup.tar.gz /  somedirectory  
Note  

The tar command is similar to ps in that single-letter command options do not require a leading dash.

Archiving by cpio

The cpio command can help you archive a class of files, because unlike tar , it works with standard input and output. This use is suggested by its name ( cpio = copy + input/output).

As with tar , it s fairly easy to archive known directories (along with the files in their subdirectories). For example, if you want to back up the files in mj s home directory, you run the following command:

 # find /home/mj  cpio -o > mjarch.cpio 

But there is a disadvantage ; cpio takes from standard input and archives to standard output. Note how the standard input, all files in the /home/mj directory, are piped to the cpio command. Since this works with classes of files, you can use wildcards to set up a group of files as standard input as well. For example, the following command creates an archive from the .tif files in the current directory:

 # find *.tif  cpio -o > mjtifs.cpio 

Remember, the find command is flexible; the following command creates an archive from all the .tif files on your system:

 # find / -name 


Mastering Red Hat Linux 9
Building Tablet PC Applications (Pro-Developer)
ISBN: 078214179X
EAN: 2147483647
Year: 2005
Pages: 220

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