社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
目录
XFS提供了 xfsdump 和 xfsrestore 工具协助备份XFS文件系统中的数据。xfsdump 按inode顺序备份一个XFS文件系统。
Centos7选择xfs格式作为默认文件系统,而且不再使用以前的ext,仍然支持ext4,xfs专为大数据产生,每个单个文件系统最大可以支持8eb,单个文件可以支持16tb,不仅数据量大,而且扩展性高。还可以通过xfsdump,xfsrestore来备份和恢复。
通俗来说类似Win系统的gho文件
通过实验学习 xfsdump 和 xfsrestore 使用方法
系统CENTOS7.4添加一块虚拟硬盘(准备一个测试分区)
正常使用一块磁盘过程如下:
添加磁盘 ——分区——格式化——挂载
[root@centos7 ~]# ls /dev/sd* #查看硬盘信息,sda表示第一块硬盘,sdb第二块硬盘,sda1第一块 硬盘第一个分区
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb
[root@centos7 ~]# fdisk /dev/sdb #对sdb进行分区
欢迎使用 fdisk (util-linux 2.23.2)。更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。Device does not contain a recognized partition table
使用磁盘标识符 0x7eaf86c1 创建新的 DOS 磁盘标签。命令(输入 m 获取帮助):n ###创建一个新的分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p ###创建一个主分区
分区号 (1-4,默认 1):
起始 扇区 (2048-83886079,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-83886079,默认为 83886079):+30G ###指定分区大小,不填默认全部
分区 1 已设置为 Linux 类型,大小设为 30 GiB命令(输入 m 获取帮助):p ###打印分区表
磁盘 /dev/sdb:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x7eaf86c1设备 Boot Start End Blocks Id System
/dev/sdb1 2048 62916607 31457280 83 Linux命令(输入 m 获取帮助):w ###保存
The partition table has been altered!Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@centos7 ~]# ls /dev/sd ###查看硬盘情况,已经多了一个sdb1分区
sda sda1 sda2 sdb sdb1
[root@centos7 ~]# mkfs.xfs /dev/sdb1 ###格式化为xfs文件模式
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=1966080 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=7864320, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=3840, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@centos7 ~]# mkdir /sdb1 ###创建挂载目录sdb1
[root@centos7 ~]# mount /dev/sdb1 /sdb1 ###将sdb1挂载到/sdb1目录上
[root@centos7 ~]# touch /sdb1/a.txt ###新建一个文件看检查是否可用
[root@centos7 ~]# ls /sdb1
a.txt
[root@centos7 ~]#
语法:xfsdump -f 备份存放位置 要备份路径或设备文件
---------------------------------------------------创建测试文件------------------------------------------------------------
[root@centos7 ~]# touch /sdb1/a{1..10}.txt ###连续创建文件
[root@centos7 ~]# cp /etc/passwd /sdb1 ###复制passwd文件到sdb1目录
[root@centos7 ~]# ls /sdb1 ###查看
a10.txt a1.txt a2.txt a3.txt a4.txt a5.txt a6.txt a7.txt a8.txt a9.txt a.txt passwd---------------------------------------------------备份语句------------------------------------------------------------
[root@centos7 ~]# xfsdump -f /opt/dump_sdb1 /sdb1 ###将/sdb1下的内容,备份到/opt下,名称为dump_sdb1
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
-> dump_sdb1 ###指定备份会话标签,一般与备份文件名称一致
session label entered: "dump_sdb1"--------------------------------- end dialog ---------------------------------
xfsdump: level 0 dump of centos7:/sdb1
xfsdump: dump date: Sat Apr 6 17:57:13 2019
xfsdump: session id: b2ee3c68-38e3-4437-91f9-7f0e5f46f71c
xfsdump: session label: "dump_sdb1"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 45120 bytes============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
-> sdb1test ###指定设备标签,就是对要备份的设备做一个描述
media label entered: "sdb1test"--------------------------------- end dialog ---------------------------------
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 30640 bytes
xfsdump: dump size (non-dir files) : 5792 bytes
xfsdump: dump complete: 24 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /opt/dump_sdb1 OK (success)
xfsdump: Dump Status: SUCCESS
-------------------------------------------------------------检查备份情况-------------------------------------------------------------
[root@centos7 ~]# ll /opt
总用量 32
-rw-r--r-- 1 root root 30640 4月 6 17:57 dump_sdb1 ###这里看到已经备份文件已经有大小
drwxr-xr-x. 2 root root 6 9月 7 2017 rh
drwxr-xr-x 2 root root 6 4月 6 17:44 test
[root@centos7 ~]#
[root@centos7 ~]# xfsdump -f /opt/dump_sdb2 /sdb1 -L dump_sdb2 -M sdb2test
参数说明:
/opt/dump_sdb2: 备份的存放路径和备份文件名为 “dump_sdb2”
/sdb1:备份标
-L dump_sdb2: -L是标准写法,dump_sdb2是会话标签
-M sdb2test: -M是标准写法,sdb2test是会话标签描述
[root@centos7 ~]# mkdir /sdb1/test
[root@centos7 ~]# touch /sdb1/test/b{1..10}.txt
[root@centos7 ~]# xfsdump -f /opt/dump_test -s test /sdb1 -L dump_test -M tmp
说明:
-s test /sdb1:指 -s是标准参数, test是相对路径, /sdb1是根路径,意思是将:/sdb1/test目录进行备份xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsdump: WARNING: most recent level 0 dump was interrupted, but not resuming that dump since resume (-R) option not specified
xfsdump: level 0 dump of centos7:/sdb1
xfsdump: dump date: Sat Apr 6 18:29:29 2019
xfsdump: session id: 722cfb44-e47c-412e-8b30-a3cb7ecc9ded
xfsdump: session label: "dump_test"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 45120 bytes
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 27928 bytes
xfsdump: dump size (non-dir files) : 2720 bytes
xfsdump: dump complete: 1 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /opt/dump_test OK (success)
xfsdump: Dump Status: SUCCESS
[root@centos7 ~]# ll /opt
总用量 92
-rw-r--r-- 1 root root 30640 4月 6 17:57 dump_sdb1
-rw-r--r-- 1 root root 30640 4月 6 18:03 dump_sdb2
-rw-r--r-- 1 root root 27928 4月 6 18:29 dump_test
drwxr-xr-x. 2 root root 6 9月 7 2017 rh
drwxr-xr-x 2 root root 6 4月 6 17:44 test
[root@centos7 ~]# ll /opt
语法:xfsrestore -f 备份存放文件 还原的目标位置
[root@centos7 ~]# xfsrestore -f /opt/dump_sdb1 /sdb1 ###将dump_sdb1备份文件内容还原到/sdb1分区
[root@centos7 ~]# xfsdump -f /opt/dump_sdb1 /sdb1 -L dump_sdb1 -M sdb1test ###备份一次全局
[root@centos7 ~]# xfsdump -l 1 -f /opt/dump_sdb1_1 /sdb1 -L dump_sdb1_1 -M sdb1_1 ###只更新有变动的
[root@centos7 ~]# xfsdump -l 2 -f /opt/dump_sdb1_2 /sdb1 -L dump_sdb1_1 -M sdb1_2
说明:-l <level> 做一个等级为1的备份,如果还有多个次,如此类推
和第5点一样,只是增量备份的还原顺序是:还原全局——还原1级——还原2级——如果类推
使用 xfsdump 时,请注意下面下面的几个限制:
1、xfsdump 不支持没有挂载的文件系统备份!所以只能备份已挂载的!
2、xfsdump 必须使用 root 的权限才能操作 (涉及文件系统的关系)
3、xfsdump 只能备份 XFS 文件系统
4、xfsdump 备份下来的数据 (档案或储存媒体) 只能让 xfsrestore 解析
5、xfsdump 是透过文件系统的 UUID 来分辨各个备份档的,因此不能备份两个具有相同 UUID 的文件系统
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!