> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/handbook/di-21-zhang-cun-chu/21.10.-wen-jian-xi-tong-kuai-zhao.md).

# 21.10.文件系统快照

FreeBSD 提供了一项与 [软更新（Soft Updates）](/handbook/di-14-zhang-pei-zhi-fu-wu-ri-zhi-yu-dian-yuan-guan-li/14.1.-gai-shu.md) 结合使用的功能：文件系统快照。

UFS 快照能让用户创建指定文件系统的镜像，并将其作为文件处理。如果你使用的是 [Z 文件系统（ZFS）](/handbook/di-23-zhang-z-wen-jian-xi-tong-zfs/23.1.-shi-shi-mo-shi-zfs-yu-zhong-bu-tong.md)，请参考 [管理快照](/handbook/di-23-zhang-z-wen-jian-xi-tong-zfs/23.4.-zfs-guan-li.md) 以了解如何使用快照。

快照文件必须在执行操作的文件系统中创建，每个文件系统最多可创建 20 个快照。活动快照会记录在超级块中，因此它们在卸载和重新挂载操作以及系统重启后会保持持久性。当不再需要某个快照时，可使用 [rm(1)](https://man.freebsd.org/cgi/man.cgi?query=rm\&sektion=1\&format=html) 删除它。尽管可按任意顺序删除快照，但可能无法完全回收所有使用的空间，因为另一个快照可能会占用一些已释放的块。

不可更改的 `snapshot` 文件标志由 [mksnap\_ffs(8)](https://man.freebsd.org/cgi/man.cgi?query=mksnap_ffs\&sektion=8\&format=html) 在快照文件初始创建时设置。[unlink(1)](https://man.freebsd.org/cgi/man.cgi?query=unlink\&sektion=1\&format=html) 对快照文件做了例外处理，可删除它们。

快照是通过 [mount(8)](https://man.freebsd.org/cgi/man.cgi?query=mount\&sektion=8\&format=html) 创建的。要将 **/var** 的快照放入文件 **/var/snapshot/snap** 中，请使用以下命令：

```sh
# mount -u -o snapshot /var/snapshot/snap /var
```

或者，使用 [mksnap\_ffs(8)](https://man.freebsd.org/cgi/man.cgi?query=mksnap_ffs\&sektion=8\&format=html) 创建快照：

```sh
# mksnap_ffs /var /var/snapshot/snap
```

可使用 [find(1)](https://man.freebsd.org/cgi/man.cgi?query=find\&sektion=1\&format=html) 查找文件系统中的快照文件，例如 **/var**：

```sh
# find /var -flags snapshot
```

创建快照后，它有多个用途：

* 一些管理员会使用快照文件备份，因为快照可被传输到 CD 或磁带。
* 可在快照上运行文件系统完整性检查工具 [fsck(8)](https://man.freebsd.org/cgi/man.cgi?query=fsck\&sektion=8\&format=html)。假设文件系统在挂载时是干净的，这将始终提供干净且不变的结果。
* 在快照上运行 [dump(8)](https://man.freebsd.org/cgi/man.cgi?query=dump\&sektion=8\&format=html) 会生成与文件系统和快照时间戳一致的转储文件。`dump` 也可使用 `-L` 选项在一条命令中创建快照、生成转储镜像，然后删除快照。
* 快照可作为文件系统的冻结镜像挂载。要挂载快照 **/var/snapshot/snap**，可执行以下命令：

  ```sh
  # mdconfig -a -t vnode -o readonly -f /var/snapshot/snap -u 4
  # mount -r /dev/md4 /mnt
  ```

现在，冻结的 **/var** 可通过 **/mnt** 访问。一切最初都会保持快照创建时的状态。唯一的例外是，任何早期的快照将显示为零长度文件。要卸载快照，请执行：

```sh
# umount /mnt
# mdconfig -d -u 4
```

有关 `softupdates` 和文件系统快照的更多信息，包括技术论文，请访问 Marshall Kirk McKusick 的网站 <http://www.mckusick.com/>。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/handbook/di-21-zhang-cun-chu/21.10.-wen-jian-xi-tong-kuai-zhao.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
