dump 和 restore 命令
概述¶
dump
命令会检查文件系统中的文件,确定需要备份的文件,并将这些文件复制到指定的磁盘、磁带或其他存储介质。restore
命令执行与 dump
相反的功能。
此实用程序适用于以下文件系统
- ext2
- ext3
- ext4
技巧
对于 xfs 文件系统,请使用 xfsdump
。
此处是项目的首页。
在使用此实用程序之前,请运行以下命令进行安装
Shell > dnf -y install dump
安装完成后,可以使用两个常用的命令行工具
dump
restore
dump
命令¶
此命令主要有两个用途
- 执行备份 (dump) 操作 -
dump [选项] -f <文件名> <文件1> ...
- 查看备份 (dump) 信息 -
dump [-W | -w]
常用选项包括
-<level>
- 备份级别。使用时,请将“level”替换为 0-9 之间的任意数字。数字 0 代表完全备份,而其他数字代表增量备份。-f <文件名>
- 指定备份后的文件名和路径。-u
- 成功备份后,将备份时间记录在 /etc/dumpdates 文件中。当被备份对象是独立分区时,您可以使用-u
选项。但是,当备份对象是未分区目录时,您不能使用-u
选项。-v
- 在备份过程中显示处理详情。-W
- 用于查看 dump 信息的选项。-z[LEVEL]
- 使用 zlib 库调整压缩级别,默认压缩级别为 2。例如,您可以将备份文件压缩为.gz
格式。压缩级别的可调范围是 1-9。-j[LEVEL]
- 使用 bzlib 库调整压缩级别,默认压缩级别为 2。例如,您可以将备份文件压缩为.bz2
格式。压缩级别的可调范围是 1-9。
dump
使用示例¶
-
对根分区执行完全备份
Shell > dump -0u -j3 -f /tmp/root-20241208.bak.bz2 / DUMP: Date of this level 0 dump: Sun Dec 8 19:04:39 2024 DUMP: Dumping /dev/nvme0n1p2 (/) to /tmp/root-20241208.bak.bz2 DUMP: Label: none DUMP: Writing 10 Kilobyte records DUMP: Compressing output at transformation level 3 (bzlib) DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 14693111 blocks. DUMP: Volume 1 started with block 1 at: Sun Dec 8 19:04:41 2024 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: 20.69% done at 10133 kB/s, finished in 0:19 DUMP: 43.74% done at 10712 kB/s, finished in 0:12 DUMP: 70.91% done at 11575 kB/s, finished in 0:06 DUMP: 93.23% done at 11415 kB/s, finished in 0:01 DUMP: Closing /tmp/root-20241208.bak.bz2 DUMP: Volume 1 completed at: Sun Dec 8 19:26:08 2024 DUMP: Volume 1 took 0:21:27 DUMP: Volume 1 transfer rate: 5133 kB/s DUMP: Volume 1 14722930kB uncompressed, 6607183kB compressed, 2.229:1 DUMP: 14722930 blocks (14377.86MB) on 1 volume(s) DUMP: finished in 1287 seconds, throughput 11439 kBytes/sec DUMP: Date of this level 0 dump: Sun Dec 8 19:04:39 2024 DUMP: Date this dump completed: Sun Dec 8 19:26:08 2024 DUMP: Average transfer rate: 5133 kB/s DUMP: Wrote 14722930kB uncompressed, 6607183kB compressed, 2.229:1 DUMP: DUMP IS DONE Shell > ls -lh /tmp/root-20241208.bak.bz2 -rw-r--r-- 1 root root 6.4G Dec 8 19:26 /tmp/root-20241208.bak.bz2
-
成功 dump 后,检查相关信息
Shell > cat /etc/dumpdates /dev/nvme0n1p2 0 Sun Dec 8 19:04:39 2024 +0800 Shell > dump -W Last dump(s) done (Dump '>' file systems): /dev/nvme0n1p2 ( /) Last dump: Level 0, Date Sun Dec 8 19:04:39 2024
-
在完全备份的基础上实施增量备份
Shell > echo "jack" >> /tmp/tmpfile.txt Shell > dump -1u -j4 -f /tmp/root-20241208-LV1.bak.bz2 / DUMP: Date of this level 1 dump: Sun Dec 8 19:38:51 2024 DUMP: Date of last level 0 dump: Sun Dec 8 19:04:39 2024 DUMP: Dumping /dev/nvme0n1p2 (/) to /tmp/root-20241208-LV1.bak.bz2 DUMP: Label: none DUMP: Writing 10 Kilobyte records DUMP: Compressing output at transformation level 4 (bzlib) DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 6620898 blocks. DUMP: Volume 1 started with block 1 at: Sun Dec 8 19:38:58 2024 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: 38.13% done at 8415 kB/s, finished in 0:08 DUMP: 75.30% done at 8309 kB/s, finished in 0:03 DUMP: Closing /tmp/root-20241208-LV1.bak.bz2 DUMP: Volume 1 completed at: Sun Dec 8 19:52:03 2024 DUMP: Volume 1 took 0:13:05 DUMP: Volume 1 transfer rate: 8408 kB/s DUMP: Volume 1 6620910kB uncompressed, 6600592kB compressed, 1.004:1 DUMP: 6620910 blocks (6465.73MB) on 1 volume(s) DUMP: finished in 785 seconds, throughput 8434 kBytes/sec DUMP: Date of this level 1 dump: Sun Dec 8 19:38:51 2024 DUMP: Date this dump completed: Sun Dec 8 19:52:03 2024 DUMP: Average transfer rate: 8408 kB/s DUMP: Wrote 6620910kB uncompressed, 6600592kB compressed, 1.004:1 DUMP: DUMP IS DONE Shell > cat /etc/dumpdates /dev/nvme0n1p2 0 Sun Dec 8 19:04:39 2024 +0800 /dev/nvme0n1p2 1 Sun Dec 8 19:38:51 2024 +0800 Shell > dump -W Last dump(s) done (Dump '>' file systems): /dev/nvme0n1p2 ( /) Last dump: Level 1, Date Sun Dec 8 19:38:51 2024
-
对于未分区目录,您只能使用完全备份 (
-0
) 选项,而不能使用-u
选项Shell > dump -0uj -f /tmp/etc-full-20241208.bak.bz2 /etc/ DUMP: You can't update the dumpdates file when dumping a subdirectory DUMP: The ENTIRE dump is aborted. Shell > dump -0j -f /tmp/etc-full-20241208.bak.bz2 /etc/ DUMP: Date of this level 0 dump: Sun Dec 8 20:00:38 2024 DUMP: Dumping /dev/nvme0n1p2 (/ (dir etc)) to /tmp/etc-full-20241208.bak.bz2 DUMP: Label: none DUMP: Writing 10 Kilobyte records DUMP: Compressing output at transformation level 2 (bzlib) DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 28204 blocks. DUMP: Volume 1 started with block 1 at: Sun Dec 8 20:00:38 2024 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing /tmp/etc-full-20241208.bak.bz2 DUMP: Volume 1 completed at: Sun Dec 8 20:00:40 2024 DUMP: Volume 1 took 0:00:02 DUMP: Volume 1 transfer rate: 3751 kB/s DUMP: Volume 1 29090kB uncompressed, 7503kB compressed, 3.878:1 DUMP: 29090 blocks (28.41MB) on 1 volume(s) DUMP: finished in 2 seconds, throughput 14545 kBytes/sec DUMP: Date of this level 0 dump: Sun Dec 8 20:00:38 2024 DUMP: Date this dump completed: Sun Dec 8 20:00:40 2024 DUMP: Average transfer rate: 3751 kB/s DUMP: Wrote 29090kB uncompressed, 7503kB compressed, 3.878:1 DUMP: DUMP IS DONE
对 /etc/ 目录执行增量备份将导致错误
```bash
Shell > dump -1j -f /tmp/etc-incr-20241208.bak.bz2 /etc/
DUMP: Only level 0 dumps are allowed on a subdirectory
DUMP: The ENTIRE dump is aborted.
```
restore
命令¶
此命令的用法是 - restore <模式(标志)> [选项] -f <dump文件>
模式 (标志) 可以是以下之一
-C
- 比较模式。Restore 会读取备份并将其内容与磁盘上的文件进行比较。它主要用于在分区备份后进行比较。在此模式下,restore
只根据原始数据进行比较。如果磁盘上有新数据,您无法比较或检测到。-i
- 交互模式。此模式允许从 dump 中交互式恢复文件。-t
- 列表模式。列出备份文件中包含的数据。-r
- 恢复 (重建) 模式。如果采用“完全备份 + 增量备份”的方式,恢复数据将按时间顺序进行。-x
- 提取模式。从备份文件中提取部分或全部文件。
restore
使用示例¶
-
从 /tmp/etc-full-20241208.bak.bz2 恢复数据
Shell > mkdir /tmp/data/ Shell > restore -t -f /tmp/etc-full-20241208.bak.bz2 Shell > cd /tmp/data/ ; restore -r -f /tmp/etc-full-20241208.bak.bz2 Shell > ls -l /tmp/data/ total 4992 drwxr-xr-x. 90 root root 4096 Dec 8 17:13 etc -rw------- 1 root root 5107632 Dec 8 20:39 restoresymtable
您会注意到,成功恢复后会出现一个名为
restoresymtable
的文件。此文件很重要,它用于增量备份系统的恢复操作。 -
在交互模式下处理备份文件
Shell > restore -i -f /tmp/etc-full-20241208.bak.bz2 Dump tape is compressed. restore > ?
您可以输入 ? 来查看此模式下可用的交互命令。
作者:李天赐
贡献者:Steven Spencer