- 学习视频来自于B站【小白入门 通俗易懂】2021韩顺平 一周学会Linux。
- 可能会用到的资料有如下所示,下载链接见文末:
- 《鸟哥的Linux私房菜 基础学习篇 第四版》1
- 《鸟哥的Linux私房菜 服务器架设篇 第三版》2
- 《韩顺平_2021图解Linux全面升级》3
在学习Linux的过程中,我们一直用VMware新建虚拟机来进行开发,并且即使有rm -rf /*
之类的骚操作也可以使用“快照”来进行恢复。但在工作环境下,实体机无法做快照,如果出现严重的异常或者数据损坏,甚至要重做系统,就会造成数据丢失,所以我们就需要“备份和恢复”。linux的备份和恢复很简单,有两种方式:
- 把需要的文件(或者分区)用
tar
指令打包,下次需要恢复的时候,再解压开覆盖即可。- 使用
dump
和restore
命令——dump
指令备份、restore
指令还原。注:备份的重要数据时应上传到其他服务器,不要将所有数据都放在一台机器上。
注:dump
指令配合crontab
定时调度指令显然可以实现无人值守备份。
上图展示了在Linux备份与恢复中一个非常重要的概念——“备份层级”。以备份/boot分区为例,在当第一次备份时,显然需要将/boot分区完整的备份一遍(备份层级0);但日常一般不会对整个/boot分区进行大的删改,但可能会设计到某些文件的删改,此时为了不重新完整的备份一遍浪费资源,便可以只对上次备份过后新增的删改进行备份(备份层级1)。也就是说,除了备份层级0是完整备份,剩下的备份层级都是在上一级备份的基础上,进行“增量备份”。注意两个要点:
- 备份层级只有0~9。到达备份层级9之后会回退到备份层级0重新开始。
- “备份层级”的概念只存在于“分区”的备份,对于普通文件/目录只有“备份层级0”。
Linux下使用dump
进行备份,使用restore
指令进行还原。下面展示如何安装dump
和restore
:
################## 指令速览 #####################
yum -y install dump # 安装dump
yum -y install restore # 安装restore
################## 实际演示 #####################
# 1. 安装dump
[root@CentOS76 ~]# yum -y install dump
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 dump.x86_64.1.0.4-0.23.b44.el7 将被 安装
--> 正在处理依赖关系 rmt,它被软件包 1:dump-0.4-0.23.b44.el7.x86_64 需要
--> 正在检查事务
---> 软件包 rmt.x86_64.2.1.5.2-13.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================
Package 架构 版本 源 大小
=======================================================================================================
正在安装:
dump x86_64 1:0.4-0.23.b44.el7 base 148 k
为依赖而安装:
rmt x86_64 2:1.5.2-13.el7 base 103 k
事务概要
=======================================================================================================
安装 1 软件包 (+1 依赖软件包)
总下载量:251 k
安装大小:581 k
Downloading packages:
(1/2): dump-0.4-0.23.b44.el7.x86_64.rpm | 148 kB 00:00:00
(2/2): rmt-1.5.2-13.el7.x86_64.rpm | 103 kB 00:00:00
-------------------------------------------------------------------------------------------------------
总计 611 kB/s | 251 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 2:rmt-1.5.2-13.el7.x86_64 1/2
正在安装 : 1:dump-0.4-0.23.b44.el7.x86_64 2/2
验证中 : 2:rmt-1.5.2-13.el7.x86_64 1/2
验证中 : 1:dump-0.4-0.23.b44.el7.x86_64 2/2
已安装:
dump.x86_64 1:0.4-0.23.b44.el7
作为依赖被安装:
rmt.x86_64 2:1.5.2-13.el7
完毕!
# 2. 安装restore
[root@CentOS76 ~]# yum -y install restore
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
没有可用软件包 restore。
错误:无须任何处理
# 注意上述报错,可能是因为安装dump时顺便安装上了restore
# 3. 检验dump和restore是否安装上
[root@CentOS76 ~]# dump
dump 0.4b44 (using libext2fs 1.42.9 of 28-Dec-2013)
usage: dump [-level#] [-acmMnqSuv] [-A file] [-B records] [-b blocksize]
[-d density] [-D file] [-e inode#,inode#,...] [-E file]
[-f file] [-h level] [-I nr errors] [-j zlevel] [-Q file]
[-s feet] [-T date] [-y] [-z zlevel] filesystem
dump [-W | -w]
[root@CentOS76 ~]# restore
restore 0.4b44 (using libext2fs 1.42.9 of 28-Dec-2013)
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 ...]
dump
为备份工具程序,可将目录或整个文件系统备份至指定的设备,同时支持对整个分区进行增量备份。所谓“增量备份”是指只备份上次备份后 新修改/增加 过的文件,而无需再重新进行完整的备份,也称差异备份。注意上述仅对分区进行备份时支持“增量备份”,普通文件或目录只能使用0级别备份。下面是dump
的基本语法:
# 基本语法-dump
dump [选项参数] [目录或文件系统]
dump [-wW]
# 常用选项-dump
-0123456789 备份的层级。0为最完整备份,会备份所有文件。若指定0以上的层级,则备份至上一次备份以来修改或新增的文件,到9后可以再次从0开始。
-u 备份完毕后,在/etc/dumpdares中记录备份的文件系统、层级、日期、时间等。
-j 调用bzlib库压缩备份文件,也就是将备份后的文件压缩成bz2格式,让文件更小。
-f<备份后文件名> 指定备份后文件名。
-T<日期> 指定开始备份的时间与日期。
-c 修改备份磁带预设的密度与容量。
-t 指定文件名,若该文件已存在备份文件中,则列出名称。
-W 显示需要备份的文件及其最后一次备份的层级、时间、日期。
-w 与-W类似,但仅显示需要备份的文件。
# 常用指令-dump
dump -W # 显示需要备份的文件及其最后一次备份的层级、时间、日期
cat /etc/dumpdates # 查看备份时间、文件、次数
下面展示四个dump
应用案例:
【案例1】将/boot
分区所有内容备份到/opt/boot.bak0.bz2
文件中,备份层级为“0”。
################## 指令速览 #####################
dump -0uj -f /opt/boot.bak0.bz2 /boot
################## 实际演示 #####################
[root@CentOS76 ~]# cd /opt
[root@CentOS76 opt]# dump -0uj -f /opt/boot.bak0.bz2 /boot
DUMP: Date of this level 0 dump: Fri Aug 25 16:20:28 2023
DUMP: Dumping /dev/sda1 (/boot) to /opt/boot.bak0.bz2
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: Compressing output at compression level 2 (bzlib)
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 179588 blocks.
DUMP: Volume 1 started with block 1 at: Fri Aug 25 16:20:28 2023
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /opt/boot.bak0.bz2
DUMP: Volume 1 completed at: Fri Aug 25 16:20:41 2023
DUMP: Volume 1 took 0:00:13
DUMP: Volume 1 transfer rate: 12457 kB/s
DUMP: Volume 1 180210kB uncompressed, 161941kB compressed, 1.113:1
DUMP: 180210 blocks (175.99MB) on 1 volume(s)
DUMP: finished in 13 seconds, throughput 13862 kBytes/sec
DUMP: Date of this level 0 dump: Fri Aug 25 16:20:28 2023
DUMP: Date this dump completed: Fri Aug 25 16:20:41 2023
DUMP: Average transfer rate: 12457 kB/s
DUMP: Wrote 180210kB uncompressed, 161941kB compressed, 1.113:1
DUMP: DUMP IS DONE
[root@CentOS76 opt]# ll -h
总用量 305M
-rw-r--r--. 1 root root 159M 8月 25 16:20 boot.bak0.bz2
# 其他的文件就不显示了,注意备份文件大小为159M
【案例2】在/boot
目录下新建一个hello.txt
,然后将/boot
分区增量备份到/opt/boot.bak1.bz2
文件中(备份层级1)。
此例可发现:
- 备份层级0文件
boot.bak0.bz2
大小:159M。- 备份层级1文件
boot.bak1.bz2
大小:12K。
################## 指令速览 #####################
dump -1uj -f /opt/boot.bak1.bz2 /boot
################## 实际演示 #####################
[root@CentOS76 opt]# cd /boot
[root@CentOS76 boot]# touch hello.txt
[root@CentOS76 boot]# ll -h
总用量 159M
-rw-r--r--. 1 root root 0 8月 25 16:23 hello.txt
# /boot目录下其他的就不显示了
[root@CentOS76 boot]# dump -1uj -f /opt/boot.bak1.bz2 /boot
DUMP: Date of this level 1 dump: Fri Aug 25 16:24:20 2023
DUMP: Date of last level 0 dump: Fri Aug 25 16:20:28 2023
DUMP: Dumping /dev/sda1 (/boot) to /opt/boot.bak1.bz2
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: Compressing output at compression level 2 (bzlib)
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 35 blocks.
DUMP: Volume 1 started with block 1 at: Fri Aug 25 16:24:20 2023
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /opt/boot.bak1.bz2
DUMP: Volume 1 completed at: Fri Aug 25 16:24:20 2023
DUMP: 30 blocks (0.03MB) on 1 volume(s)
DUMP: finished in less than a second
DUMP: Date of this level 1 dump: Fri Aug 25 16:24:20 2023
DUMP: Date this dump completed: Fri Aug 25 16:24:20 2023
DUMP: Average transfer rate: 0 kB/s
DUMP: Wrote 30kB uncompressed, 11kB compressed, 2.728:1
DUMP: DUMP IS DONE
[root@CentOS76 boot]# ll -h /opt
总用量 305M
-rw-r--r--. 1 root root 159M 8月 25 16:20 boot.bak0.bz2
-rw-r--r--. 1 root root 12K 8月 25 16:24 boot.bak1.bz2
# /opt目录下其他的文档就不显示了
【案例3】查看使用dump
备份的文件及其最后一次备份的层级、时间、日期。
################## 指令速览 #####################
dump -W
cat /etc/dumpdates
################## 实际演示 #####################
[root@CentOS76 boot]# dump -W
Last dump(s) done (Dump '>' file systems):
> /dev/sda3 ( /) Last dump: never
/dev/sda1 ( /boot) Last dump: Level 1, Date Fri Aug 25 16:24:20 2023
[root@CentOS76 boot]# cat /etc/dumpdates
/dev/sda1 0 Fri Aug 25 16:20:28 2023 +0800
/dev/sda1 1 Fri Aug 25 16:24:20 2023 +0800
【案例4】使用dump
备份/etc
整个目录。
- 注意“实际演示”还演示了普通文件不支持备份层级1、不支持选项
-u
。
################## 指令速览 #####################
dump -0j -f /opt/etc.bak.bz2 /etc/
# 下面一行指令报错!提示子目录只能使用备份层级0!
# dump -1j -f /opt/etc.bak.bz2 /etc/
################## 实际演示 #####################
# 1. 演示dump使用“备份层级0”备份普通目录/etc
[root@CentOS76 boot]# dump -0j -f /opt/etc.bak0.bz2 /etc/
DUMP: Date of this level 0 dump: Fri Aug 25 16:33:29 2023
DUMP: Dumping /dev/sda3 (/ (dir etc)) to /opt/etc.bak0.bz2
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: Compressing output at compression level 2 (bzlib)
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 68703 blocks.
DUMP: Volume 1 started with block 1 at: Fri Aug 25 16:33:30 2023
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /opt/etc.bak0.bz2
DUMP: Volume 1 completed at: Fri Aug 25 16:33:33 2023
DUMP: Volume 1 took 0:00:03
DUMP: Volume 1 transfer rate: 8208 kB/s
DUMP: Volume 1 78350kB uncompressed, 24626kB compressed, 3.182:1
DUMP: 78350 blocks (76.51MB) on 1 volume(s)
DUMP: finished in 3 seconds, throughput 26116 kBytes/sec
DUMP: Date of this level 0 dump: Fri Aug 25 16:33:29 2023
DUMP: Date this dump completed: Fri Aug 25 16:33:33 2023
DUMP: Average transfer rate: 8208 kB/s
DUMP: Wrote 78350kB uncompressed, 24626kB compressed, 3.182:1
DUMP: DUMP IS DONE
[root@CentOS76 boot]# ll -h /opt
总用量 353M
-rw-r--r--. 1 root root 159M 8月 25 16:20 boot.bak0.bz2
-rw-r--r--. 1 root root 12K 8月 25 16:24 boot.bak1.bz2
-rw-r--r--. 1 root root 25M 8月 25 16:33 etc.bak0.bz2
# /opt目录下其他的文档就不显示了
# 2. 演示dump不支持使用“备份层级1”备份普通目录/etc
[root@CentOS76 boot]# dump -1j -f /opt/etc.bak1.bz2 /etc/
DUMP: Only level 0 dumps are allowed on a subdirectory
DUMP: The ENTIRE dump is aborted.
# 3. 演示dump不支持使用“选项-u”备份普通目录/etc
[root@CentOS76 boot]# dump -0uj -f /opt/etc.bak0.bz2 /etc/
DUMP: You can't update the dumpdates file when dumping a subdirectory
DUMP: The ENTIRE dump is aborted.
上一节讲了如何使用dump
指令进行备份,本节就来介绍如何使用restore
指令将备份的文件恢复到指令目录中。只需要注意,若有多个备份层级,从备份层级0开始依次恢复即可。下面是restore
指令的基本语法:
# 基本语法-restore
restore [模式选项] [选项]
# 模式选项-restore
# 说明:下面四个模式不能混用!一次命令中只能指定一种。
-C 对比模式。将备份的文件与已存在的文件相互对比。
-i 交互模式。在进行还原操作时,restore指令将依序询问用户。
-r 还原模式【使用最多】。有多个备份层级时,从0开始依次还原即可。
-t 查看模式。看备份文件有哪些文件。
# 常用选项-restore
-f<备份设备> 从指定的文件中读取备份数据,进行还原操作
# 常用指令-restore
restore -r -f<备份好的文件>
下面展示四个restore
指令的应用案例:
【案例1】将/boot/hello.txt
文件重命名为hello1.txt
,然后使用restore
指令的“对比模式”,比较备份文件/opt/boot.bak1.bz2
和原目录/boot
的区别。
################## 指令速览 #####################
mv /boot/hello.txt /boot/hello1.txt # 重命名/boot/hello.txt
restore -C -f boot.bak1.bz2 # 注意和最新的文件比较
################## 实际演示 #####################
# 1. 将文件重命名
[root@CentOS76 boot]# ll -h
总用量 159M
-rw-r--r--. 1 root root 0 8月 25 16:23 hello.txt
# /opt目录下其他的文档就不显示了
[root@CentOS76 boot]# mv /boot/hello.txt /boot/hello1.txt
[root@CentOS76 boot]# ll -h
总用量 159M
-rw-r--r--. 1 root root 0 8月 25 16:23 hello1.txt
# /opt目录下其他的文档就不显示了
# 2. 使用“对比模式”查看当前目录与备份文件的区别
[root@CentOS76 boot]# restore -C -f /opt/boot.bak1.bz2
Dump tape is compressed.
Dump date: Fri Aug 25 16:24:20 2023
Dumped from: Fri Aug 25 16:20:28 2023
Level 1 dump of /boot on CentOS76:/dev/sda1
Label: none
filesys = /boot
restore: unable to stat ./hello.txt: No such file or directory
Some files were modified! 1 compare errors
# 注意上述有1个compare errors。
# 3. 再将/boot/hello1.txt文件名改回去,重新使用“对比模式”查看
[root@CentOS76 boot]# mv /boot/hello1.txt /boot/hello.txt
[root@CentOS76 boot]# restore -C -f /opt/boot.bak1.bz2
Dump tape is compressed.
Dump date: Fri Aug 25 16:24:20 2023
Dumped from: Fri Aug 25 16:20:28 2023
Level 1 dump of /boot on CentOS76:/dev/sda1
Label: none
filesys = /boot
【案例2】使用restore
指令的“查看模式”,看备份文件/opt/boot.bak0.bz2
有哪些数据/文件。
################## 指令速览 #####################
restore -t -f /opt/boot.bak0.bz2
################## 实际演示 #####################
# 1. 看看备份层级1中的文件都记录了啥
[root@CentOS76 boot]# restore -t -f /opt/boot.bak1.bz2
Dump tape is compressed.
Dump date: Fri Aug 25 16:24:20 2023
Dumped from: Fri Aug 25 16:20:28 2023
Level 1 dump of /boot on CentOS76:/dev/sda1
Label: none
2 .
346 ./hello.txt
# 2. 看看备份层级0的文件中都记录了啥
[root@CentOS76 boot]# restore -t -f /opt/boot.bak0.bz2
Dump tape is compressed.
Dump date: Fri Aug 25 16:20:28 2023
Dumped from: the epoch
Level 0 dump of /boot on CentOS76:/dev/sda1
Label: none
2 .
11 ./lost+found
12 ./efi
13 ./efi/EFI
14 ./efi/EFI/centos
22 ./efi/EFI/centos/MokManager.efi
20 ./efi/EFI/centos/BOOT.CSV
21 ./efi/EFI/centos/BOOTX64.CSV
25 ./efi/EFI/centos/shimx64-centos.efi
23 ./efi/EFI/centos/mmx64.efi
24 ./efi/EFI/centos/shim.efi
27 ./efi/EFI/centos/fw
26 ./efi/EFI/centos/shimx64.efi
28 ./efi/EFI/centos/fwupia32.efi
29 ./efi/EFI/centos/fwupx64.efi
16 ./efi/EFI/BOOT
18 ./efi/EFI/BOOT/fallback.efi
17 ./efi/EFI/BOOT/BOOTX64.EFI
19 ./efi/EFI/BOOT/fbx64.efi
8193 ./grub2
38 ./grub2/device.map
39 ./grub2/i386-pc
41 ./grub2/i386-pc/usbtest.mod
43 ./grub2/i386-pc/nativedisk.mod
45 ./grub2/i386-pc/ldm.mod
46 ./grub2/i386-pc/crypto.mod
48 ./grub2/i386-pc/part_acorn.mod
49 ./grub2/i386-pc/spkmodem.mod
52 ./grub2/i386-pc/gcry_dsa.mod
54 ./grub2/i386-pc/hashsum.mod
56 ./grub2/i386-pc/gcry_md5.mod
57 ./grub2/i386-pc/testspeed.mod
58 ./grub2/i386-pc/gcry_serpent.mod
59 ./grub2/i386-pc/keylayouts.mod
60 ./grub2/i386-pc/bitmap_scale.mod
64 ./grub2/i386-pc/file.mod
67 ./grub2/i386-pc/sfs.mod
68 ./grub2/i386-pc/at_keyboard.mod
69 ./grub2/i386-pc/aout.mod
70 ./grub2/i386-pc/mda_text.mod
71 ./grub2/i386-pc/minix2_be.mod
72 ./grub2/i386-pc/gfxterm.mod
75 ./grub2/i386-pc/halt.mod
78 ./grub2/i386-pc/mmap.mod
79 ./grub2/i386-pc/squash4.mod
81 ./grub2/i386-pc/minix2.mod
83 ./grub2/i386-pc/syslinuxcfg.mod
84 ./grub2/i386-pc/regexp.mod
85 ./grub2/i386-pc/ls.mod
86 ./grub2/i386-pc/bufio.mod
88 ./grub2/i386-pc/romfs.mod
89 ./grub2/i386-pc/exfctest.mod
91 ./grub2/i386-pc/ufs1_be.mod
92 ./grub2/i386-pc/odc.mod
93 ./grub2/i386-pc/gdb.mod
95 ./grub2/i386-pc/priority_queue.mod
98 ./grub2/i386-pc/part_dvh.mod
101 ./grub2/i386-pc/sendkey.mod
102 ./grub2/i386-pc/cmdline_cat_test.mod
106 ./grub2/i386-pc/sleep_test.mod
110 ./grub2/i386-pc/test.mod
113 ./grub2/i386-pc/dm_nv.mod
114 ./grub2/i386-pc/usbserial_common.mod
115 ./grub2/i386-pc/jpeg.mod
120 ./grub2/i386-pc/vga_text.mod
124 ./grub2/i386-pc/test_blockarg.mod
128 ./grub2/i386-pc/echo.mod
130 ./grub2/i386-pc/part_apple.mod
131 ./grub2/i386-pc/gcry_des.mod
133 ./grub2/i386-pc/gcry_md4.mod
134 ./grub2/i386-pc/boot.mod
137 ./grub2/i386-pc/parttool.mod
138 ./grub2/i386-pc/zfs.mod
140 ./grub2/i386-pc/part_sunpc.mod
141 ./grub2/i386-pc/geli.mod
142 ./grub2/i386-pc/http.mod
143 ./grub2/i386-pc/efiemu.mod
145 ./grub2/i386-pc/terminal.mod
147 ./grub2/i386-pc/pxechain.mod
148 ./grub2/i386-pc/datetime.mod
154 ./grub2/i386-pc/ext2.mod
155 ./grub2/i386-pc/affs.mod
159 ./grub2/i386-pc/linux16.mod
160 ./grub2/i386-pc/hexdump.mod
163 ./grub2/i386-pc/lzopio.mod
164 ./grub2/i386-pc/biosdisk.mod
165 ./grub2/i386-pc/gzio.mod
167 ./grub2/i386-pc/cpio_be.mod
168 ./grub2/i386-pc/testload.mod
169 ./grub2/i386-pc/multiboot2.mod
175 ./grub2/i386-pc/verify.mod
178 ./grub2/i386-pc/ntfs.mod
181 ./grub2/i386-pc/help.mod
183 ./grub2/i386-pc/gcry_rmd160.mod
184 ./grub2/i386-pc/backtrace.mod
186 ./grub2/i386-pc/password_pbkdf2.mod
188 ./grub2/i386-pc/gcry_rijndael.mod
189 ./grub2/i386-pc/udf.mod
190 ./grub2/i386-pc/usbserial_pl2303.mod
191 ./grub2/i386-pc/legacy_password_test.mod
192 ./grub2/i386-pc/lsacpi.mod
199 ./grub2/i386-pc/mdraid09_be.mod
201 ./grub2/i386-pc/fshelp.mod
202 ./grub2/i386-pc/search_fs_file.mod
203 ./grub2/i386-pc/minix3.mod
204 ./grub2/i386-pc/gcry_sha1.mod
205 ./grub2/i386-pc/png.mod
206 ./grub2/i386-pc/fat.mod
209 ./grub2/i386-pc/relocator.mod
212 ./grub2/i386-pc/ufs2.mod
213 ./grub2/i386-pc/bitmap.mod
214 ./grub2/i386-pc/minix.mod
216 ./grub2/i386-pc/memrw.mod
220 ./grub2/i386-pc/reboot.mod
223 ./grub2/i386-pc/macbless.mod
224 ./grub2/i386-pc/macho.mod
226 ./grub2/i386-pc/cmosdump.mod
227 ./grub2/i386-pc/cbls.mod
230 ./grub2/i386-pc/gcry_crc.mod
231 ./grub2/i386-pc/gcry_camellia.mod
234 ./grub2/i386-pc/usbms.mod
237 ./grub2/i386-pc/gcry_cast5.mod
240 ./grub2/i386-pc/minicmd.mod
241 ./grub2/i386-pc/gcry_tiger.mod
242 ./grub2/i386-pc/cbmemc.mod
243 ./grub2/i386-pc/uhci.mod
245 ./grub2/i386-pc/gcry_rfc2268.mod
246 ./grub2/i386-pc/pcidump.mod
248 ./grub2/i386-pc/gcry_sha512.mod
252 ./grub2/i386-pc/pci.mod
255 ./grub2/i386-pc/xfs.mod
262 ./grub2/i386-pc/ntfscomp.mod
263 ./grub2/i386-pc/raid5rec.mod
268 ./grub2/i386-pc/xnu_uuid.mod
269 ./grub2/i386-pc/exfat.mod
271 ./grub2/i386-pc/usbserial_usbdebug.mod
272 ./grub2/i386-pc/setpci.mod
273 ./grub2/i386-pc/reiserfs.mod
276 ./grub2/i386-pc/hfs.mod
278 ./grub2/i386-pc/minix3_be.mod
279 ./grub2/i386-pc/ufs1.mod
281 ./grub2/i386-pc/bfs.mod
283 ./grub2/i386-pc/eval.mod
284 ./grub2/i386-pc/tga.mod
285 ./grub2/i386-pc/mdraid1x.mod
286 ./grub2/i386-pc/gcry_rsa.mod
288 ./grub2/i386-pc/ata.mod
289 ./grub2/i386-pc/archelp.mod
292 ./grub2/i386-pc/gcry_sha256.mod
295 ./grub2/i386-pc/blocklist.mod
296 ./grub2/i386-pc/cpuid.mod
297 ./grub2/i386-pc/part_plan.mod
298 ./grub2/i386-pc/moddep.lst
299 ./grub2/i386-pc/command.lst
305 ./grub2/i386-pc/terminal.lst
345 ./grub2/i386-pc/boot.img
177 ./grub2/i386-pc/font.mod
236 ./grub2/i386-pc/video_bochs.mod
123 ./grub2/i386-pc/cryptodisk.mod
144 ./grub2/i386-pc/drivemap.mod
87 ./grub2/i386-pc/gcry_whirlpool.mod
119 ./grub2/i386-pc/part_amiga.mod
235 ./grub2/i386-pc/ntldr.mod
74 ./grub2/i386-pc/part_bsd.mod
44 ./grub2/i386-pc/diskfilter.mod
139 ./grub2/i386-pc/video_colors.mod
76 ./grub2/i386-pc/morse.mod
97 ./grub2/i386-pc/vga.mod
62 ./grub2/i386-pc/functional_test.mod
170 ./grub2/i386-pc/elf.mod
158 ./grub2/i386-pc/ohci.mod
80 ./grub2/i386-pc/setjmp.mod
116 ./grub2/i386-pc/configfile.mod
135 ./grub2/i386-pc/msdospart.mod
211 ./grub2/i386-pc/all_video.mod
210 ./grub2/i386-pc/afs.mod
182 ./grub2/i386-pc/signature_test.mod
77 ./grub2/i386-pc/cs5536.mod
180 ./grub2/i386-pc/minix_be.mod
229 ./grub2/i386-pc/progress.mod
174 ./grub2/i386-pc/sleep.mod
225 ./grub2/i386-pc/memdisk.mod
215 ./grub2/i386-pc/bsd.mod
176 ./grub2/i386-pc/play.mod
108 ./grub2/i386-pc/gcry_blowfish.mod
198 ./grub2/i386-pc/gfxterm_background.mod
94 ./grub2/i386-pc/lspci.mod
132 ./grub2/i386-pc/disk.mod
111 ./grub2/i386-pc/plan9.mod
104 ./grub2/i386-pc/xnu.mod
129 ./grub2/i386-pc/btrfs.mod
66 ./grub2/i386-pc/videoinfo.mod
53 ./grub2/i386-pc/gcry_twofish.mod
200 ./grub2/i386-pc/probe.mod
166 ./grub2/i386-pc/usb.mod
103 ./grub2/i386-pc/chain.mod
125 ./grub2/i386-pc/hfspluscomp.mod
118 ./grub2/i386-pc/extcmd.mod
63 ./grub2/i386-pc/iso9660.mod
193 ./grub2/i386-pc/mpi.mod
51 ./grub2/i386-pc/lsmmap.mod
50 ./grub2/i386-pc/videotest.mod
47 ./grub2/i386-pc/keystatus.mod
196 ./grub2/i386-pc/iorw.mod
73 ./grub2/i386-pc/lvm.mod
105 ./grub2/i386-pc/truecrypt.mod
121 ./grub2/i386-pc/gcry_idea.mod
218 ./grub2/i386-pc/trig.mod
122 ./grub2/i386-pc/tftp.mod
208 ./grub2/i386-pc/procfs.mod
99 ./grub2/i386-pc/part_gpt.mod
232 ./grub2/i386-pc/loadenv.mod
156 ./grub2/i386-pc/videotest_checksum.mod
61 ./grub2/i386-pc/hdparm.mod
197 ./grub2/i386-pc/net.mod
221 ./grub2/i386-pc/search_label.mod
151 ./grub2/i386-pc/raid6rec.mod
161 ./grub2/i386-pc/jfs.mod
100 ./grub2/i386-pc/tr.mod
194 ./grub2/i386-pc/cbtable.mod
42 ./grub2/i386-pc/video.mod
195 ./grub2/i386-pc/usbserial_ftdi.mod
187 ./grub2/i386-pc/cmostest.mod
146 ./grub2/i386-pc/datehook.mod
152 ./grub2/i386-pc/scsi.mod
65 ./grub2/i386-pc/usb_keyboard.mod
153 ./grub2/i386-pc/xnu_uuid_test.mod
173 ./grub2/i386-pc/video_fb.mod
233 ./grub2/i386-pc/pata.mod
228 ./grub2/i386-pc/date.mod
127 ./grub2/i386-pc/password.mod
162 ./grub2/i386-pc/setjmp_test.mod
55 ./grub2/i386-pc/hfsplus.mod
172 ./grub2/i386-pc/gcry_seed.mod
82 ./grub2/i386-pc/multiboot.mod
219 ./grub2/i386-pc/time.mod
136 ./grub2/i386-pc/serial.mod
109 ./grub2/i386-pc/freedos.mod
185 ./grub2/i386-pc/cpio.mod
238 ./grub2/i386-pc/tar.mod
217 ./grub2/i386-pc/div_test.mod
179 ./grub2/i386-pc/part_msdos.mod
171 ./grub2/i386-pc/ahci.mod
157 ./grub2/i386-pc/search_fs_uuid.mod
126 ./grub2/i386-pc/search.mod
107 ./grub2/i386-pc/cmp.mod
150 ./grub2/i386-pc/cbfs.mod
207 ./grub2/i386-pc/mdraid09.mod
90 ./grub2/i386-pc/gptsync.mod
149 ./grub2/i386-pc/blscfg.mod
222 ./grub2/i386-pc/lsapm.mod
112 ./grub2/i386-pc/acpi.mod
117 ./grub2/i386-pc/linux.mod
96 ./grub2/i386-pc/ehci.mod
239 ./grub2/i386-pc/pbkdf2.mod
244 ./grub2/i386-pc/xzio.mod
247 ./grub2/i386-pc/pxe.mod
249 ./grub2/i386-pc/nilfs2.mod
250 ./grub2/i386-pc/read.mod
251 ./grub2/i386-pc/loopback.mod
253 ./grub2/i386-pc/adler32.mod
254 ./grub2/i386-pc/zfscrypt.mod
256 ./grub2/i386-pc/gcry_arcfour.mod
257 ./grub2/i386-pc/part_dfly.mod
258 ./grub2/i386-pc/gfxmenu.mod
259 ./grub2/i386-pc/true.mod
260 ./grub2/i386-pc/crc64.mod
261 ./grub2/i386-pc/cat.mod
264 ./grub2/i386-pc/pbkdf2_test.mod
265 ./grub2/i386-pc/hello.mod
266 ./grub2/i386-pc/vbe.mod
267 ./grub2/i386-pc/gettext.mod
270 ./grub2/i386-pc/cbtime.mod
274 ./grub2/i386-pc/luks.mod
275 ./grub2/i386-pc/gfxterm_menu.mod
277 ./grub2/i386-pc/normal.mod
280 ./grub2/i386-pc/legacycfg.mod
282 ./grub2/i386-pc/offsetio.mod
287 ./grub2/i386-pc/newc.mod
290 ./grub2/i386-pc/part_sun.mod
291 ./grub2/i386-pc/zfsinfo.mod
293 ./grub2/i386-pc/terminfo.mod
294 ./grub2/i386-pc/video_cirrus.mod
300 ./grub2/i386-pc/fs.lst
301 ./grub2/i386-pc/partmap.lst
302 ./grub2/i386-pc/parttool.lst
303 ./grub2/i386-pc/video.lst
304 ./grub2/i386-pc/crypto.lst
306 ./grub2/i386-pc/modinfo.sh
344 ./grub2/i386-pc/core.img
40 ./grub2/locale
307 ./grub2/locale/[email protected]
308 ./grub2/locale/da.mo
309 ./grub2/locale/fr.mo
310 ./grub2/locale/gl.mo
311 ./grub2/locale/id.mo
312 ./grub2/locale/[email protected]
313 ./grub2/locale/de_CH.mo
314 ./grub2/locale/zh_TW.mo
315 ./grub2/locale/it.mo
316 ./grub2/locale/[email protected]
317 ./grub2/locale/ca.mo
318 ./grub2/locale/de.mo
319 ./grub2/locale/[email protected]
320 ./grub2/locale/zh_CN.mo
321 ./grub2/locale/ast.mo
322 ./grub2/locale/es.mo
323 ./grub2/locale/tr.mo
324 ./grub2/locale/sl.mo
325 ./grub2/locale/pa.mo
326 ./grub2/locale/fi.mo
327 ./grub2/locale/pt_BR.mo
328 ./grub2/locale/eo.mo
329 ./grub2/locale/hu.mo
330 ./grub2/locale/ru.mo
331 ./grub2/locale/vi.mo
332 ./grub2/locale/nl.mo
333 ./grub2/locale/[email protected]
334 ./grub2/locale/uk.mo
335 ./grub2/locale/[email protected]
336 ./grub2/locale/ja.mo
337 ./grub2/locale/[email protected]
338 ./grub2/locale/lt.mo
339 ./grub2/locale/pl.mo
340 ./grub2/locale/sv.mo
341 ./grub2/fonts
342 ./grub2/fonts/unicode.pf2
343 ./grub2/grubenv
353 ./grub2/grub.cfg
8194 ./grub
15 ./grub/splash.xpm.gz
35 ./initramfs-3.10.0-1160.el7.x86_64.img
30 ./.vmlinuz-3.10.0-1160.el7.x86_64.hmac
31 ./System.map-3.10.0-1160.el7.x86_64
32 ./config-3.10.0-1160.el7.x86_64
33 ./symvers-3.10.0-1160.el7.x86_64.gz
34 ./vmlinuz-3.10.0-1160.el7.x86_64
36 ./initramfs-0-rescue-0d4bcac3ad0e4afe96e50f962baa9f7d.img
37 ./vmlinuz-0-rescue-0d4bcac3ad0e4afe96e50f962baa9f7d
352 ./initramfs-3.10.0-1160.95.1.el7.x86_64.img
347 ./.vmlinuz-3.10.0-1160.95.1.el7.x86_64.hmac
348 ./System.map-3.10.0-1160.95.1.el7.x86_64
349 ./config-3.10.0-1160.95.1.el7.x86_64
350 ./symvers-3.10.0-1160.95.1.el7.x86_64.gz
351 ./vmlinuz-3.10.0-1160.95.1.el7.x86_64
【案例3】使用restore
指令的“还原模式”,将/boot
目录的备份还原到/opt/boottmp
目录中。
################## 指令速览 #####################
mkdir /opt/boottmp
cd /opt/boottmp
restore -r -f /opt/boot.bak0.bz2 # 恢复备份层级0
restore -r -f /opt/boot.bak1.bz2 # 恢复备份层级1
################## 实际演示 #####################
# 1. 恢复备份层级0
[root@CentOS76 boot]# mkdir /opt/boottmp
[root@CentOS76 boot]# cd /opt/boottmp/
[root@CentOS76 boottmp]# restore -r -f /opt/boot.bak0.bz2
Dump tape is compressed.
[root@CentOS76 boottmp]# ll -h
总用量 160M
-rw-r--r--. 1 root root 151K 7月 24 22:03 config-3.10.0-1160.95.1.el7.x86_64
-rw-r--r--. 1 root root 150K 10月 20 2020 config-3.10.0-1160.el7.x86_64
drwx------. 3 root root 4.0K 7月 29 2020 efi
drwxr-xr-x. 2 root root 4.0K 7月 13 17:07 grub
drwx------. 5 root root 4.0K 8月 25 11:17 grub2
-rw-------. 1 root root 77M 7月 13 17:10 initramfs-0-rescue-0d4bcac3ad0e4afe96e50f962baa9f7d.img
-rw-------. 1 root root 28M 8月 25 11:17 initramfs-3.10.0-1160.95.1.el7.x86_64.img
-rw-------. 1 root root 28M 7月 13 17:12 initramfs-3.10.0-1160.el7.x86_64.img
drwx------. 2 root root 4.0K 7月 13 17:06 lost+found
-rw-------. 1 root root 143K 8月 25 17:01 restoresymtable
-rw-r--r--. 1 root root 314K 7月 24 22:04 symvers-3.10.0-1160.95.1.el7.x86_64.gz
-rw-r--r--. 1 root root 314K 10月 20 2020 symvers-3.10.0-1160.el7.x86_64.gz
-rw-------. 1 root root 3.5M 7月 24 22:03 System.map-3.10.0-1160.95.1.el7.x86_64
-rw-------. 1 root root 3.5M 10月 20 2020 System.map-3.10.0-1160.el7.x86_64
-rwxr-xr-x. 1 root root 6.5M 7月 13 17:10 vmlinuz-0-rescue-0d4bcac3ad0e4afe96e50f962baa9f7d
-rwxr-xr-x. 1 root root 6.8M 7月 24 22:03 vmlinuz-3.10.0-1160.95.1.el7.x86_64
-rwxr-xr-x. 1 root root 6.5M 10月 20 2020 vmlinuz-3.10.0-1160.el7.x86_64
# 可以发现上述没有hello.txt
# 2. 恢复备份层级1
[root@CentOS76 boottmp]# restore -r -f /opt/boot.bak1.bz2
Dump tape is compressed.
[root@CentOS76 boottmp]# ll -h
总用量 160M
-rw-r--r--. 1 root root 151K 7月 24 22:03 config-3.10.0-1160.95.1.el7.x86_64
-rw-r--r--. 1 root root 150K 10月 20 2020 config-3.10.0-1160.el7.x86_64
drwx------. 3 root root 4.0K 7月 29 2020 efi
drwxr-xr-x. 2 root root 4.0K 7月 13 17:07 grub
drwx------. 5 root root 4.0K 8月 25 11:17 grub2
-rw-r--r--. 1 root root 0 8月 25 16:23 hello.txt
-rw-------. 1 root root 77M 7月 13 17:10 initramfs-0-rescue-0d4bcac3ad0e4afe96e50f962baa9f7d.img
-rw-------. 1 root root 28M 8月 25 11:17 initramfs-3.10.0-1160.95.1.el7.x86_64.img
-rw-------. 1 root root 28M 7月 13 17:12 initramfs-3.10.0-1160.el7.x86_64.img
drwx------. 2 root root 4.0K 7月 13 17:06 lost+found
-rw-------. 1 root root 143K 8月 25 17:02 restoresymtable
-rw-r--r--. 1 root root 314K 7月 24 22:04 symvers-3.10.0-1160.95.1.el7.x86_64.gz
-rw-r--r--. 1 root root 314K 10月 20 2020 symvers-3.10.0-1160.el7.x86_64.gz
-rw-------. 1 root root 3.5M 7月 24 22:03 System.map-3.10.0-1160.95.1.el7.x86_64
-rw-------. 1 root root 3.5M 10月 20 2020 System.map-3.10.0-1160.el7.x86_64
-rwxr-xr-x. 1 root root 6.5M 7月 13 17:10 vmlinuz-0-rescue-0d4bcac3ad0e4afe96e50f962baa9f7d
-rwxr-xr-x. 1 root root 6.8M 7月 24 22:03 vmlinuz-3.10.0-1160.95.1.el7.x86_64
-rwxr-xr-x. 1 root root 6.5M 10月 20 2020 vmlinuz-3.10.0-1160.el7.x86_64
# 可以上述已经恢复出hello.txt
【案例4】使用restore
指令恢复备份的文件,恢复/etc/整个目录的备份。
################## 指令速览 #####################
mkdir /opt/etctmp
cd /opt/etctmp/
restore -r -f /opt/etc.bak0.bz2
################## 实际演示 #####################
[root@CentOS76 boottmp]# mkdir /opt/etctmp
[root@CentOS76 boottmp]# cd /opt/etctmp/
[root@CentOS76 etctmp]# restore -r -f /opt/etc.bak0.bz2
Dump tape is compressed.
./lost+found: (inode 11) not found on tape
./boot: (inode 655361) not found on tape
./dev: (inode 131073) not found on tape
./proc: (inode 262145) not found on tape
./run: (inode 917505) not found on tape
./sys: (inode 393217) not found on tape
./root: (inode 786433) not found on tape
./var: (inode 131074) not found on tape
./tmp: (inode 262146) not found on tape
./data: (inode 799503) not found on tape
./usr: (inode 393218) not found on tape
./bin: (inode 17) not found on tape
./sbin: (inode 16) not found on tape
./lib: (inode 13) not found on tape
./lib64: (inode 15) not found on tape
./home: (inode 655362) not found on tape
./media: (inode 917506) not found on tape
./mnt: (inode 786434) not found on tape
./opt: (inode 655363) not found on tape
./srv: (inode 917507) not found on tape
[root@CentOS76 etctmp]# ls
etc restoresymtable
[root@CentOS76 etctmp]# ls /opt/etctmp/etc
abrt firefox magic rmt
adjtime firewalld mail.rc rpc
aliases flatpak makedumpfile.conf.sample rpm
aliases.db fonts man_db.conf rsyncd.conf
alsa fprintd.conf maven rsyslog.conf
alternatives fstab mke2fs.conf rsyslog.d
anacrontab fuse.conf modprobe.d rwtab
asound.conf fwupd modules-load.d rwtab.d
at.deny gconf motd samba
audisp gcrypt mtab sane.d
audit gdbinit mtools.conf sasl2
autofs.conf gdbinit.d multipath scl
autofs_ldap_auth.conf gdm my.cnf securetty
auto.master geoclue my.cnf.d security
auto.master.d GeoIP.conf nanorc selinux
auto.misc ghostscript ndctl services
auto.net glvnd netconfig sestatus.conf
auto.smb gnupg NetworkManager setroubleshoot
avahi GREP_COLORS networks setuptool.d
bash_completion.d groff nfs.conf sgml
bashrc group nfsmount.conf shadow
binfmt.d group- nsswitch.conf shadow-
bluetooth grub2.cfg nsswitch.conf.bak shells
brltty grub.d ntp skel
brltty.conf gshadow ntp.conf smartmontools
centos-release gshadow- numad.conf sos.conf
centos-release-upstream gss oddjob speech-dispatcher
certmonger gssproxy oddjobd.conf ssh
cgconfig.conf host.conf oddjobd.conf.d ssl
cgconfig.d hostname openldap sssd
cgrules.conf hosts opt statetab
cgsnapshot_blacklist.conf hosts.allow os-release statetab.d
chkconfig.d hosts.deny PackageKit subgid
chrony.conf hp pam.d subuid
chrony.keys idmapd.conf papersize subversion
cifs-utils init.d passwd sudo.conf
cron.d inittab passwd- sudoers
cron.daily inputrc pbm2ppa.conf sudoers.d
cron.deny ipa pinforc sudo-ldap.conf
cron.hourly iproute2 pkcs11 sysconfig
cron.monthly ipsec.conf pki sysctl.conf
crontab ipsec.d plymouth sysctl.d
cron.weekly ipsec.secrets pm systemd
crypttab iscsi pnm2ppa.conf system-release
csh.cshrc issue polkit-1 system-release-cpe
csh.login issue.net popt.d target
cups java postfix tcsd.conf
cupshelpers jvm ppp terminfo
dbus-1 jvm-commmon prelink.conf.d tmpfiles.d
dconf kdump.conf printcap trusted-key.key
default kernel profile tuned
depmod.d krb5.conf profile.d udev
dhcp krb5.conf.d protocols udisks2
DIR_COLORS ksmtuned.conf pulse unbound
DIR_COLORS.256color ld.so.cache purple updatedb.conf
DIR_COLORS.lightbgcolor ld.so.conf python UPower
dleyna-server-service.conf ld.so.conf.d qemu-ga usb_modeswitch.conf
dnsmasq.conf libaudit.conf qemu-kvm vconsole.conf
dnsmasq.d libblockdev radvd.conf vimrc
dracut.conf libibverbs.d rc0.d virc
dracut.conf.d libnl rc1.d vmware-tools
dumpdates libpaper.d rc2.d wgetrc
e2fsck.conf libreport rc3.d wpa_supplicant
egl libuser.conf rc4.d wvdial.conf
enscript.cfg libvirt rc5.d X11
environment locale.conf rc6.d xdg
ethertypes localtime rc.d xinetd.d
exports login.defs rc.local xml
exports.d logrotate.conf rdma yum
favicon.png logrotate.d redhat-release yum.conf
fcoe lsm request-key.conf yum.repos.d
festival lvm request-key.d
filesystems machine-id resolv.conf
《鸟哥的Linux私房菜 基础学习篇 第四版》 ↩︎
《鸟哥的Linux私房菜 服务器架设篇 第三版》 ↩︎
《韩顺平_2021图解Linux全面升级》 ↩︎