0377-0382.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 360 行

HTML
360
字号




<HTML>

<HEAD>

<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Backup and Restore</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311739 //-->

<!-- TITLE=RED HAT LINUX 2ND EDITION //-->

<!-- AUTHOR=DAVID PITTS ET AL //-->

<!-- PUBLISHER=MACMILLAN //-->

<!-- IMPRINT=SAMS PUBLISHING //-->

<!-- PUBLICATION DATE=1998 //-->

<!-- CHAPTER=18 //-->

<!-- PAGES=0373-0382 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="0373-0376.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="../ch19/0383-0386.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-377"><P>Page 377</P></A>















<P>The advantage of this backup scheme is that it requires only two sets of tapes. Restoring

the full system from the level 0 backup and the previous evening's incremental can perform a

complete restore. The negative side is that the amount backed up grows throughout the week,

and additional tapes might be needed to perform the backup. Here is the second strategy:

</P>



<TABLE WIDTH="360">

<TR><TD>

Sunday

</TD><TD>

Level 0 backup

</TD></TR>

<TR><TD>

Monday

</TD><TD>

Level 1 backup

</TD></TR>

<TR><TD>

Tuesday

</TD><TD>

Level 2 backup

</TD></TR>

<TR><TD>

Wednesday

</TD><TD>

Level 3 backup

</TD></TR>

<TR><TD>

Thursday

</TD><TD>

Level 4 backup

</TD></TR>

<TR><TD>

Friday

</TD><TD>

Level 5 backup

</TD></TR>

<TR><TD>

Saturday

</TD><TD>

Level 6 backup

</TD></TR>

</TABLE>













<P>The advantage of this backup scheme is that each backup is relatively quick. Also, the

backups stay relatively small and easy to manage. The disadvantage is that it requires seven sets of

tapes. Also, to do a complete restore, you must use all seven tapes.

</P>









<P>When deciding which type of backup scheme to use, you need to know how the system is

used. Files that change often should be backed up more often than files that rarely change.

Some directories, such as /tmp, never need to be backed up.

</P>









<H4><A NAME="ch18_ 7">





Performing Backups with tar and cpio

</A></H4>









<P>A full backup with tar is as easy as

</P>





<!-- CODE SNIP //-->

<PRE>

$ tar -c /

</PRE>

<!-- END CODE SNIP //-->











<P>An incremental backup takes a bit more work. Fortunately, the

find command is a wonderful tool to use with backups. The

find command can be used to find all files that have

changed since a certain date. It can also find files that are newer than a specified file. With this

information, it is easy to perform an incremental backup. The following command finds all files

that have been modified today, and backs up those files with the

tar command to an archive on

/dev/rmt1:

</P>





<!-- CODE SNIP //-->

<PRE>

$ tar c1 `find / -mtime -1 ! -type d -print`

</PRE>

<!-- END CODE SNIP //-->











<P>! -type d says that if the object found is a directory, don't give it to the

tar command for archiving. This is done because

tar follows the directories, and you don't want to back up

an entire directory unless everything in it has changed. Of course, the

find command can also be used for the cpio command. The following command performs the same task as the

preceding tar command:

</P>





<!-- CODE SNIP //-->

<PRE>

$ find / -mtime -1 | cpio -o &gt;/dev/rmt1

</PRE>

<!-- END CODE SNIP //-->











<P>As mentioned, the find command can find files that are newer than a specified file. The

touch command updates the time of a file. Therefore, it is easy to touch a file after a backup has

</P>



<A NAME="PAGENUM-378"><P>Page 378</P></A>











<P>completed. Then, at the next backup, you simple search for files that are newer than the

file you touched. The following example searches for files that are newer than the file

/tmp/last_backup and performs a cpio to archive the data:

</P>





<!-- CODE SNIP //-->

<PRE>

$ find / -newer /tmp/last_backup -print | cpio -o &gt; /dev/rmt0

</PRE>

<!-- END CODE SNIP //-->











<P>With tar, the same action is completed this way:

</P>





<!-- CODE SNIP //-->

<PRE>

$ tar c1 `find / -newer /tmp/last_backup -print`

</PRE>

<!-- END CODE SNIP //-->



<TABLE BGCOLOR="#FFFF99">

<TR><TD><B>

NOTE

</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

<BR>You will want to touch the file before you start the backup. This means that you have to

use different files for each level of backup, but it ensures that the next backup gets any files

that are modified during the current backup.

</BLOCKQUOTE></TD></TR>

</TABLE>

<BR>



<H3>

Restoring Files

</H3>









<P>Backing up files is a good thing. But, backups are like an insurance policy. When it is time

for them to pay up, you want it all, and you want it now! In order to get the files, you must

restore them. Fortunately, it is not difficult to restore files with either

tar or cpio. The following command restores the file

/home/alana/bethany.txt from the current tape in the drive:

</P>





<!-- CODE SNIP //-->

<PRE>

$ tar -xp /home/alana/bethany.txt

$ cpio -im `*bethany.txt$` &lt; /dev/rmt0

</PRE>

<!-- END CODE SNIP //-->











<P>The -p in tar and the -m in cpio ensures that all the file attributes are restored along with

the file. By the way, when restoring directories with

cpio, the -d option will create subdirectories. The

tar command does it automatically.

</P>









<H3><A NAME="ch18_ 8">

What Is on the Tape?

</A></H3>









<P>When you have a tape, you may or may not know what is on it. Perhaps you are using a

multiple level backup scheme and you don't know which day the file was backed up. Both

tar and cpio offer a way of creating a table of contents for the tape. The most convenient time to

create this file, of course, is during the actual backup. The following two lines show how to

perform a backup and at the same time create a table of contents file for that tape:

</P>





<!-- CODE SNIP //-->

<PRE>

$ tar -cv / &gt; /tmp/backup.Monday.TOC

$ find / -print | cpio -ov &gt; /dev/rmt0 2&gt; /tmp/backup.Monday.TOC

</PRE>

<!-- END CODE SNIP //-->













<P>The cpio backup automatically sends the list to standard error. Therefore, this line just

captures standard error and saves it as a file. By the way, if the

&gt; in the tar command is replaced with the word

tee, then the table of contents will not only be written to the file; it will also

be printed to standard output (the screen).

</P>



<A NAME="PAGENUM-379"><P>Page 379</P></A>













<H3><A NAME="ch18_ 9">

Summary

</A></H3>









<P>Backups are important, but being able to restore the files is more important. There is

nothing that will cause the lump in the throat to appear faster than trying to restore a system, only

to find that the backups failed. As with any administrative task performed on a system,

backups require a good plan, proper implementation, good documentation, and lots of testing.

An occasional spot check of a backup could save hours, if not days, of time.

</P>



<A NAME="PAGENUM-380"><P>Page 380</P></A>



<A NAME="PAGENUM-381"><P>Page 381</P></A>





<h3><P><A NAME="1739_ 0">Part V

</P></h3></A>





<H2>



Dealing with Others



</H2>



<P><B>In This PART

</P></B>







<UL>

<LI>     User Accounts and Logins 383

<LI>     System Security 395

<LI>     Shell Programming 411

</UL>







<A NAME="PAGENUM-382"><P>Page 382</P></A>









<P><CENTER>

<a href="0373-0376.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="../ch19/0383-0386.html">Next</A>

</CENTER></P>









</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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