Contact us |
Using cpio
1. Make sure you are still in the sample directory. 2. Create files that we wish to backup differentially with respect to the full backup performed above. root@localhost sample# touch file6 file7 3. Go down one directory root@localhost sample# cd .. 4. Create a new archive “sample_diff.tar” that contains only the new files root@localhost folder1# tar –C sample -cvf sample_diff.tar file6 file7 5. To check the contents of the new archive, run root@localhost folder1# tar –tf sample_diff.tar What is the output of this command? Now you can safely delete the entire sample directory and restore its entire contents from the full and differential backup. 6. Write down the command that you would use to back up the entire “/root/folder1” directory to an archive named folder1.tar. To backup and restore a directory to a new location You will now see a more practical use for “tar”. Here you will try back up the user ying’s home directory (/home/ying) and restore it to a new location “/home/ying-test/ying”. 1. Create the new directory “/home/ying-test” using the “mkdir” command. 2. Change directory to the /home directory. 3. Now run the tar command. Type: root@localhost home# tar -cf - ying | (cd /home/ying-test; tar –xvpf - ) 4. For the new home directory to be truly usable by ying, you need to change the owner of the directory and contents to that of user ying. (try : “chown -R ying:ying ying-test”). You also need to edit the “/etc/passwd” file to reflect the new home directory. The above exercises are just a sample of how to perform a “plain vanilla” type of backup. There are far more complex ways and utilities that can be used for backing up a system. Using cpio cpio is a tool for creating and extracting archives, or copying files from one place to another. It handles a number of cpio formats as well as reading and writing tar files. cpio copies files into or out of a cpio or tar archive, which is a file that contains other files plus information about them, such as their file name, owner, timestamps, and access permissions. The archive can be another file on the disk, a magnetic tape, or a pipe. cpio has three operating modes - copy-out, copy-in and copy-pass mode. In copy-out mode, cpio copies files into an archive. It reads a list of filenames, one per line, on the standard input, and writes the archive onto the standard output. A typical way to generate the list of filenames is with the find command; you should give find the -depth option to minimize problems with permissions on directories that are un-writable or not searchable. In copy-in mode, cpio copies files out of an archive or lists the archive contents. It reads the archive from the standard input. In copy-pass mode, cpio copies files from one directory tree to another, combining the copy-out and copy-in steps without actually using an archive. It reads the list of files to copy from the standard input; the directory into which it will copy them is given as a non-option argument. Usage: cpio cpio {-o|--create} -0acvABLV -C bytes -H format -M message [-O [user@]host:]archive] [-F [user@]host:]archive] [--file=[user@]host:]archive] --format=format --message=message --null --reset-access-time --verbose --dot --append --block-size=blocks --dereference --io-size=bytes --quiet --force-local --rsh-command=command --help --version < name-list > archive cpio {-i|--extract} -bcdfmnrtsuvBSV -C bytes -E file -H format -M message [-R user:.group] [-I [user@]host:]archive] [-F [user@]host:]archive] [--file=[user@]host:]archive] --make-directories --nonmatching --preserve-modification-time --numeric-uid-gid --rename --list --swap-bytes --swap --dot --unconditional --verbose --block-size=blocks --swap-halfwords --io-size=bytes --pattern-file=file --format=format [--owner=user:.group] --no-preserve-owner --message=message --force-local --no-absolute-filenames --sparse --only-verify-crc --quiet --rsh-command=command --help --version pattern... < archive cpio {-p|--pass-through} -0adlmuvLV [-R user:.group] --null --reset-access-time --make-directories --link --quiet --preserve-modification-time --unconditional --verbose --dot --dereference [--owner=user:.group] --no-preserve-owner --sparse --help --version destination-directory < name-list To use cpio 1. Change to the “/root/folder1” directory you created earlier. 2. Make sure you still have the sample directory in your pwd. Archive the contents of the sample directory using cpio. Type: root@localhost folder1# find sample | cpio -ocv > mybackup.cpio sample sample/file1 sample/file2 sample/file3 sample/file4 sample/file5 sample/file6 sample/file7 3 blocks 3. List the contents of archive you created. Type: root@localhost folder1# cpio - t < mybackup.cpio 4. Test the backup you created by deleting the sample directory. Type: root@localhost folder1# rm -rf sample 5. Restore the sample directory from the cpio backup you created. Type: root@localhost folder1# cpio -iv < mybackup.cpio 6. List the contents of the sample directory to make sure everything was restored properly.
|
Login... |
||||