cpio

 < Day Day Up > 

cpio is a powerful utility that is used in conjunction with find to perform full and incremental backups. cpio is an established Linux and UNIX utility that works similarly on most Linux and UNIX variants.

You'll use several commands in the upcoming examples, including the following:

 # find . -print | cpio -ov > /dev/st0 ;find the contents of                                            the current dir and                                            write them to tape. # cpio -it < /dev/st0        ;read table of contents (t) of tape. # cpio -iv < /dev/st0        ;restore (i) the contents of tape. 

The first command you'll issue is to find the contents in /var/log/sa and write them to your tape device /dev/st0. The options to cpio used in the following example are o for output mode and v for verbose reporting:

 [root@demtstd1 log]# cd /var/log/sa [root@demtstd1 log]# find . -print | cpio -ov > /dev/st0. . ./sa05 ./sa03 ./sa04 ./sar03 ./sar04 ./sa25 ./sa26 ./sar24 ./sa27 ./sar26 ./sa28 ./sar27 ./sa01 ./sar28 ./sa02 ./sar01 ./sar02 ./sar25 10637 blocks [root@demtstd1 sa]# 

In the example, you first changed directory to /var/log/sa, then issued the find command and pipe its output to cpio. cpio is almost always used in conjunction with find in the manner shown in the example. This produced a backup with relative path names because we changed to the directory /var/ log/sa before issuing the backup commands.

Next, view the contents of the tape to see the files you wrote to it with cpio. The i option is used for input, and the t option is used to get a table of contents in the following listing:

 [root@demtstd1 sa]# cpio -it < /dev/st0. . sa05 sa03 sa04 sar03 sar04 sa25 sa26 sar24 sa27 sar26 sa28 sar27 sa01 sar28 sa02 sar01 sar02 sar25 10637 blocks [root@demtstd1 sa]# 

Now that you have written to the tape and viewed its table of contents, you'll restore the contents of /var/log/sa to the directory /root/test.cpio. In the following example, you use only the -i option to extract the files from tape to the present directory.

 [root@demtstd1 sa]# cd /root [root@demtstd1 root]# mkdir test.cpio [root@demtstd1 root]# cd test.cpio [root@demtstd1 test.cpio]# cpio -iv < /dev/st0. . sa05 sa03 sa04 sar03 sar04 sa25 sa26 sar24 sa27 sar26 sa28 sar27 sa01 sar28 sa02 sar01 sar02 sar25 10637 blocks [root@demtstd1 test.cpio]# pwd /root/test.cpio [root@demtstd1 test.cpio]# ll total 5440 -rw-r--r--    1 root     root     329701 Mar 5 10:54 sa01 -rw-r--r--    1 root     root     329701 Mar 5 10:54 sa02 -rw-r--r--    1 root     root     329701 Mar 5 10:54 sa03 -rw-r--r--    1 root     root     329701 Mar 5 10:54 sa04 -rw-r--r--    1 root     root       4805 Mar 5 10:54 sa05 -rw-r--r--    1 root     root     329701 Mar 5 10:54 sa25 -rw-r--r--    1 root     root     329701 Mar 5 10:54 sa26 -rw-r--r--    1 root     root     329701 Mar 5 10:54 sa27 -rw-r--r--    1 root     root     329701 Mar 5 10:54 sa28 -rw-r--r--    1 root     root     311429 Mar 5 10:54 sar01 -rw-r--r--    1 root     root     311428 Mar 5 10:54 sar02 -rw-r--r--    1 root     root     311430 Mar 5 10:54 sar03 -rw-r--r--    1 root     root     311430 Mar 5 10:54 sar04 -rw-r--r--    1 root     root     311429 Mar 5 10:54 sar24 -rw-r--r--    1 root     root     311430 Mar 5 10:54 sar25 -rw-r--r--    1 root     root     311429 Mar 5 10:54 sar26 -rw-r--r--    1 root     root     311430 Mar 5 10:54 sar27 -rw-r--r--    1 root     root     311430 Mar 5 10:54 sar28 [m[root@demtstd1 test.cpio]# 

The cpio command produces a list of files that will be read from the tape and restored to the system. Often, I use several other options when restoring such as c for ASCII header format, v for verbose, B for block output, d for creating directories, u for unconditional write over existing files, and m to restore the original modification times.

This was a very quick overview of cpio. Often, I use it to perform backups of remote systems as well using the following format:

 # find . -print | cpio -o | (rsh remote_sys dd of=/dev/rmt/0m)           ;find the contents of the current dir and            write (o) them to tape on remote_sys. # rsh remote_sys "dd if=/dev/rmt/0m bs=8k" | cpio -iv                    ;restore the contents (i) of a tape on remote_sys                     to the local system. 

For rsh to work, you have to enable this command as shown in Chapter 8. In addition, you have to set up the .rhosts file with the name of the system to trust and the user name.

You can build from the simple examples in this cpio section to develop backup and restore commands to meet your needs in any environment.

     < Day Day Up > 


    Linux on HP Integrity Servers. A System Administrator's Guide
    Linux on HP Integrity Servers: A System Administrators Guide
    ISBN: 0131400002
    EAN: 2147483647
    Year: 2004
    Pages: 100

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