📄 snapshots.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>File System Snapshots</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Storage" href="disks.html" /><link rel="PREVIOUS" title="Network, Memory, and File-Backed File Systems"href="disks-virtual.html" /><link rel="NEXT" title="File System Quotas" href="quotas.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="disks-virtual.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 16 Storage</td><td width="10%" align="right" valign="bottom"><a href="quotas.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="SNAPSHOTS" name="SNAPSHOTS">16.13 File System Snapshots</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Contributed by</span> Tom Rhodes.</i> <p>FreeBSD 5.0 offers a new feature in conjunction with <ahref="configtuning-disk.html#SOFT-UPDATES">Soft Updates</a>: File system snapshots.</p><p>Snapshots allow a user to create images of specified file systems, and treat them as afile. Snapshot files must be created in the file system that the action is performed on,and a user may create no more than 20 snapshots per file system. Active snapshots arerecorded in the superblock so they are persistent across unmount and remount operationsalong with system reboots. When a snapshot is no longer required, it can be removed withthe standard <a href="http://www.FreeBSD.org/cgi/man.cgi?query=rm&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">rm</span>(1)</span></a> command.Snapshots may be removed in any order, however all the used space may not be acquiredbecause another snapshot will possibly claim some of the released blocks.</p><p>During initial creation, the <var class="OPTION">schg</var> flag (see the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=chflags&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">chflags</span>(1)</span></a> manualpage) is set to ensure that even <tt class="USERNAME">root</tt> cannot write to thesnapshot. The <a href="http://www.FreeBSD.org/cgi/man.cgi?query=unlink&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">unlink</span>(1)</span></a> commandmakes an exception for snapshot files since it allows them to be removed with the <varclass="OPTION">schg</var> flag set, so it is not necessary to clear the <varclass="OPTION">schg</var> flag before removing a snapshot file.</p><p>Snapshots are created with the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=mount&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mount</span>(8)</span></a> command. Toplace a snapshot of <tt class="FILENAME">/var</tt> in the file <ttclass="FILENAME">/var/snapshot/snap</tt> use the following command:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">mount -u -o snapshot /var/snapshot/snap /var</kbd></pre><p>Alternatively, you can use <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=mksnap_ffs&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mksnap_ffs</span>(8)</span></a> tocreate a snapshot:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">mksnap_ffs /var /var/snapshot/snap</kbd></pre><p>Once a snapshot has been created, it has several uses:</p><ul><li><p>Some administrators will use a snapshot file for backup purposes, because the snapshotcan be transfered to CDs or tape.</p></li><li><p>File integrity, <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=fsck&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">fsck</span>(8)</span></a> may be ran onthe snapshot. Assuming that the file system was clean when it was mounted, you shouldalways get a clean (and unchanging) result. This is essentially what the background <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=fsck&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">fsck</span>(8)</span></a> processdoes.</p></li><li><p>Run the <a href="http://www.FreeBSD.org/cgi/man.cgi?query=dump&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">dump</span>(8)</span></a> utility on thesnapshot. A dump will be returned that is consistent with the file system and thetimestamp of the snapshot. <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=dump&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">dump</span>(8)</span></a> can also takea snapshot, create a dump image and then remove the snapshot in one command using the<var class="OPTION">-L</var> flag.</p></li><li><p><a href="http://www.FreeBSD.org/cgi/man.cgi?query=mount&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mount</span>(8)</span></a> the snapshotas a frozen image of the file system. To <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=mount&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mount</span>(8)</span></a> the snapshot<tt class="FILENAME">/var/snapshot/snap</tt> run:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">mdconfig -a -t vnode -f /var/snapshot/snap -u 4</kbd><samp class="PROMPT">#</samp> <kbd class="USERINPUT">mount -r /dev/md4 /mnt</kbd></pre></li></ul><p>You can now walk the hierarchy of your frozen <tt class="FILENAME">/var</tt> filesystem mounted at <tt class="FILENAME">/mnt</tt>. Everything will be in the same state itwas during the snapshot creation time. The only exception is that any earlier snapshotswill appear as zero length files. When the use of a snapshot has delimited, it can beunmounted with:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">umount /mnt</kbd><samp class="PROMPT">#</samp> <kbd class="USERINPUT">mdconfig -d -u 4</kbd></pre><p>For more information about <var class="OPTION">softupdates</var> and file systemsnapshots, including technical papers, you can visit Marshall Kirk McKusick's website at<a href="http://www.mckusick.com/" target="_top">http://www.mckusick.com/</a>.</p></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="disks-virtual.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="quotas.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Network, Memory, and File-Backed FileSystems</td><td width="34%" align="center" valign="top"><a href="disks.html"accesskey="U">Up</a></td><td width="33%" align="right" valign="top">File System Quotas</td></tr></table></div><p align="center"><small>This, and other documents, can be downloaded from <ahref="ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/">ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/</a>.</small></p><p align="center"><small>For questions about FreeBSD, read the <ahref="http://www.FreeBSD.org/docs.html">documentation</a> before contacting <<ahref="mailto:questions@FreeBSD.org">questions@FreeBSD.org</a>>.<br />For questions about this documentation, e-mail <<ahref="mailto:doc@FreeBSD.org">doc@FreeBSD.org</a>>.</small></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -