一:使用xfsdump备份和恢复xfs文件系统
首先了解一下xfsdump的备份级别如下,默认为0(即完全备份)
0 完全备份
1 <= level <= 9 增量备份
1.创建xfs文件系统并挂载到/data目录下
linux-x4xj:~ # mkfs.xfs /dev/sdb
linux-x4xj:~ # mkdir /data
linux-x4xj:~ # mount /dev/sdb /data
linux-x4xj:~ # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 4.0G 1.6G 2.2G 43% /
devtmpfs 465M 168K 465M 1% /dev
tmpfs 465M 0 465M 0% /dev/shm
/dev/sdb 20G 33M 20G 1% /data
linux-x4xj:~ #
2.备份测试
首先复制一些文件到/data目录下,以便测试,如下所示
linux-x4xj:~ # ls -l /data
total 1792
-rwxr--r-- 1 nobody nobody 1832960 Sep 1314:12 iozone3_429.tar
drwxr-xr-x 2 nobody nobody 102 Sep 16 20:46 lustre-client-el5.8-2.1.6
linux-x4xj:~ #
◆首先备份/data整个目录到/tmp目录下
测试过程中发现:如果命令这样写xfsdump -f /tmp/dump_data /data/,就会提示错误(xfsdump:ERROR: /data/ does not identify a file system)
linux-x4xj:~ # xfsdump -f /tmp/dump_data/data/
xfsdump: using file dump (drive_simple)strategy
xfsdump: version 3.0.5 (dump format 3.0) -Running single-threaded
============================= dump labeldialog ==============================
please enter label for this dump session(timeout in 300 sec)
-> dump_data
session label entered:"dump_data"
---------------------------------end dialog ---------------------------------
xfsdump: ERROR:/data/ does not identify a file system
xfsdump: usage: xfsdump [ -a (dump DMFdualstate files as offline) ]
*
*
*
必须要这样写xfsdump -f /tmp/dump_data /data(即/data后面的/不能要)这样才能成功
linux-x4xj:~ # xfsdump -f /tmp/data_dump /data
xfsdump: using file dump (drive_simple)strategy
xfsdump: version 3.0.5 (dump format 3.0) -Running single-threaded
============================= dump labeldialog ==============================
please enter label for this dump session(timeout in 300 sec)
-> data_dump
session label entered:"data_dump"
--------------------------------- end dialog---------------------------------
xfsdump: level 0 dump of linux-x4xj:/data
xfsdump: dump date: Tue Sep 16 20:58:582014
xfsdump: session id:ca3390ef-1a8c-429b-8d87-4e60d22d3c54
xfsdump: session label: "data_dump"
xfsdump: ino map phase 1: constructinginitial dump list
xfsdump: ino map phase 2: skipping (nopruning necessary)
xfsdump: ino map phase 3: skipping (onlyone dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 70670208bytes
============================= media labeldialog =============================
please enter label for media in drive 0(timeout in 300 sec)
-> media0
media label entered: "media0"
--------------------------------- 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 70680352 bytes
xfsdump: dump size (non-dir files) :70656816 bytes
xfsdump: dump complete: 9 seconds elapsed
xfsdump: Dump Status: SUCCESS
linux-x4xj:~ # ls -l /tmp/data_dump
-rw-r--r-- 1 root root 70680352 Sep 1620:59 /tmp/data_dump
linux-x4xj:~ #
以上为会话模式,即会提示让你输入label for session和label for dump,可以用下面的命令运行,就不会出现会话模式了
linux-x4xj:~ # xfsdump -f /tmp/data_dump /data -L data_dump -M data_dump
◆备份/data目录下的lustre-client-el5.8-2.1.6子目录到/tmp目录下,命令如下
linux-x4xj:~ # xfsdump -f /tmp/data_lustre_client_dump -s lustre-client-el5.8-2.1.6 /data -L data_lustre_client_dump -M media0 (注意子目录前面不能有/,最后面也不能有/)
xfsdump: using file dump (drive_simple)strategy
xfsdump: version 3.0.5 (dump format 3.0) -Running single-threaded
xfsdump: level 0 dump of linux-x4xj:/data
xfsdump: dump date: Tue Sep 16 21:07:14 2014
xfsdump: session id:12d13ad4-47d2-4ea5-94df-afc2d71cb6a4
xfsdump: session label:"data_lustre_client_dump"
xfsdump: ino map phase 1: constructinginitial dump list
xfsdump: ino map phase 2: skipping (nopruning necessary)
xfsdump: ino map phase 3: skipping (onlyone dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 68834880bytes
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 68845344 bytes
xfsdump: dump size (non-dir files) :68822096 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Status: SUCCESS
linux-x4xj:~ # ls -l /tmp/data_lustre_client_dump
-rw-r--r-- 1 root root 68845344 Sep 1621:07 /tmp/data_lustre_client_dump
linux-x4xj:~ #
◆克隆/data(备份所有内容到另一个目录或到另一个硬盘下),本次新加了一个盘用作备份,挂载到了/data2下,开始克隆,命令如下
linux-x4xj:~ #xfsdump - /data | xfsrestore - /data2
或者
linux-x4xj:~ #xfsdump -l 0 - /data | xfsrestore - /data2 (因为默认级别为0)
linux-x4xj:~ # ll/data
total 1792
-rwxr--r-- 1 nobodynobody 1832960 Sep 13 14:12 iozone3_429.tar
drwxr-xr-x 2 nobodynobody 102 Sep 16 20:46lustre-client-el5.8-2.1.6
linux-x4xj:~ # ll /data2/
total 1792
-rwxr--r-- 1 nobodynobody 1832960 Sep 13 14:12 iozone3_429.tar
drwxr-xr-x 2 nobodynobody 102 Sep 16 20:46lustre-client-el5.8-2.1.6
linux-x4xj:~ #
◆只克隆/data下的子目录lustre-client-el5.8-2.1.6到/data2目录下,命令如下
linux-x4xj:~ #xfsdump - -s lustre-client-el5.8-2.1.6 /data | xfsrestore - /data2
或者
linux-x4xj:~ #xfsdump -l 0 - -s lustre-client-el5.8-2.1.6 /data | xfsrestore - /data2
linux-x4xj:~ # ll /data2/
total 0
drwxr-xr-x 2 nobodynobody 102 Sep 16 20:46 lustre-client-el5.8-2.1.6
linux-x4xj:~ #
3.查看会话存档
可以使用xfsdump -I来查看session存档
linux-x4xj:~ #xfsdump -I (从存档中选择了一个会话内容如下)
session 2:
mount point: linux-x4xj:/data
device: linux-x4xj:/dev/sdb
time: Tue Sep 16 20:58:58 2014
session label: "data_dump" (会话标识)
session id: ca3390ef-1a8c-429b-8d87-4e60d22d3c54
level: 0
resumed: NO
subtree: NO
streams: 1
stream 0:
pathname: /tmp/data_dump
start: ino 131 offset 0
end: ino 136 offset 0
interrupted: NO
media files: 1
media file 0:
mfileindex: 0
mfiletype: data
mfilesize: 70680352
mfilestart: ino 131 offset 0
mfile end: ino 136 offset 0
medialabel: "media0" (介质标识)
media id: 43881f83-231f-4835-a858-4d4ade150efe
4.使用xfsrestore恢复数据
★模拟删除/data目录内的所有内容,然后恢复数据
linux-x4xj:~ # rm -rf /data/*
linux-x4xj:~ #xfsrestore -f /tmp/data_dump /data
★根据会话标识,只恢复某个文件或者是子目录
linux-x4xj:~#xfsrestore -f /tmp/data_dump -L data_dump -s lustre-client-el5.8-2.1.6 /data
5.在没有进行恢复之前可以通过xfsrestore -f /tmp/data_dump -t查看data_dump内容
本文出自 “永不止步” 博客,谢绝转载!