xfsrestore-备份还原

5.打包与压缩

本章同步视频:https://edu.51cto.com/sd/e4874

5.3.3 XFS 文件系统还原xfsrestore

1.xfsrestore - XFS filesystem incremental restore utility

[root@study ~]# xfsrestore -I                           

 <==用来察看备份文件资料

[root@study ~]# xfsrestore [-f 备份档] [-L S_label] [-s] 待复原目录

<==单一档案全系统复原

[root@study ~]# xfsrestore [-f 备份文件] -r 待复原目录

<==透过累积备份文件来复原系统

[root@study ~]# xfsrestore [-f 备份文件] -i待复原目录

<==进入互动模式

选项与参数:

-I  :跟xfsdump相同的输出!可查询备份数据,包括 Label 名称与备份时间等

-f  :后面接的就是备份档!

-L  :就是 Session 的 Label name 喔!可用 -I 查询到的数据,在这个选项后输入!

-s  :需要接某特定目录,亦即仅复原某一个档案或目录之意!

-r  :如果是用档案来储存备份数据,那这个就不需要使用。如果是一个磁带内有多个档案,需要这东西来达成累积复原

-i:进入互动模式,进阶管理员使用的!一般我们不太需要操作它!

2.查看备份信息

[root@localhost mnt]# xfsrestore -I

file system 0:

fs id:  f598c75c-bd26-4543-af2f-8192841c4c8b

session 0:

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

level:  0

resumed: NO

subtree: NO

streams: 1

stream 0:

pathname: /tmp/sda3

start:  ino 131 offset 0

end:  ino 132 offset 0

interrupted: NO

media files: 1

media file 0:

mfile index: 0

mfile type: data

mfile size: 21656

mfile start: ino 131 offset 0

mfile end: ino 132 offset 0

media label: "sda3"

media id: 23a27bd0-e47b-4bee-9005-d530e6303f63

session 1:

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

level:  1

resumed: NO

subtree: NO

streams: 1

stream 0:

pathname: /tmp/sda3-1

start:  ino 132 offset 0

end:  ino 133 offset 0

interrupted: NO

media files: 1

media file 0:

mfile index: 0

mfile type: data

mfile size: 21680

mfile start: ino 132 offset 0

mfile end: ino 133 offset 0

media label: "sda3"

media id: 42121b62-abf0-4e26-98f1-48d50f01b633

session 2:

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

level:  2

resumed: NO

subtree: NO

streams: 1

stream 0:

pathname: /tmp/sda3-2

start:  ino 133 offset 0

end:  ino 137 offset 0

interrupted: NO

media files: 1

media file 0:

mfile index: 0

mfile type: data

mfile size: 23624

mfile start: ino 133 offset 0

mfile end: ino 137 offset 0

media label: "sda3"

media id: f410ea13-eada-4566-87c8-844b1a939ce1

xfsdump: Dump Status: SUCCESS

3.还原level0

[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: dump description:

xfsrestore: hostname: localhost.localdomain

xfsrestore: mount point: /mnt/sda3

xfsrestore: volume: /dev/sda3

xfsrestore: session time: Tue Mar 31 20:42:51 2020

xfsrestore: level: 0

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: Restore Summary:

xfsrestore:   stream 0 /tmp/sda3 OK (success)

xfsrestore: Restore Status: SUCCESS

[root@localhost mnt]# ls sda3/

1.txt

4.还原level 1

[root@localhost mnt]# xfsrestore -f /tmp/sda3-1 /mnt/sda3/

[root@localhost mnt]# ls sda3/

1.txt  2.txt

5.还原level 2

[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

6.交互式部分还原

[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: dump description:

xfsrestore: hostname: localhost.localdomain

xfsrestore: mount point: /mnt/sda3

xfsrestore: volume: /dev/sda3

xfsrestore: session time: Tue Mar 31 20:56:34 2020

xfsrestore: level: 2

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:

       pwd

ls [ <path> ]

cd [ <path> ]

add [ <path> ]

delete [ <path> ]

       extract

       quit

       help

 -> ls

             136 6.txt

             135 5.txt

             134 4.txt

             133 3.txt

             132 2.txt

             131 1.txt

 -> add 2.txt     #本条无效,因为2.txt不在本次备份文件中

 -> add 4.txt

 -> add 6.txt

 -> extract

 --------------------------------- end dialog ---------------------------------

xfsrestore: restoring non-directory files

xfsrestore: restore complete: 97 seconds elapsed

xfsrestore: Restore Summary:

xfsrestore:   stream 0 /tmp/sda3-2 OK (success)

xfsrestore: Restore Status: SUCCESS

[root@localhost mnt]# ls sda3/

4.txt  6.txt

7.非交互式部分还原

如果只想要复原某一个目录或档案的话,直接加上『 -s 目录』这个选项与参数即可!前提是你要知道被还原的文档名。

[root@localhost mnt]# xfsrestore -f /tmp/sda3-2 -s 6.txt /mnt/sda3

[root@localhost mnt]# ls sda3/

6.txt

5.4 其他备份工具

5.4.1 dd - convert and copy a file

1.语法

[root@study ~]# dd if="input_file" of="output_file" bs="block_size" count="number"

选项与参数:

if   :就是 input file ~也可以是装置!

of   :就是 output file~也可以是装置;

bs   :规划的一个 block 的大小,若未指定则预设是 512 bytes(一个 sector 的大小)

count:多少个 bs 的意思。

2.用法

(1)将本地的/dev/hdb整盘备份到/dev/hdd

[root@localhost ~]# dd if=/dev/hdb of=/dev/hdd

(2)将/dev/hdb全盘数据备份到指定路径的image文件

[root@localhost ~]# dd if=/dev/hdb of=/root/image

(3)将备份文件恢复到指定盘

[root@localhost ~]# dd if=/root/image of=/dev/hdb

(4)备份与恢复MBR

[root@localhost ~]# dd if=/dev/hda of=/root/image count=1 bs=512

[root@localhost ~]# dd if=/root/image of=/dev/had

3./dev/null

        把/dev/null看作"黑洞", 它等价于一个只写文件,所有写入它的内容都会永远丢失.,而尝试从它那儿读取内容则什么也读不到。然而, /dev/null对命令行和脚本都非常的有用。

(1)禁止标准输出

[root@localhost ~]# echo "aaaa"

aaaa

[root@localhost ~]# echo "aaaa" >/dev/null

(2)禁止标准错误输出

[root@localhost ~]# cat aaaaa

cat: aaaaa: No such file or directory

[root@localhost ~]# cat aaaaa 2>/dev/null

(3)禁止标准输出和标准错误输出

[root@localhost tmp]# ls

root  test

[root@localhost tmp]# cat root

aaaaa

[root@localhost tmp]# cat calf

cat: calf: No such file or directory

[root@localhost tmp]# cat root calf >/dev/null 2>/dev/null

(4)清空文件内容

[root@localhost tmp]# cat /dev/null >root

[root@localhost tmp]# cat root

4./dev/zero

        /dev/zero也是一个伪文件, 但它实际上产生连续不断的null的流(二进制的零流,而不是ASCII型的)。  /dev/zero主要的用处是用来创建一个指定长度用于初始化的空文件,就像临时交换文件。

(1)创建一个10M大小的临时文件test

[root@localhost tmp]# dd if=/dev/zero of=test bs=1M count=10

10+0 records in

10+0 records out

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 建置的备份档;


猜你喜欢

转载自blog.51cto.com/5482173/2490132