centos 7 下的xfs文件的备份与恢复


请读者跳过此段,此段为小博主整理的内容,没有详细讲解:

备份:xfsdump -f /opt/dump-dir /media/cdrom 
不是(/media/cdrom/)
脚本备份:xfsdump -f /opt/dump-dir /media/cdrom -L dump-sh-dir -M sh-dir
部分目录、文件备份:xfsdump -f /opt/dump--sh-wenjian -s wenjian /media/cdrom -L dump-sh-wenjian -M sh-wenjian
增量备份:
xfsdump -l 1 -f /opt/dump--sh-dir1 /media/cdrom -L dump-sh-dir1 -M sh-dir1
xfsdump -l 2 -f /opt/dump--sh-dir2 /media/cdrom -L dump-sh-dir2 -M sh-dir2
恢复:xfsrestore -f /opt/dump-dir 需要恢复到那个文件夹
xfsrestore -f /opt/dump-dir ./

 


正文:

为了简化整个过程,小博主这里选择增加一块新的分区,并只给予其1个G的空间大小:

备份

xfsdump -f 备份文件  需要备份的文件

xfsdump -f /opt/dump /media/cdrom

错误示范:xfsdump -f /opt/dump /media/cdrom/        (是.../cdrom 不是.../cdrom/)

在新增加的磁盘上划分1个G,并挂载至/media/cdrom下面

挂载情况如下:

[root@localhost ~]# df -hT
文件系统                类型      容量  已用  可用 已用% 挂载点
......
/dev/sdb1               xfs      1014M   33M  982M    4% /media/cdrom

创建一个文件夹和一个多个子文件

[root@localhost cdrom]# pwd
/media/cdrom
[root@localhost cdrom]# ls
[root@localhost cdrom]# mkdir wenjian
[root@localhost cdrom]# vim 1.txt
[root@localhost cdrom]# vim 2.txt
[root@localhost cdrom]# cd wenjian/
[root@localhost wenjian]# vim 1
[root@localhost wenjian]# vim 2
[root@localhost wenjian]# cd ..
[root@localhost cdrom]# find .
.
./wenjian
./wenjian/1
./wenjian/2
./1.txt
./2.txt

使用xfsdump备份命令,所以的内容备份至/opt/dump-dir下

[root@localhost cdrom]# xfsdump -f /opt/dump-dir /media/cdrom
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.4 (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-dir #输入标签        
session label entered: "dump-dir"

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

xfsdump: level 0 dump of localhost.localdomain:/media/cdrom
xfsdump: dump date: Fri Sep 14 16:03:17 2018
xfsdump: session id: 73baa490-32c2-4ee3-afcf-e8ae7fc556b7
xfsdump: session label: "dump-dir"
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: 22400 bytes

 ============================= media label dialog =============================

please enter label for media in drive 0 (timeout in 300 sec)
 -> dir #注释
media label entered: "dir"

 --------------------------------- 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 24256 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 15 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /opt/dump-dir OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost cdrom]# ls /opt/
dump-dir  rh

备份成功!

但是,我们平常使用备份命令的时候,都是使用脚本定时备份,那么中间输入标签和注释就会导致备份需要人为跟进,这并不是我们需要的,所以,我们需要在备份的过程中,让其跳过输入的过程:

使用以下命令:(主要是-L和-M)

[root@localhost cdrom]# xfsdump -f /opt/dump--sh-dir /media/cdrom -L dump-sh-dir -M sh-dir
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.4 (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 localhost.localdomain:/media/cdrom
xfsdump: dump date: Fri Sep 14 16:21:11 2018
xfsdump: session id: c1292efc-b783-41c5-ae3b-f1df342f34ff
xfsdump: session label: "dump-sh-dir"
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: 22400 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 24256 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /opt/dump--sh-dir OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost cdrom]# ls /opt/
dump-dir  dump--sh-dir  rh

当然,有时候我们也许只准备备份一个目录,而不是所有的文件,我们可以用下面命令来执行

[root@localhost cdrom]# ls
1.txt  2.txt  wenjian
[root@localhost cdrom]# xfsdump -f /opt/dump--sh-wenjian -s wenjian /media/cdrom -L dump-sh-wenjian -M sh-wenjian
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and control
xfsdump: level 0 dump of localhost.localdomain:/media/cdrom
xfsdump: dump date: Fri Sep 14 16:24:05 2018
xfsdump: session id: f997126c-08f0-4d56-baef-f68574626250
xfsdump: session label: "dump-sh-wenjian"
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: 21760 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 23008 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /opt/dump--sh-wenjian OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost cdrom]# ls /opt/
dump-dir  dump--sh-dir  dump--sh-wenjian  rh

增量备份:

好了,现在问题来了,小博主第一天创建了一个a.txt文本,第二天创建了一个在/media/cdrom/wenjian下创建了a.txt文本,如果/media/cdrom文件很大,按照上面的做法就是备份全部文件,而文件只是增加了一个a.txt,所以我们需要用到增量备份

[root@localhost cdrom]# vim a.txt
[root@localhost cdrom]# find .
.
./wenjian
./wenjian/1
./wenjian/2
./1.txt
./2.txt
./a.txt
[root@localhost cdrom]# xfsdump -l 1 -f /opt/dump--sh-dir1 /media/cdrom -L dump-sh-dir1 -M sh-dir1
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and control
xfsdump: level 1 incremental dump of localhost.localdomain:/media/cdrom based on level 0 dump begun Fri Sep 14 16:21:11 2018
xfsdump: dump date: Fri Sep 14 16:30:24 2018
xfsdump: session id: 484fd518-e7a3-4f4f-bd49-ad13570b882f
xfsdump: session label: "dump-sh-dir1"
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: 21440 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 22408 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /opt/dump--sh-dir1 OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost cdrom]# ls /opt/
dump-dir  dump--sh-dir  dump--sh-dir1  dump--sh-wenjian  rh

dump--sh-dir1是dump-dir的增量备份,级别一级

[root@localhost cdrom]# vim wenjian/a.txt
[root@localhost cdrom]# find .
.
./wenjian
./wenjian/1
./wenjian/2
./wenjian/a.txt
./1.txt
./2.txt
./a.txt
[root@localhost cdrom]# xfsdump -l 2 -f /opt/dump--sh-dir2 /media/cdrom -L dump-sh-dir2 -M sh-dir2
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and control
xfsdump: level 2 incremental dump of localhost.localdomain:/media/cdrom based on level 1 dump begun Fri Sep 14 16:30:24 2018
xfsdump: dump date: Fri Sep 14 16:31:53 2018
xfsdump: session id: c3c686c1-8cda-4069-b404-8a9cf2a14612
xfsdump: session label: "dump-sh-dir2"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: pruning unneeded subtrees
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 21440 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 22432 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /opt/dump--sh-dir2 OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost cdrom]# ls /opt/
dump-dir  dump--sh-dir  dump--sh-dir1  dump--sh-dir2  dump--sh-wenjian  rh

二级备份dump--sh-dir2

注意:恢复从二级到一级,如果都是一级备份,按最好一次的备份文件恢复即可,当然,首先要恢复完整备份


恢复:

[root@localhost cdrom]# ls
1.txt  2.txt  a.txt  wenjian
[root@localhost cdrom]# rm -rf *
[root@localhost cdrom]# ls
[root@localhost cdrom]# xfsrestore -f /opt/dump-dir ./
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.4 (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: /media/cdrom
xfsrestore: volume: /dev/sdb1
xfsrestore: session time: Fri Sep 14 16:05:04 2018
xfsrestore: level: 0
xfsrestore: session label: "dump-dir"
xfsrestore: media label: "dir"
xfsrestore: file system id: f3be7c4c-1c3b-4522-96f1-219a68c3421b
xfsrestore: session id: b99f416c-d9d6-4b70-b4c8-598ad3250ea5
xfsrestore: media id: 5ed60d57-7a56-458d-847d-54f7b23149a6
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 2 directories and 5 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /opt/dump-dir OK (success)
xfsrestore: Restore Status: SUCCESS
[root@localhost cdrom]# ls
1.txt  2.txt  wenjian
[root@localhost cdrom]# find .
.
./wenjian
./wenjian/1
./wenjian/2
./1.txt
./2.txt

需要注意的是,增量备份只是备份了增加的,所以恢复的时候要先恢复原本的,在恢复增加的!

你可能感兴趣的:(Centos,Linux)