Linux系统之restore命令的基本使用
Linux系统之restore命令的基本使用
- 一、restore命令介绍
- 二、restore的使用帮助
- 2.1 查看帮助信息
- 2.2 基本语法
- 三、restore命令的基本使用
- 3.1 备份数据
- 3.2 恢复整个文件系统
- 3.3 查看备份文件内容
- 3.4 测试文件是否在备份中
- 3.5 比较备份文件和当前文件系统
- 四、注意事项
一、restore命令介绍
restore 命令是 dump 命令的配套工具,用于从 dump 创建的备份文件中恢复数据。下面是一些基本的使用方法和常用选项。
二、restore的使用帮助
2.1 查看帮助信息
命令行的help帮助信息
[root@openEuler-test ~]# dump --help
[root@openEuler-test ~]# restore --help
restore: invalid option -- '-'
restore 0.4b47 (using libext2fs 1.47.0 of 5-Feb-2023)
usage: restore -C [-cdeHlMvVy] [-b blocksize] [-D filesystem] [-E mls][-f file] [-F script] [-L limit] [-s fileno]restore -i [-acdehHlmMouvVy] [-A file] [-b blocksize] [-E mls][-f file] [-F script] [-Q file] [-s fileno]restore -P file [-acdhHlmMuvVy] [-b blocksize][-f file] [-F script] [-s fileno] [-X filelist] [file ...]restore -r [-cdeHlMuvVy] [-b blocksize] [-E mls][-f file] [-F script] [-s fileno] [-T directory]restore -R [-cdeHlMuvVy] [-b blocksize] [-E mls][-f file] [-F script] [-s fileno] [-T directory]restore -t [-cdhHlMuvVy] [-A file] [-b blocksize][-f file] [-F script] [-Q file] [-s fileno] [-X filelist] [file ...]restore -x [-acdehHlmMouvVy] [-A file] [-b blocksize] [-E mls][-f file] [-F script] [-Q file] [-s fileno] [-X filelist] [file ...]
2.2 基本语法
restore [选项] [备份文件]
restore
命令常用选项
选项 | 描述 |
---|---|
-C | 校验备份文件中的文件,但不实际恢复。 |
-c | 使用标准输入作为备份文件。 |
-d | 列出备份文件中的目录和文件。 |
-f <file> | 指定备份文件的位置,可以是本地文件、远程主机上的文件或设备。 |
-h <level> | 在恢复时忽略指定层级及更高层级的备份。 |
-i | 进入交互模式,允许用户选择要恢复的文件。 |
-r | 恢复整个文件系统,覆盖现有的文件。 |
-R | 恢复增量备份,需要结合 -L 选项使用。 |
-t <file> | 测试指定文件是否在备份中,但不实际恢复。 |
-T <file> | 恢复指定的文件或目录。 |
-v | 显示处理过程中的详细信息。 |
-x <file> | 提取指定的文件或目录。 |
-b <区块大小> | 设置区块大小,单位为 Byte。 |
-D <文件系统> | 允许用户指定文件系统的名称。 |
-m | 解开符合指定的 inode 编号的文件或目录而非用文件名称指定。 |
-s <文件编号> | 当备份数据超过一卷磁带时,用户可以指定备份文件的编号。 |
-y | 不询问任何问题,一律以同意回答并继续执行指令。 |
三、restore命令的基本使用
3.1 备份数据
测试在/home/test目录中,写入内容。
[root@openEuler-test ~]# mkdir -p /home/test
[root@openEuler-test ~]# echo test > /home/test/datest.txt
对 /home/test/目录进行完整备份,并将结果保存到/backup/datest.bak 文件中:
dump -0u -f /backup/datest.bak /home
3.2 恢复整个文件系统
删除测试文件:/home/test/datest.txt
rm -rf /home/test/datest.txt
创建恢复目录/data/restore
mkdir -p /data/restore && cd /data/restore
从备份文件
/backup/datest.bak 文件中
中恢复整个/home/test/目录内容:
restore -rf /backup/datest.bak
查看测试文件是否已经恢复,可以看到已经正常恢复数据。
[root@openEuler-test restore]# restore -rf /backup/datest.bak
[root@openEuler-test restore]# ll
total 53392
drwx------. 2 admin admin 4096 Sep 28 15:55 admin
drwx------. 2 root root 4096 Jun 27 15:47 lost+found
-rw------- 1 root root 54657872 Nov 12 14:50 restoresymtable
drwxr-xr-x 2 root root 4096 Nov 12 14:47 test
[root@openEuler-test restore]# cat test/datest.txt
test
3.3 查看备份文件内容
- 查看备份文件内容:
[root@openEuler-test restore]# restore -tf /backup/datest.bak
Dump date: Tue Nov 12 14:47:26 2024
Dumped from: the epoch
Level 0 dump of /home on openEuler-test:/dev/mapper/openeuler-home
Label: none2 .11 ./lost+found12320769 ./admin12320770 ./admin/.bash_profile12320771 ./admin/.bash_logout12320772 ./admin/.bashrc12320773 ./admin/.bash_history14155777 ./test14155778 ./test/datest.txt12 ./restoresymtable
3.4 测试文件是否在备份中
测试文件datest.txt是否在备份文件中:
[root@openEuler-test restore]# restore -tf /backup/datest.bak ./test/datest.txt
Dump date: Tue Nov 12 14:47:26 2024
Dumped from: the epoch
Level 0 dump of /home on openEuler-test:/dev/mapper/openeuler-home
Label: none14155778 ./test/datest.txt
3.5 比较备份文件和当前文件系统
向原目录中,向测试文件datest.txt写入不同内容:
[root@openEuler-test restore]# cp -a ./test/datest.txt /home/test/
[root@openEuler-test restore]# echo hello >> /home/test/datest.txt
[root@openEuler-test restore]#
用于将备份文件中的内容与当前文件系统中的内容进行比较。它可以帮助你检查备份数据和实际数据是否一致。
[root@openEuler-test restore]# restore -C -f /backup/datest.bak
Dump date: Tue Nov 12 14:47:26 2024
Dumped from: the epoch
Level 0 dump of /home on openEuler-test:/dev/mapper/openeuler-home
Label: none
filesys = /home
./test/datest.txt: size has changed.
Some files were modified! 1 compare errors
四、注意事项
- 确保备份文件的完整性:在恢复数据前,确保备份文件没有损坏,可以使用
restore -C
命令进行校验。 - 使用超级用户权限:恢复操作通常需要超级用户权限,使用
sudo
或以root
用户身份运行。 - 指定正确的备份文件路径:确保指定的备份文件路径正确无误,特别是在远程主机上恢复时。
- 备份文件的层级:在恢复增量备份时,确保按照正确的层级顺序进行恢复。
- 目标文件系统状态:在恢复数据前,确保目标文件系统没有正在进行的写操作,以避免数据不一致。
- 交互模式谨慎选择:使用交互模式 (
-i
) 时,仔细选择要恢复的文件,避免恢复不必要的文件。 - 详细信息输出:使用
-v
选项显示详细信息,以便监控恢复过程和排查问题。 - 定期测试恢复过程:定期测试恢复过程,确保备份文件能够在需要时成功恢复。
- 保护备份文件:将备份文件存储在安全的地方,防止未经授权的访问或损坏。
- 备份文件的更新:定期更新备份文件,确保备份数据是最新的。