TrumanWong

cpio

Utility program used to create and restore backup files

Supplementary instructions

cpio command is mainly a tool program used to create or restore backup files. The cpio command can copy files to or from the archive package.

grammar

cpio(option)

Options

-0 or --null: accept new column control characters, usually used with the "-print0" parameter of the find command;
-a or --rest-access-time: Reset the access time of the file;
-A or --append: Append to an existing backup file, and this backup file must be stored on the disk and cannot be placed in the tape drive;
-b or --awap: The effect of this parameter is the same as specifying the "-ss" parameter at the same time;
-B: Change the input/output block size to 5210Bytes;
-c: Use the old ASCII backup format;
-C<block size> or --io-size=<block size>: Set the input/output block size, the unit is Byte;
-d or --make-directories: cpio will create directories by itself if necessary;
-E<template file> or --pattern-file=<template file>: Specify a template file, which contains one or more template styles, allowing cpio to unlock files that meet the template conditions. The format is one template style per column;
-f or --nonmatching: Let cpio unpack all files that do not meet the template conditions;
-F<backup file> or --file=<backup file>: Specify the name of the backup file, which is used to replace the standard input or output. It can also be used to access the backup file through the network using the storage device of another host;
-H<backup format>: Specify the file format to be used for backup;
-i or --extract: execute copy-in mode and restore backup files;
-l<backup file>: Specifies the name of the backup file, which is used to replace the standard input and can also be used to read the backup file through the network using the storage device of another host;
-k: This parameter will be ignored and will not be processed. It is only responsible for solving compatibility issues between different versions of cpio;
-l or --link: Replace copying files with hard links and can be used in copy-pass mode;
-L or --dereference: Do not establish a symbolic link and directly copy the original file pointed to by the link;
-m or preserve-modification-time: Do not change the modification time of the file;
-M<return message> or --message=<return message>: Set the information for changing the save media;
-n or --numeric-uid-gid: When using the "-tv" parameter to list the contents of the backup file, if the parameter "-n" is added, the owner and group will be replaced by the user ID and group ID. Group name lists files;
-o or --create: execute copy-out mode and create a backup file;
-O<backup file>: Specifies the name of the backup file, which is used to replace the standard output. It can also be used to use the storage device of another host through the network to store the backup file;
-p or --pass-through: execute copy-pass mode, skip the backup step, and copy the file directly to the destination directory;
-r or --rename: Use interactive mode when a file name needs to be changed;
-R<owner><:/.><group> or ----owner<owner><:/.><group> Restore the backup file in copy-in mode, or copy-pass mode When copying files, you can specify the backup, owner and group of the copied files;
-s or --swap-bytes: exchange the contents of each queue of bytes;
-S or --swap-halfwords: Swap the contents of each half byte;
-t or --list: Present the input content;
-u or --unconditional: Replace all files, regardless of whether the date and time are new or old, and overwrite them directly without asking;
-v or --verbose: Display the execution process of the command in detail;
-V or --dot: when executing instructions. Add a "." sign in front of the executable program of each file;
--block-size=<block size>: Set the input/output block size. If the value is set to 5, the block size is 2500. If it is set to 10, the block size is 5120, and so on;
--force-local: Force the backup file to be stored on the local host;
--help: online help;
--no-absolute-filenames: Use relative paths to create file names;
--no-preserve-owner: Do not preserve the owner of the files. Whoever unlocks the backup file will own those files;
-only-verify-crc: When the backup file uses CRC backup format, you can use this parameter to check whether each file in the backup file is correct;
--quiet: Do not display how many blocks have been copied;
--sparse: If a file contains a large number of consecutive 0 bytes, the file will be stored in a sparse file;
--version: Display version information.

Example

**Back up all ordinary files under /etc to /opt/etc.cpio, use the following command: **

find /etc –type f | cpio –ocvB >/opt/etc.cpio

**Back up all data on the system to the tape drive, use the following command: **

find / -print | cpio -covB > /dev/st0

Here /dev/st0 is the device name of the tape, which represents the SCSI tape drive.

**To view the files backed up on the tape drive in the above example, use the following command: **

cpio -icdvt < /dev/st0 > /tmp/st_content

Sometimes there may be too many backup files that cannot be displayed on one screen. In this case, we use the following command to output the file information of the tape drive to a file.

**Restore the backup package in Example 1 to the corresponding location. If there are identical files to overwrite, use the following command: **

cpio –icduv < /opt/etc.cpio

Note that for the cpio recovery path, if cpio uses absolute paths when packaging backups, it will automatically restore to these absolute paths during recovery. In this example, all backup files will be restored to the corresponding paths under the /etc path. in the directory. In the same way, if you use a relative path when packaging the backup, it will also be restored to the relative path when restoring.

From the above example, it can be seen that cpio cannot directly read files. It requires the complete path name of each file or directory to identify and read. The output of the find command just does this. Therefore, the cpio command is generally the same as find. Used in conjunction with the command. In fact, we have already seen their combined usage in the above examples.