-->
Previous | Table of Contents | Next |
Another way to create the tar file is to start from datas parent directory and specify the directory name as the thing to archive. Heres the command sequence:
$ pwd /home/dave $ tar cvf data.tar data
This also creates an archive of the data directory, but it puts the directory entry as the first thing in the archive. This way, when the tar file is extracted, the first thing thats created is the directory data, and all the files in data are placed in the data subdirectory.
NOTE: If you want to create a tar file of all the files in the directory, its a good idea to specify a different location for the tar file (other than the current directory). That way, if you try to archive all the files in the current directory, tar wont get confused and try to add its tar file recursively to the tar that its creating.
cpio is a general-purpose command for copying file archives. You can use it to create backups by using the -o option, or to restore files by using the -i option. It takes its input from standard input and sends its output to standard output.
The advantages of cpio include the following:
Some people find cpios syntax to be a bit more confusing than tars syntax. Also, to perform incremental backups, you have to do some shell programming.
Table 11.2 lists the commonly used options for cpio. See cpios man page for a complete description of the options you can use with this command.
Option | Description |
---|---|
-o | Copy out. Creates an archive on standard out. |
-B | Blocks input or output at 5,120 bytes per record; useful for efficient storage on magnetic tape. |
-i | Copy in. Extracts files from standard input. This is typically used when the standard input is the result of a copy out action of another cpio command. |
-t | Creates a table of contents of the input. |
The following list provides some examples of using cpio to back up and restore files:
ls /home | cpio -o > /dev/fd0
cpio -it < /dev/fd0 > bkup.indx
find /home -mtime 1 -type f -print | cpio -oB > /dev/fd0
echo "/home/dave/notes.txt" | cpio -i < /dev/fd0
NOTE: You must give the complete filename to restore a file with cpio.
TIP: You can automate any of these commands by putting them in roots crontab file. For example, you could put the following entry in the roots cron file to perform a daily backup of /home at 1:30 a.m.:30 01 * * * ls /home | cpio -o > /dev/fd0If you need to do more complicated backups, you can create shell scripts to control your backups. You also can run these shell scripts via cron.
You can find more information about system administration in the following chapters:
Previous | Table of Contents | Next |