📄 lsg22.htm
字号:
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Specifies the archive media device name</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
F
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Specifies the name of a file for tar arguments</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
k
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Gives size of archive volume (in kilobytes)</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
l
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Displays error messages if links are unresolved</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
m
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Does not restore modification times</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
n
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Indicates the archive is not a tape</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
p
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Extracts files with their original permissions</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
v
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Provides verbose output (lists files on the console)</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
w
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Displays archive action and waits for user confirmation</FONT>
</TABLE><P>The tar command uses absolute pathnames for most actions, unless you specify the A modifier.
<BR>
<P>A few examples may help explain the tar command and how to use tar switches. If you are using a tape drive called /dev/tape and the entire filesystem to be archived totals less than <A NAME="I2"></A>the tape's capacity, you can create the tape archive with the following command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar cf /dev/tape /</FONT></PRE>
<P>The f option enables you to specify the device name, /dev/tape in this case. The entire root filesystem is archived in a new archive file (indicated by the c). Any existing contents on the tape are automatically overwritten when the new archive is created. (You are not asked whether you are sure you want to delete the existing contents of the tape, so make sure you are overwriting material you don't need.) If you include the v option in the command, tar would echo the filenames and their sizes to the console as they are archived.
<BR>
<P>If you need to restore the entire filesystem from the tape used in the preceding example, issue the command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar xf /dev/tape</FONT></PRE>
<P>This command restores all files on the tape because no specific directory has been indicated for recovery. The default, when no file or directory is specified, is the entire tape archive. If you want to restore a single file from the tape, use the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar xf /dev/tape /usr/tparker/big_file</FONT></PRE>
<P>which restores only the file /usr/tparker/big_file.
<BR>
<P>Sometimes you may want to obtain a list of all files on a tape archive. You can do this with the following command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar tvf /dev/tape</FONT></PRE>
<P>This command uses the v option to display the results from tar. If the list is long, you may want to redirect the command to a file.
<BR>
<P>Most tapes require a blocking factor when creating an archive, but you don't need to specify a blocking factor when reading a tape because tar can figure it out automatically. The blocking factor tells tar how much data to write in a chunk on the tape. When archiving to a tape, you specify the blocking factor with the b modifier. For example, the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar cvfb /dev/tape 20 /usr</FONT></PRE>
<P>creates an new archive on /dev/tape that has a blocking factor of 20 and contains all the files in /usr. Most tapes can use a blocking factor of 20, and you can assume this factor as a default value unless your tape drive specifically won't work with this value. The only times blocking factors are changed are for floppy disks and other hard disk volumes. Note that the arguments following the modifiers are in the same order as the modifiers. The f precedes the b modifier so the arguments have the device before the blocking factor. The arguments must be in the same order as the modifiers, which can sometimes cause a little confusion.
<BR>
<P>Another common problem is that a tape may not be large enough to hold the entire archive, in which case more than one tape will be needed. To tell tar the size of each tape, you need the k option. This option uses an argument that is the capacity in kilobytes. For example, the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar cvbfk 20 /dev/tape 122880 /usr</FONT></PRE>
<P>tells tar to use a blocking factor of 20 for the device /dev/tape. The tape capacity is 122880 kilobytes (approximately 120 M). Again, note that the order of arguments matches the order of the modifiers.
<BR>
<P>Floppy disks create another problem with tar, as the blocking factor is usually different. When you use floppy disks, archives usually require more than one disk. You use the k option to specify the archive volume's capacity. For example, to back up the /usr/tparker directory to 1.2M floppy disks, the command would be
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar cnfk /dev/fd0 1200 /usr/tparker</FONT></PRE>
<P>where /dev/fd0 is the device name of the floppy drive and 1200 is the size of the disk in kilobytes. The n modifier tells tar that this is not a tape. As a result, tar runs a little more efficiently than if the modifier had been left off.
<BR>
<BR>
<A NAME="E68E123"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Summary</B></FONT></CENTER></H3>
<BR>
<P>This chapter looked at the basics of backups. You should maintain a backup log and make regular backups to protect your work. Although tar is a little awkward to use at first, it soon becomes second nature. You can use the tar command in combination with compression utilities such as compress. Alternatively, you can use utilities like gzip and gunzip that combine both utilities into one program. Although this program may be more convenient, tar is still the most widely used archive utility and is therefore worth knowing.
<BR>
<P>A number of scripts are beginning to appear that automate the backup process or give you a menu-driven interface to the backup system. These scripts are not in general distribution, but you may want to check FTP and BBS sites for a utility that simplifies backups for you.
<P ALIGN=LEFT>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -