5.打包与压缩
本章同步视频:https://edu.51cto.com/sd/e4874
5.3.3 XFS 文件系统还原xfsrestore
1.xfsrestore - XFS filesystem incremental restore utility
[root@study ~]# xfsrestore [-f 备份档] [-L S_label] [-s] 待复原目录
[root@study ~]# xfsrestore [-f 备份文件] -r 待复原目录
[root@study ~]# xfsrestore [-f 备份文件] -i待复原目录
-I :跟xfsdump相同的输出!可查询备份数据,包括 Label 名称与备份时间等
-L :就是 Session 的 Label name 喔!可用 -I 查询到的数据,在这个选项后输入!
-r :如果是用档案来储存备份数据,那这个就不需要使用。如果是一个磁带内有多个档案,需要这东西来达成累积复原
-i:进入互动模式,进阶管理员使用的!一般我们不太需要操作它!
[root@localhost mnt]# xfsrestore -I
fs id: f598c75c-bd26-4543-af2f-8192841c4c8b
mount point: localhost.localdomain:/mnt/sda3
device: localhost.localdomain:/dev/sda3
time: Tue Mar 31 20:42:51 2020
session label: "dump_sda3_20200331"
session id: b2315293-f79f-43b2-9276-157268eea187
media id: 23a27bd0-e47b-4bee-9005-d530e6303f63
mount point: localhost.localdomain:/mnt/sda3
device: localhost.localdomain:/dev/sda3
time: Tue Mar 31 20:47:58 2020
session label: "dump_sda3_20200331-1"
session id: 989e4ade-b8c3-40be-9714-10c648f6b46c
media id: 42121b62-abf0-4e26-98f1-48d50f01b633
mount point: localhost.localdomain:/mnt/sda3
device: localhost.localdomain:/dev/sda3
time: Tue Mar 31 20:56:34 2020
session label: "dump_sda3_20200331-2"
session id: 1a6e946b-fd0e-4e70-bb00-b82c04291de7
media id: f410ea13-eada-4566-87c8-844b1a939ce1
[root@localhost mnt]# rm -f sda3/*
[root@localhost mnt]# ls sda3/
[root@localhost mnt]# xfsrestore -f /tmp/sda3 /mnt/sda3/
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.3 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: hostname: localhost.localdomain
xfsrestore: mount point: /mnt/sda3
xfsrestore: session time: Tue Mar 31 20:42:51 2020
xfsrestore: session label: "dump_sda3_20200331"
xfsrestore: media label: "sda3"
xfsrestore: file system id: f598c75c-bd26-4543-af2f-8192841c4c8b
xfsrestore: session id: b2315293-f79f-43b2-9276-157268eea187
xfsrestore: media id: 23a27bd0-e47b-4bee-9005-d530e6303f63
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 1 directories and 1 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: stream 0 /tmp/sda3 OK (success)
xfsrestore: Restore Status: SUCCESS
[root@localhost mnt]# ls sda3/
[root@localhost mnt]# xfsrestore -f /tmp/sda3-1 /mnt/sda3/
[root@localhost mnt]# ls sda3/
[root@localhost mnt]# xfsrestore -f /tmp/sda3-2 /mnt/sda3/
[root@localhost mnt]# ls sda3/
1.txt 2.txt 3.txt 4.txt 5.txt 6.txt
[root@localhost mnt]# xfsrestore -f /tmp/sda3-2 -i /mnt/sda3/
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.3 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: hostname: localhost.localdomain
xfsrestore: mount point: /mnt/sda3
xfsrestore: session time: Tue Mar 31 20:56:34 2020
xfsrestore: session label: "dump_sda3_20200331-2"
xfsrestore: media label: "sda3"
xfsrestore: file system id: f598c75c-bd26-4543-af2f-8192841c4c8b
xfsrestore: session id: 1a6e946b-fd0e-4e70-bb00-b82c04291de7
xfsrestore: media id: f410ea13-eada-4566-87c8-844b1a939ce1
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 1 directories and 6 entries processed
xfsrestore: directory post-processing
================= subtree selection dialog ==================
the following commands are available:
-> add 2.txt #本条无效,因为2.txt不在本次备份文件中
--------------------------------- end dialog ---------------------------------
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 97 seconds elapsed
xfsrestore: stream 0 /tmp/sda3-2 OK (success)
xfsrestore: Restore Status: SUCCESS
[root@localhost mnt]# ls sda3/
如果只想要复原某一个目录或档案的话,直接加上『 -s 目录』这个选项与参数即可!前提是你要知道被还原的文档名。
[root@localhost mnt]# xfsrestore -f /tmp/sda3-2 -s 6.txt /mnt/sda3
[root@localhost mnt]# ls sda3/
5.4 其他备份工具
5.4.1 dd - convert and copy a file
[root@study ~]# dd if="input_file" of="output_file" bs="block_size" count="number"
bs :规划的一个 block 的大小,若未指定则预设是 512 bytes(一个 sector 的大小)
[root@localhost ~]# dd if=/dev/hdb of=/dev/hdd
(2)将/dev/hdb全盘数据备份到指定路径的image文件
[root@localhost ~]# dd if=/dev/hdb of=/root/image
[root@localhost ~]# dd if=/root/image of=/dev/hdb
[root@localhost ~]# dd if=/dev/hda of=/root/image count=1 bs=512
[root@localhost ~]# dd if=/root/image of=/dev/had
把/dev/null看作"黑洞", 它等价于一个只写文件,所有写入它的内容都会永远丢失.,而尝试从它那儿读取内容则什么也读不到。然而, /dev/null对命令行和脚本都非常的有用。
[root@localhost ~]# echo "aaaa"
[root@localhost ~]# echo "aaaa" >/dev/null
cat: aaaaa: No such file or directory
[root@localhost ~]# cat aaaaa 2>/dev/null
[root@localhost tmp]# cat root
[root@localhost tmp]# cat calf
cat: calf: No such file or directory
[root@localhost tmp]# cat root calf >/dev/null 2>/dev/null
[root@localhost tmp]# cat /dev/null >root
[root@localhost tmp]# cat root
/dev/zero也是一个伪文件, 但它实际上产生连续不断的null的流(二进制的零流,而不是ASCII型的)。 /dev/zero主要的用处是用来创建一个指定长度用于初始化的空文件,就像临时交换文件。
[root@localhost tmp]# dd if=/dev/zero of=test bs=1M count=10
10485760 bytes (10 MB) copied, 0.021191 s, 495 MB/s
5.5 总结
l 压缩指令为透过一些运算方法去将原本的档案进行压缩,以减少档案所占用的磁盘容量。
l 压缩文件案的扩展名大多是:『*.gz, *.bz2, *.xz, *.tar, *.tar.gz, *.tar.bz2, *.tar.xz』
l 常见的压缩指令有 gzip, bzip2, xz。压缩率最佳的是 xz。
l tar 可以用来进行档案打包,并可支持 gzip, bzip2, xz 的压缩。
l xfsdump 指令可备份文件系统或单一目录,xfsrestore 指令可还原被 xfsdump 建置的备份档;