Tải bản đầy đủ (.docx) (9 trang)

Backing Up and Restoring

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (126.39 KB, 9 trang )

Backing Up and Restoring
Objectives
Upon completion of this module, you should be able to:
• Use the tar and compress commands to back up files and directories
• Use the jar command to save and compress files and directories
• Position a tape to a selected data set using the mt utility
Discussion – How frequently do you back up or restore files?
Contents Overview
In order to back up or easily transfer files via ftp or another method, you need to be able to
package and restore the files easily. This module covers the following commands:
• tar
• compress
• jar
• mt
In addition, specific instructions for backing up and restoring your home directory using tar
and compress are included.
The tar Command
The tar (tape archive) command enables you to back up single or multiple files in a directory
hierarchy.
Command Format
tar function_[letter/modifier] [output file]
filename(s)/directory(s)
Function Letters
c Create a new tar file
t List the table of contents of the tar file
x Extract the specified files from the tar file
Function Modifiers
f Specify the tar file ( /tmp/file.tar) or tape
drive (/dev/rmt/x) if other than default
v Execute in verbose mode
Saving a Directory to Tape


You can create the tar file using a relative path name.
$ cd /home
$ tar cv user1
This archives the user1 directory to the default device,/dev/rmt/0.
This command is also useful for creating archive files to share with other users or attach
to mail messages.
$ cd
$ tar cvf files.tar file1 file2 file3
file1
file2
file3
$
You can view the table of contents of the .tar file using tf or tvf option:
$ tar tf files.tar
file1
file2
file3
$
$ tar tvf files.tar
-rw-rw-r-- vominh/vominh 10240 2002-09-16 04:10:21 file1
-rw-rw-r-- vominh/vominh 12345 2002-09-16 04:10:21 file2 -rw-
rw-r-- vominh/vominh 10240 2002-09-16 04:10:34 file3
Use tar command to extract files from an archive:
$ tar xf files.tar
Note – The existed files will be overwritten without a notice.
The compress Command
The compress command is used to compress files using a special format to reduce the size of
the file from 20 percent to 80 percent.
Command Format
compress filename

Compressing a File
The following example uses the -v (verbose) option to compress a file called
bin.file:
The file is compressed and a .Z suffix is appended to the file name.
$ compress -v bin.file
bin.file: Compression: 70.84% -- replaced with
bin.file.Z
Files are uncompressed using the uncompress command.
Command Format: Uncompressing
uncompress filename
Uncompressing a File
$ uncompress bin.file.Z
The jar Command
The jar command is similar to the tar command, but compresses the resulting file in the
same step. It is a Java™ application that combines multiple files into a single JAR (Java archive)
file. It is also a generalpurpose archiving and compression tool, based on ZIP and the ZLIB
compression format. The jar command was originally created for Java programmers to
download multiple files with one request, rather than having to issue a download request for each
separate file. jar is standard with the Linux operating system, but is available on any system
that has Java virtual machine (JVM) installed.
Command Format
The syntax for the jar tool is almost identical to the syntax for the tar
command.
jar options [ output file ] filename(s)/directory(s)
Options
c Create a new jar file
t List the table of contents of the jar file
x Extract the specified files from the jar file
f Specify the jar file ( /tmp/file.jar) or tape drive (/dev/rmt/x) if other
than default

v Execute in verbose mode
Note – It is not necessary to use a hyphen (-) before options when
issuing the jar command.
Adding All the Files in a Directory to an Archive
$ ls
dante dir1 dir3 file1 file3 fruit
dante_1 dir2 dir4 file2 file4 fruit2
$ jar cvf bundle.jar *
adding: dante (in=1320) (out=744) (deflated 43%)
adding: dante_1 (in=368) (out=242) (deflated 34%)
adding: dir1/ (in=0) (out=0) (stored 0%)
adding: dir1/coffees/ (in=0) (out=0) (stored 0%)
adding: dir1/coffees/beans (in=0) (out=0) (stored 0%)
adding: dir1/coffees/nuts (in=0) (out=0) (stored 0%)
adding: dir1/fruit/ (in=0) (out=0) (stored 0%)
adding: dir1/trees/ (in=0) (out=0) (stored 0%)
adding: dir2/ (in=0) (out=0) (stored 0%)
<output omitted>
adding: file1 (in=1696) (out=874) (deflated 48%)
<output omitted>
Note – The jar tool is not intended for backing up symbolic links.
Error messages will display if this is attempted.
The mt Command
The mt command enables direct tape manipulation.
Command Format
mt [ -f tape-device-name] command[ count]
The -f option is used to specify the tape device file name, typically a no-rewind device
file name. If the -f option is omitted, the value of the TAPE environment variable is
used to determine the tape device to manipulate.
Commands

status Displays status information about the tape drive.
rewind Rewinds the tape.
retension Rewinds the cartridge tape completely, winds
the tape forward to the end of the tape, then
rewinds back to the beginning of the tape to
smooth out the tape tension.
erase Erases the entire tape.
fsf Forward skips count tape files.
bsf Backward skips count tape files.
eom Skips to the end of the recorded media.
off Ejects 4- or 8-mm tapes.
Note – Only the unique prefix of a command is required. For example,
use ret in place of retension.
Use the following mt command to rewind a tape:
$ mt rew
To have the tape skip forward a tape file, use the following command:
$ mt -f /dev/rmt/0n fsf 1
The device name /dev/rmt/0n tells the tape drive not to rewind the tape after it has
performed a function. This device naming convention can also be used when archiving
files with tar and jar.
Note – The retension option does not work with 8-mm tapes.

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×