本文主要是介绍系列教程--Linux基础--16--XFS 文件系统备份和恢复,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本节概要
交互式备份
非交互式备份
文件系统恢复
文件克隆
环境准备
操作系统: Centos6.5、Centos7.2
一、文件系统备份
1. xfsdump 简介
为防止文件被误删,或者分区被破坏可以对分区进行备份,出现问题时使用已经存在的备份进行数据的恢复。
备份命令:xfsdump
参数:
-f 备份到指定的路径
-l 指定备份等级,0为全量备份,1-9为增量备份。
-L 备份标签
-M 设备标签
2. xfsdump安装
[root@node1 ~]# yum install -y xfsdump
[root@node1 ~]# yum install -y xfsprogs-devel
3. 环境准备
新加一块磁盘,格式化为xfs文件系统,并挂载到/xfs 路径下。
添加分区:
格式化分区:
挂载分区:
[root@node1 ~]# mkdir /xfs
[root@node1 ~]# mount /dev/sdb1 /xfs
添加测试文件:
[root@node1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 47G 3.9G 44G 9% /
devtmpfs 473M 0 473M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 7.0M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 173M 842M 18% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 1014M 33M 982M 4% /xfs
[root@node1 ~]# cd /xfs
[root@node1 xfs]# ls
[root@node1 xfs]# mkdir dir1
[root@node1 xfs]# echo xfsdump test > f1
[root@node1 xfs]# ll
total 4
drwxr-xr-x 2 root root 6 Jun 21 01:32 dir1
-rw-r--r-- 1 root root 13 Jun 21 01:32 f1
4. 交互式备份
备份/xfs整个目录到/tmp/tmp-xfs:
[root@node1 xfs]# xfsdump -f /tmp/tmp-xfs /xfs
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)
-> xfs #备份标签
session label entered: "xfs"
--------------------------------- end dialog ---------------------------------
xfsdump: level 0 dump of node1:/xfs
xfsdump: dump date: Thu Jun 21 01:36:33 2018
xfsdump: session id: 0f3c602a-451f-43c8-95a2-5b93e772c65a
xfsdump: session label: "xfs"
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: 25536 bytes
xfsdump: /var/lib/xfsdump/inventory created
============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
-> sdb1 #设备标签
media label entered: "sdb1"
--------------------------------- 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 22176 bytes
xfsdump: dump size (non-dir files) : 544 bytes
xfsdump: dump complete: 51 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /tmp/tmp-xfs OK (success)
xfsdump: Dump Status: SUCCESS
查看备份是否成功:
[root@node1 ~]# ll /tmp/tmp-xfs
-rw-r--r-- 1 root root 22176 Jun 21 01:37 /tmp/tmp-xfs
5. 非交互式备份
交互式备份适用于手动操作时,不适合放在脚本中或者计划任务中进行,此时可以使用非交互式的备份方式进行代替。
非交互式方式备份/xfs到/tmp/tmp-xfs2
[root@node1 ~]# xfsdump -f /tmp/tmp-xfs2 /xfs -L tmp-xfs2 -M sdb1
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsdump: level 0 dump of node1:/xfs
xfsdump: dump date: Thu Jun 21 04:25:06 2018
xfsdump: session id: a746b3b1-ed76-485a-9802-299335e054aa
xfsdump: session label: "tmp-xfs2"
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: 25536 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 22176 bytes
xfsdump: dump size (non-dir files) : 544 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /tmp/tmp-xfs2 OK (success)
xfsdump: Dump Status: SUCCESS
-L 备份标签
-M 设备标签
查看备份:
[root@node1 ~]# ll /tmp/tmp-xfs2
-rw-r--r-- 1 root root 22176 Jun 21 04:25 /tmp/tmp-xfs2
二、文件系统恢复
文件系统恢复需要借助于xfsdump备份的文件。
命令 xfsrestore
参数:
-l 查询备份数据
-f 指定需要使用的备份文档
-L 指定备份标签
-s 指定需要恢复的特定的目录或者文档
-I 进入交互模式
1. 删除分区
删除分区,模拟分区故障
[root@node1 ~]# rm -rf /dev/sdb1
[root@node1 ~]# ls /xfs #分区被删除后目录已空
2. 文件系统恢复
使用备份/tmp/tmp-xfs恢复文件系统
[root@node1 ~]# xfsrestore -f /tmp/tmp-xfs /xfs
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (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: node1
xfsrestore: mount point: /xfs
xfsrestore: volume: /dev/sdb1
xfsrestore: session time: Thu Jun 21 01:36:33 2018
xfsrestore: level: 0
xfsrestore: session label: "xfs"
xfsrestore: media label: "sdb1"
xfsrestore: file system id: db1d1feb-9012-4bac-b151-f7f150886efc
xfsrestore: session id: 0f3c602a-451f-43c8-95a2-5b93e772c65a
xfsrestore: media id: 32adad60-9557-4afe-a757-a05c2627bce8
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 2 directories and 2 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /tmp/tmp-xfs OK (success)
xfsrestore: Restore Status: SUCCESS
查看文件:
[root@node1 ~]# ls /xfs
dir1 f1
[root@node1 ~]# cat /xfs/f1
xfsdump test
除了恢复整个文件系统,也可恢复指定的文件或者目录:
xfsrestore -f /tmp/tmp-xfs -s /xfs/f1 #恢复单个文件f1
三、文件克隆
克隆文件系统或者称为分区的拷贝。
[root@node1 ~]# mkdir /xfs-back #目标目录需要提前新建,否则报错
# 将/xfs中所有文件克隆岛/xfs-back
[root@node1 ~]# xfsdump - /xfs | xfsrestore - /xfs-back
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0)
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0)
xfsdump: level 0 dump of node1:/xfs
xfsdump: dump date: Thu Jun 21 04:50:06 2018
xfsdump: session id: 8fcc75b8-62fd-4f0b-9550-371f1c70d0d8
xfsdump: session label: ""
xfsrestore: searching media for dump
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: 25536 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 22176 bytes
xfsdump: dump size (non-dir files) : 544 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Status: SUCCESS
xfsrestore: examining media file 0
xfsrestore: dump description:
xfsrestore: hostname: node1
xfsrestore: mount point: /xfs
xfsrestore: volume: /dev/sdb1
xfsrestore: session time: Thu Jun 21 04:50:06 2018
xfsrestore: level: 0
xfsrestore: session label: ""
xfsrestore: media label: ""
xfsrestore: file system id: db1d1feb-9012-4bac-b151-f7f150886efc
xfsrestore: session id: 8fcc75b8-62fd-4f0b-9550-371f1c70d0d8
xfsrestore: media id: faaeb1cb-6435-475d-8320-e982efb39bd6
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 2 directories and 2 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Status: SUCCESS
[root@node1 ~]# ls /xfs-back/
dir1 f1
也可克隆单个的文件或者目录。
四、拓展
1. 查询ext3、ext4文件系统的恢复方法,并操作。
这篇关于系列教程--Linux基础--16--XFS 文件系统备份和恢复的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!