⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch20_03.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 20] 20.3 How to Make Backups with a Local Tape Drive </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-10-23T15:44:50Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch20_01.htm"TITLE="20. Backing Up Files"><LINKREL="prev"HREF="ch20_02.htm"TITLE="20.2 Make Your Own Backups "><LINKREL="next"HREF="ch20_04.htm"TITLE="20.4 Restoring Files from Tape with tar "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch20_02.htm"TITLE="20.2 Make Your Own Backups "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 20.2 Make Your Own Backups "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 20<BR>Backing Up Files</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch20_04.htm"TITLE="20.4 Restoring Files from Tape with tar "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 20.4 Restoring Files from Tape with tar "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0422">20.3 How to Make Backups with a Local Tape Drive </A></H2><PCLASS="para">As we said in article<ACLASS="xref"HREF="ch20_02.htm"TITLE="Make Your Own Backups ">20.2</A>,making a backup is easy:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cd</B></CODE>% <CODECLASS="userinput"><B>tar c .</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">The<EMCLASS="emphasis">cd</EM>command moves you to your home directory.You could back up any directory the same way.</P><PCLASS="para">The<SPANCLASS="link"><EMCLASS="emphasis">tar</EM> (<ACLASS="linkend"HREF="ch20_01.htm#UPT-ART-8024"TITLE="tar in a Nutshell ">20.1</A>)</SPAN>command, which is an abbreviation of <EMCLASS="emphasis">t</EM>ape <EMCLASS="emphasis">ar</EM>chive,copies the current directory (specified by the <CODECLASS="literal">.</CODE>)to the default tape drive. The <CODECLASS="literal">c</CODE>argument specifies the<EMCLASS="emphasis">create</EM>mode of <EMCLASS="emphasis">tar</EM>.</P><PCLASS="para">You might get an error. Something about device<EMCLASS="emphasis">rmt8</EM>off line. Don't worry. I exaggerated slightly whenI said <EMCLASS="emphasis">tar</EM>was easy to use.The tape devicethat SunOS <EMCLASS="emphasis">tar</EM>uses by default is<EMCLASS="emphasis">/dev/rmt8</EM> (yours may be different).There are several types of tape units, and not allcan be referred to using that name.Some system administrators will link that name to the actualdevice, which makes <EMCLASS="emphasis">tar</EM>easier to use. But if that doesn't work, you need to specifyadditional arguments to <EMCLASS="emphasis">tar</EM>.</P><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-422-SECT-1.1">20.3.1 Syntax of the tar Command </A></H3><PCLASS="para">Most UNIX commands follow a certain style when arguments are specified.<EMCLASS="emphasis">tar</EM>does not follow this convention, so you must be careful touse <EMCLASS="emphasis">tar</EM>properly.If the standard was followed, then the following might be an exampleof dumping the current directory to the 1/2-inch tape cartridge,verbose mode, block size of 20:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>tapedump -c -v -b 20 -f /dev/rmt8 .</B></CODE>   <EMCLASS="emphasis">Wrong!</EM></PRE></BLOCKQUOTE></P><PCLASS="para">Instead, all the flags are in the first argument, and the parameters to those flags follow the first argument, in order of theflags specified:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>tar cvbf 20 /dev/rmt8 .</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">The same command can be specified in a different way by changing the order of the letters in the first argument:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>tar cvfb /dev/rmt8 20 .</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">(Article<ACLASS="xref"HREF="ch20_11.htm"TITLE="Getting tar's Arguments in the Right Order ">20.11</A>has diagrams and more information about the order of arguments.)The only key letter that has a fixed location is the firstone, which must specify if you are reading or writing an archive.The most common key letters, and the functions they perform are listed in<ACLASS="indexterm"NAME="AUTOID-21849"></A><ACLASS="indexterm"NAME="AUTOID-21852"></A><ACLASS="indexterm"NAME="AUTOID-21855"></A><ACLASS="xref"HREF="ch20_03.htm#UPT-ART-422-TAB-0"TITLE="Common tar Key Letters">Table 20.1</A>.</P><TABLECLASS="table"><CAPTIONCLASS="table"><ACLASS="title"NAME="UPT-ART-422-TAB-0">Table 20.1: Common tar Key Letters</A></CAPTION><THEADCLASS="thead"><TRCLASS="row"VALIGN="TOP"><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Key Letter</TH><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Function</TH></TR></THEAD><TBODYCLASS="tbody"><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">c</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Create an archive.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">x</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Extract files from an archive.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">t</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Table of contents.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">v</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Give verbose information.</TD></TR></TBODY></TABLE><PCLASS="para">Some versions of <EMCLASS="emphasis">tar</EM> require a hyphen (<CODECLASS="literal">-</CODE>) before the letter.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-422-SECT-1.2">20.3.2 What Is the Name of the Tape Drive? </A></H3><PCLASS="para">Part of the difficulty in using <EMCLASS="emphasis">tar</EM>is figuring out which filename to use for which device.The best way to find out is by asking your system administrator.If you can't, here are some ideas for Sun computers.If you have a 1/2-inch tape drive, try:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>tar cf /dev/rmt8 .</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">If you have a 1/4-inch tape cartridge[or any drive connected by SCSI<EMCLASS="emphasis">-JP</EM>&nbsp;], try:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>tar cf /dev/rst8 .</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">If this doesn't work, then try changing the <CODECLASS="literal">8</CODE>to a<CODECLASS="literal">0</CODE>.You can also list the devices in the <EMCLASS="emphasis">/dev</EM>directory and look for one that has the most recent usage:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch16_02.htm"TITLE="16.2 Finding Oldest or Newest Files with ls -t and ls -u ">ut</A> <ACLASS="co"HREF="ch15_02.htm"TITLE="15.2 Filename Wildcards in a Nutshell ">[ ]</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>ls -lut /dev/r[ms]t*</B></CODE></PRE></TD></TR></TABLE></P><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-422-IX-NAMING-MAGNETIC-TAPES"></A><ACLASS="indexterm"NAME="UPT-ART-422-IX-MAGNETIC-TAPES-NAMING"></A>Some UNIX systems use different standards for naming magnetic tapes.There might be an<EMCLASS="emphasis">h</EM>at the end of a name for <EMCLASS="emphasis">high density</EM>.When in doubt, examine the<SPANCLASS="link">major and minor numbers (<ACLASS="linkend"HREF="ch17_22.htm"TITLE="Finding the Links to a File ">17.22</A>)</SPAN>(using the<EMCLASS="emphasis">ls -l</EM>command) and read the appropriate manual page, whichcan be found by searching through the possible entries using<SPANCLASS="link"><EMCLASS="emphasis">man -k</EM> or <EMCLASS="emphasis">apropos</EM> (<ACLASS="linkend"HREF="ch50_02.htm"TITLE="The apropos Command ">50.2</A>)</SPAN>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>man -k mt</B></CODE>% <CODECLASS="userinput"><B>man -k tape</B></CODE></PRE></BLOCKQUOTE></P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-422-SECT-1.3">20.3.3 More on Tape Names </A></H3><PCLASS="para">The names of tape devices typically start with an <EMCLASS="emphasis">r</EM>,which suggests they are<EMCLASS="emphasis">raw</EM>devices that do not support a filesystem.If the first two letters are<EMCLASS="emphasis">nr</EM>,then this suggests a<EMCLASS="emphasis">no-rewind</EM>operation.Normally the tape is automatically rewound when you are done.If you repeat the <EMCLASS="emphasis">tar</EM>command, it will overwrite the first dump.[1]As this can waste large amounts of tape if the dumps are small, use the<EMCLASS="emphasis">nr</EM>name of the tape to put several dumps on one tape.As an example, if you wanted to dump three separate directoriesto a 1/4-inch tape cartridge, you can type:&#13;</P><BLOCKQUOTECLASS="footnote"><PCLASS="para">[1] This is probably not what you want.You could use a new tape for each dump.</P></BLOCKQUOTE><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cd dir1</B></CODE>% <CODECLASS="userinput"><B>tar cf /dev/nrst8 .</B></CODE>% <CODECLASS="userinput"><B>cd dir2</B></CODE>% <CODECLASS="userinput"><B>tar cf /dev/nrst8 .</B></CODE>% <CODECLASS="userinput"><B>cd dir3</B></CODE>% <CODECLASS="userinput"><B>tar cf /dev/rst8 .</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Note that the third dump does not use theno-rewindname of the device, so that it will rewind when done.</P><PCLASS="para">To examine a tape without extracting any files, get a table of contents and use the key letter<CODECLASS="literal">t</CODE>or<CODECLASS="literal">tv</CODE>instead of the<CODECLASS="literal">c</CODE> .Adding the<CODECLASS="literal">v</CODE> flag gives a more verbose listing.</P><PCLASS="para">If you want to examine the third dump file, you can either use<EMCLASS="emphasis">tar</EM>twice with the no-rewindnames or skip forward one or more dump filesby using the<EMCLASS="emphasis">mt</EM>(magnetic tape)command to skip forward two.Be sure to use the no-rewind name:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>mt -f /dev/nrst8 fsf 2</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">In some versions of <EMCLASS="emphasis">tar</EM>,if you defined an environment variable<EMCLASS="emphasis">TAPE</EM>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">setenv TAPE /dev/rst8</PRE></BLOCKQUOTE></P><PCLASS="para">then you don't have to specify it for the<EMCLASS="emphasis">mt</EM>or<EMCLASS="emphasis">tar</EM>commands.</P><ACLASS="indexterm"NAME="AUTOID-21959"></A><ACLASS="indexterm"NAME="AUTOID-21960"></A></DIV><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">BB</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch20_02.htm"TITLE="20.2 Make Your Own Backups "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 20.2 Make Your Own Backups "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch20_04.htm"TITLE="20.4 Restoring Files from Tape with tar "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 20.4 Restoring Files from Tape with tar "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">20.2 Make Your Own Backups </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">20.4 Restoring Files from Tape with tar </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -