Option
Meaning
-A
Concatenate tar file(s) onto an existing tar file
-d
Use –diff to compare two archives
-r
Append files onto an existing tar file
-t
Output just the list of content (file names, directory names) of a tar file, not
the content itself
-u
Append only files newer than the tar file; used for incremental backup; note
that this only adds new files, it does not alter or add modified files
-j, -J, -z
Compress the tar file using bzip2, xz, gzip
-I
file
Compress using the executable compression program
file
432
◾
Linux with Operating System Concepts
The
cpio
program is newer than tar and can access either cpio or tar-based archives.
Cpio runs in one of three modes: copy-in, copy-out, and copy-pass. The copy-in and copy-
out modes are similar to extraction and creation operations in tar, respectively. This may
seem counterintuitive in that “in” usually denotes input into the program, but here “in”
references movement of data with respect to the file system (from archive into file system)
and “out” references movement out of the file system (from file system out to archive). The
options for copy-in and copy-out mode are -i and -o, respectively. Keep in mind then that
-i extracts from the archive while -o creates the archive.
The copy-pass mode is like using copy-out and copy-in combined and then discarding the
archive. That is, copy-pass takes files from one location and copies them to another as if you
were creating and then extracting from an archive but without retaining the archive itself.
Cpio in copy-out mode, unlike tar, is interactive. If using copy-out mode, you are placed
at a prompt where you type in file names. The instruction for copy-out mode is
cpio –o –F
filename
where
filename
is the archive to create. As you type each file name, that file’s contents are
copied into an archive.
A session to create or add to an archive might look like this.
$ cpio –o –F new_archive
file1.txt
file2.txt
file3.txt
<
control
+
d
>
183 blocks
$
After typing control
+
d, the cpio program archives the files whose names were entered.
These are placed into the new file new_archive. Once done, cpio responds with the archive’s
size in blocks and returns you to your Bash prompt. If the archive already exists, it is over-
written. You can append to an existing archive by adding the option --
append
.
The copy-in mode can be used to either output stored content (restore the content) or
output the names of the items in the archive. To extract the files from the archive, use
cpio –i –F
archive
and to list the contents, use
cpio –i –F
archive
–list
Another common backup tool is
rsync
. This program, while capable of performing
backups, is available as a network-based file copying tool. As such, it is similar to Linux
programs rcp (remote copy) and scp (secure copy). The command that you would issue
varies depending on whether you are doing a remote or local copy and in which direction.
There are three possibilities:
The Linux File System
◾
433
•
rsync
source destination
—local copy
•
rsync
username@host:source destination
—copy from remote to local
computer
•
rsync
source username@host:destination
—copy from local to remote
computer
Do'stlaringiz bilan baham: |