概述
XFS提供了 xfsdump 和 xfsrestore 工具協助備份XFS檔案系統中的資料。xfsdump 按inode順序備份一個XFS檔案系統。
centos7選擇xfs格式作為預設檔案系統,而且不再使用以前的ext,仍然支援ext4,xfs專為大資料產生,每個單個檔案系統最大可以支援8eb,單個檔案可以支援16tb,不僅資料量大,而且擴充套件性高。還可以通過xfsdump,xfsrestore來備份和恢復。
與傳統的UNIX檔案系統不同,XFS不需要在備份前被解除安裝;對使用中的XFS檔案系統做備份就可以保證映象的一致性。XFS的備份和恢復的過程是可以被中斷然後繼續的,無須凍結檔案系統。xfsdump 甚至提供了高效能的多執行緒備份操作——它把一次dump拆分成多個資料流,每個資料流可以被髮往不同的目的地
首先了解一下xfsdump的備份級別有以下兩種,預設為0(即完全備份)
- 0 級別代表: 完全備份
- 1 到9級別代表: 增量備份
擴充套件:
- 完全備份:每次都把指定的備份目錄完整的複製一遍,不管目錄下的檔案有沒有變化;
- 增量備份:每次將之前(第一次、第二次、直到前一次)做過備份之後有變化的檔案進行備份;
- 差異備份:每次都將第一次完整備份以來有變化的檔案進行備份。
環境準備
實驗環境
系統CENTOS8 新增一塊虛擬硬碟(準備一個測試分割槽)
正常使用一塊磁碟過程如下:
新增磁碟大小:2G ->分割槽->格式化->掛載
- 虛擬機器新增2G硬碟
- 開機後檢視裝置
使用fdisk -l檢視新增硬碟
Last login: Tue Oct 20 04:13:20 2020 from 10.0.0.1
[root@C8-3 ~]# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xbfcdb101
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 2099199 2097152 1G 83 Linux
/dev/sda2 2099200 41943039 39843840 19G 8e Linux LVM
Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
- 給新增硬碟分割槽
[root@C8-3 ~]# fdisk /dev/sdb #使用fdisk命令分割槽
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x467c42d4.
Command (m for help): m #檢視有哪些命令可以用
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): n #選擇新建一個分割槽
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p #建立主分割槽
Partition number (1-4, default 1): #直接回車預設值
First sector (2048-4194303, default 2048): #起始扇區,回車預設
Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): #結束扇區,回車預設分配全部空間
Created a new partition 1 of type 'Linux' and of size 2 GiB.
Command (m for help): w #將以上操作寫入硬碟分割槽表,結束分割槽
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@C8-3 ~]# lsblk #檢視分割槽是否成功
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─cl-root 253:0 0 17G 0 lvm /
└─cl-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 2G 0 disk
└─sdb1 8:17 0 2G 0 part #分割槽成功但未掛載
- 將新建分割槽格式化為xfs格式
使用mkfs.xfs格式化新分割槽
[root@C8-3 ~]# type mkfs.xfs #檢視是否有此工具
mkfs.xfs is /usr/sbin/mkfs.xfs
[root@C8-3 ~]# mkfs.xfs --help #檢視命令的幫助
mkfs.xfs: invalid option -- '-'
unknown option --
Usage: mkfs.xfs
/* blocksize */ [-b size=num]
/* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx,rmapbt=0|1,reflink=0|1]
/* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,
(sunit=value,swidth=value|su=num,sw=num|noalign),
sectsize=num
/* force overwrite */ [-f]
/* inode size */ [-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,
projid32bit=0|1,sparse=0|1]
/* no discard */ [-K]
/* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx,version=n
sunit=value|su=num,sectsize=num,lazy-count=0|1]
/* label */ [-L label (maximum 12 characters)]
/* naming */ [-n size=num,version=2|ci,ftype=0|1]
/* no-op info only */ [-N]
/* prototype file */ [-p fname]
/* quiet */ [-q]
/* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]
/* sectorsize */ [-s size=num]
/* version */ [-V]
devicename
<devicename> is required unless -d name=xxx is given.
<num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),
xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).
<value> is xxx (512 byte blocks).
[root@C8-3 ~]# mkfs.xfs -V #檢視命令版本
mkfs.xfs version 5.0.0
[root@C8-3 ~]# mkfs.xfs /dev/sdb1 #格式化新分割槽
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=131008 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=524032, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
- 檢視新分割槽情況
使用lsblk及引數-f檢視分割槽情況和檔案系統
-f, --fs output info about filesystems
[root@C8-3 ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 ext4 8df39f81-d4b1-4881-9bb4-51f8f6ee964a /boot
└─sda2 LVM2_member mQQNpB-AMy6-Ad3M-3RNh-NeRf-8tf9-OmosY7
├─cl-root xfs 8dbc40ac-24cf-45c9-8c53-d07ac9cee558 /
└─cl-swap swap ffc54438-efdc-45d7-a244-b9e9bfef4930 [SWAP]
sdb
└─sdb1 xfs d549d0dd-23a2-4223-abe5-96055a8f737a
- 建立一個目錄並將新分割槽sdb1掛載到此目錄
[root@C8-3 ~]# mkdir /xfsTest
[root@C8-3 ~]# mount /dev/sdb1 /xfsTest/
[root@C8-3 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─cl-root 253:0 0 17G 0 lvm /
└─cl-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 2G 0 disk
└─sdb1 8:17 0 2G 0 part /xfsTest
建立測試檔案和資料夾
[root@C8-3 ~]# rm -rf /xfsTest/*
[root@C8-3 ~]# ls /xfsTest/
[root@C8-3 ~]# cp /etc/passwd /xfsTest/
[root@C8-3 ~]# touch /xfsTest/file{1..3}{a..b}.txt
[root@C8-3 ~]# mkdir -p /xfsTest/m{1..3}/n{a..b}
[root@C8-3 ~]# tree /xfsTest/
/xfsTest/
├── file1a.txt
├── file1b.txt
├── file2a.txt
├── file2b.txt
├── file3a.txt
├── file3b.txt
├── m1
│ ├── na
│ └── nb
├── m2
│ ├── na
│ └── nb
├── m3
│ ├── na
│ └── nb
└── passwd
9 directories, 7 files
備份
使用xfsdump命令進行備份
先檢視xfsdump幫助
[root@C8-3 ~]# type xfsdump
xfsdump is /usr/sbin/xfsdump
[root@C8-3 ~]# xfsdump --help
xfsdump: version 3.1.8 (dump format 3.0)
xfsdump: usage: xfsdump [ -a (dump DMF dualstate files as offline) ]
……
備份整個分割槽。 (這個功能就像是虛擬機器的快照,伺服器被黑後,進行快速恢復)
[ -f <destination> ... ]
xfsdump -f 備份存放位置 要備份路徑或裝置檔案
注意:備份的路徑這裡不能寫成/xfsTest/。 可以是/dev/sdb1 或/xfsTest
[root@C8-3 ~]# xfsdump -f /opt/dump_sdb1 /dev/sdb1
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (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 C8-3:/xfsTest
xfsdump: dump date: Tue Oct 20 08:09:38 2020
xfsdump: session id: 3fdced05-235f-4926-9409-7c7e4081da84
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: 30016 bytes
============================= 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 32936 bytes
xfsdump: dump size (non-dir files) : 1568 bytes
xfsdump: dump complete: 70 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /opt/dump_sdb1 OK (success)
xfsdump: Dump Status: SUCCESS
免互動自動備份 像虛擬機器的快照
如果分割槽很大,資料很多,可能等的時間會很久,才會跳出提示輸入的介面,這樣不靠譜又沒什麼太大意義的提示會中斷很久。
免互動才是真的自動化。
指定備份時免互動操作,方便後期做定時備份
[root@C8-3 ~]# time xfsdump -f /opt/dump_sdb1_3 /dev/sdb1 -L dump_1_3 -M 1_3
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control
xfsdump: level 0 dump of C8-3:/xfsTest
xfsdump: dump date: Tue Oct 20 08:21:12 2020
xfsdump: session id: 5308f2ab-6d0e-476f-9160-a72a37e56ca9
xfsdump: session label: "dump_1_3"
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: 30016 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 32936 bytes
xfsdump: dump size (non-dir files) : 1568 bytes
xfsdump: dump complete: 10 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /opt/dump_sdb1_3 OK (success)
xfsdump: Dump Status: SUCCESS
real 0m10.058s
user 0m0.000s
sys 0m0.004s
-L :xfsdump 記錄每次備份的 session 標頭,這裡可以填寫針對此檔案系統的簡易說明
-M :xfsdump 可以記錄儲存媒體的標頭,這裡可以填寫此媒體的簡易說明
備份指定目錄
引數:-s 檔案路徑 只對指定的檔案進行備份,-s指定時,路徑寫的是相對檔案系統根的路徑(-s可以是檔案或目錄)
要對/xfsTest下的m2/nb這個目錄(完整路徑是/xfsTest/m2/nb 直接寫這個不行)進行備份,使用-s 引數
[root@C8-3 ~]# xfsdump -f /opt/dump_m2nb -s m2/nb /xfsTest -L dump_m2nb -M m2nb
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control
xfsdump: level 0 dump of C8-3:/xfsTest
xfsdump: dump date: Tue Oct 20 10:04:58 2020
xfsdump: session id: 4cd18dc2-9a10-4538-b93c-3d4169c13eae
xfsdump: session label: "dump_m2nb"
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 22592 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 10 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /opt/dump_m2nb OK (success)
xfsdump: Dump Status: SUCCESS
檢視備份資訊與內容
[root@C8-3 xfsTest]# xfsdump -I
file system 0:
fs id: d549d0dd-23a2-4223-abe5-96055a8f737a
session 0:
mount point: C8-3:/xfsTest
device: C8-3:/dev/sdb1
time: Tue Oct 20 08:09:38 2020
session label: "dump_sdb1"
session id: 3fdced05-235f-4926-9409-7c7e4081da84
level: 0
resumed: NO
subtree: NO
streams: 1
stream 0:
pathname: /opt/dump_sdb1
start: ino 131 offset 0
end: ino 138 offset 0
interrupted: NO
media files: 1
media file 0:
mfile index: 0
mfile type: data
mfile size: 32936
mfile start: ino 131 offset 0
mfile end: ino 138 offset 0
media label: "sdb1"
media id: 77e98c40-d588-4562-b801-6ba7dd2425bf
session 1:
mount point: C8-3:/xfsTest
device: C8-3:/dev/sdb1
time: Tue Oct 20 08:17:18 2020
session label: "dump_passwd"
session id: e9970178-7a24-4c9d-b9c0-7e13f8d43c48
level: 0
resumed: NO
subtree: NO
streams: 1
stream 0:
pathname: /opt/dump_sdb1
start: ino 0 offset 0
end: ino 0 offset 0
interrupted: YES
media files: 0
session 2:
mount point: C8-3:/xfsTest
device: C8-3:/dev/sdb1
time: Tue Oct 20 08:19:23 2020
session label: "dump_12"
session id: 391b7c46-47f6-4760-b454-c7835045db09
level: 0
resumed: NO
subtree: NO
streams: 1
stream 0:
pathname: /opt/dump_sdb1
start: ino 0 offset 0
end: ino 0 offset 0
interrupted: YES
media files: 0
session 3:
mount point: C8-3:/xfsTest
device: C8-3:/dev/sdb1
time: Tue Oct 20 08:20:12 2020
session label: "dump_12"
session id: d6613e91-8c68-4f40-b68b-e836fdf35568
level: 0
resumed: NO
subtree: NO
streams: 1
stream 0:
pathname: /opt/dump_sdb1_1
start: ino 131 offset 0
end: ino 138 offset 0
interrupted: NO
media files: 1
media file 0:
mfile index: 0
mfile type: data
mfile size: 32936
mfile start: ino 131 offset 0
mfile end: ino 138 offset 0
media label: "12"
media id: f85b0aff-d362-429c-9804-0ca1071f812f
session 4:
mount point: C8-3:/xfsTest
device: C8-3:/dev/sdb1
time: Tue Oct 20 08:21:12 2020
session label: "dump_1_3"
session id: 5308f2ab-6d0e-476f-9160-a72a37e56ca9
level: 0
resumed: NO
subtree: NO
streams: 1
stream 0:
pathname: /opt/dump_sdb1_3
start: ino 131 offset 0
end: ino 138 offset 0
interrupted: NO
media files: 1
media file 0:
mfile index: 0
mfile type: data
mfile size: 32936
mfile start: ino 131 offset 0
mfile end: ino 138 offset 0
media label: "1_3"
media id: 78304c29-4353-4edc-a3cb-63454d898918
xfsdump: Dump Status: SUCCESS
刪除已備份的檔案
[root@C8-3 xfsTest]# cd
[root@C8-3 ~]# rm -rf /xfsTest/*
[root@C8-3 ~]# ls -a /xfsTest/
. ..
恢復檔案系統
語法:xfsrestore -f 指定恢復檔案的位置 指定存放恢復後的檔案的路徑
[root@C8-3 ~]# mkdir /xfsTest-re #在其他分割槽建立恢復資料夾
[root@C8-3 ~]# xfsrestore -f /opt/dump_sdb1 /xfsTest-re
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.8 (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: C8-3
xfsrestore: mount point: /xfsTest
xfsrestore: volume: /dev/sdb1
xfsrestore: session time: Tue Oct 20 08:09:38 2020
xfsrestore: level: 0
xfsrestore: session label: "dump_sdb1"
xfsrestore: media label: "sdb1"
xfsrestore: file system id: d549d0dd-23a2-4223-abe5-96055a8f737a
xfsrestore: session id: 3fdced05-235f-4926-9409-7c7e4081da84
xfsrestore: media id: 77e98c40-d588-4562-b801-6ba7dd2425bf
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 10 directories and 16 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_sdb1 OK (success)
xfsrestore: Restore Status: SUCCESS
[root@C8-3 ~]# ll /xfsTest-re/ #檢視恢復的檔案
total 4
-rw-r--r--. 1 root root 0 Oct 20 07:58 file1a.txt
-rw-r--r--. 1 root root 0 Oct 20 07:58 file1b.txt
-rw-r--r--. 1 root root 0 Oct 20 07:58 file2a.txt
-rw-r--r--. 1 root root 0 Oct 20 07:58 file2b.txt
-rw-r--r--. 1 root root 0 Oct 20 07:58 file3a.txt
-rw-r--r--. 1 root root 0 Oct 20 07:58 file3b.txt
drwxr-xr-x. 4 root root 26 Oct 20 07:59 m1
drwxr-xr-x. 4 root root 26 Oct 20 07:59 m2
drwxr-xr-x. 4 root root 26 Oct 20 07:59 m3
-rw-r--r--. 1 root root 1469 Oct 20 07:58 passwd
[root@C8-3 ~]# tree /xfsTest #對比源目錄啥也沒有了
/xfsTest
0 directories, 0 files
[root@C8-3 ~]# tree /xfsTest-re/ #在恢復的目錄中重建了目錄結構
/xfsTest-re/
├── file1a.txt
├── file1b.txt
├── file2a.txt
├── file2b.txt
├── file3a.txt
├── file3b.txt
├── m1
│ ├── na
│ └── nb
├── m2
│ ├── na
│ └── nb
├── m3
│ ├── na
│ └── nb
└── passwd
9 directories, 7 files
注:
使用 xfsdump 時,請注意下面下面的幾個限制:
- xfsdump 不支援沒有掛載的檔案系統備份!所以只能備份已掛載的!
- xfsdump 必須使用 root 的許可權才能操作 (涉及檔案系統的關係)
- xfsdump 只能備份 XFS 檔案系統
- xfsdump 備份下來的資料 (檔案或儲存媒體) 只能讓 xfsrestore 解析
- xfsdump 是透過檔案系統的 UUID 來分辨各個備份檔的,因此不能備份兩個具有相同 UUID 的檔案系統
增量備份
概念
增量備份是指在一次全備份或上一次增量備份後,以後每次的備份只需備份與前一次相比增加或者被修改的檔案。這就意味著,第一次增量備份的物件是進行全備後所產生的增加和修改的檔案;第二次增量備份的物件是進行第一次增量備份後所產生的增加和修改的檔案,以此類推。
優缺點
- 優點:沒有重複的備份資料,因此備份的資料量不大,備份所需的時間很短。
- 缺點:資料恢復相對比較麻煩,它需要上一次全備份和所有增量備份的內容才能夠完全恢復成功,並且它們必須沿著從全備份到依次增量備份的時間順序逐個反推恢復,因此可能會延長的恢復時間
準備一個需要備份的目錄
[root@C8-3 ~]# tree /xfsTest
/xfsTest
├── m1
│ ├── na
│ └── nb
├── m2
│ ├── na
│ └── nb
├── m3
│ ├── na
│ └── nb
└── passwd
進行一次全面備份
[root@C8-3 ~]# xfsdump -f /opt/xFull /xfsTest -L xF1 -M x1
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control
xfsdump: level 0 dump of C8-3:/xfsTest
xfsdump: dump date: Tue Oct 20 10:43:59 2020
xfsdump: session id: 4bc4262b-afa1-493f-8b21-33428325961d
xfsdump: session label: "xF1"
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: 28096 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 29000 bytes
xfsdump: dump size (non-dir files) : 1568 bytes
xfsdump: dump complete: 10 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /opt/xFull OK (success)
xfsdump: Dump Status: SUCCESS
新增一些東西進去
[root@C8-3 ~]# echo hellow >> /xfsTest/passwd
[root@C8-3 ~]# touch /xfsTest/nb3.txt
刪掉一些東西
[root@C8-3 ~]# rm -rf /xfsTest/m2
[root@C8-3 ~]# ls /xfsTest
m1 m3 nb3.txt passwd
[root@C8-3 ~]# ll /xfsTest
total 4
drwxr-xr-x. 4 root root 26 Oct 20 07:59 m1
drwxr-xr-x. 4 root root 26 Oct 20 07:59 m3
-rw-r--r--. 1 root root 0 Oct 20 10:47 nb3.txt
-rw-r--r--. 1 root root 1476 Oct 20 10:46 passwd
進行第一次增量備份
[root@C8-3 ~]# xfsdump -l 1 -f /opt/xBL1 /xfsTest -L xBL1 -M xB1
進行第二次增量備份
新增點東西、再刪點東西
[root@C8-3 ~]# mkdir /xfsTest/xBl2
[root@C8-3 ~]# rm -rf /xfsTest/m3
然後接茬進行一次2級增量備份
[root@C8-3 ~]# xfsdump -l 2 -f /opt/xBL2 /xfsTest -L xBL2 -M xB2
刪除已備份的所有資料
[root@C8-3 ~]# rm -rf /xfsTest/*
[root@C8-3 ~]# ll /xfsTest
total 0
恢復資料
現在進行恢復,要想恢復全部全部資料,包括新新增的檔案,如何恢復?
步驟:
1、先恢復完全備份
2、情況1: 恢復最後一次增量備份(如果兩次增量備份都是1級的,所以只需要恢復最後一個增量就可以了。
3、情況2:如果你做的是第一次是1級備,第二次是2級備,那麼你在恢復的時候就需要先恢復完全備份,然後是1級備,最後是2級備)
直接恢復最後一次增量備份
[root@C8-3 ~]# xfsrestore -f /opt/xBL2 /xfsTest
[root@C8-3 ~]# tree /xfsTest
/xfsTest
└── xBl2
發現只恢復了最後一次建立的資料夾
直接恢復第一次增量備份
[root@C8-3 ~]# rm -rf /xfsTest/*
[root@C8-3 ~]# ll /xfsTest
total 0
[root@C8-3 ~]# xfsrestore -f /opt/xBL1 /xfsTest
[root@C8-3 ~]# tree /xfsTest
/xfsTest
├── nb3.txt
└── passwd
發現只恢復了第一次增量備份前新增和修改的檔案、資料夾
直接恢復第一次全備份
[root@C8-3 ~]# xfsrestore -f /opt/xFull /xfsTest
[root@C8-3 ~]# tree /xfsTest
/xfsTest
├── m1
│ ├── na
│ └── nb
├── m2
│ ├── na
│ └── nb
├── m3
│ ├── na
│ └── nb
└── passwd
9 directories, 1 file
[root@C8-3 ~]# ll /xfsTest
total 4
drwxr-xr-x. 4 root root 26 Oct 20 07:59 m1
drwxr-xr-x. 4 root root 26 Oct 20 07:59 m2
drwxr-xr-x. 4 root root 26 Oct 20 07:59 m3
-rw-r--r--. 1 root root 1469 Oct 20 07:58 passwd
這時候就恢復到了第一次增量備份之前的狀態
如果要恢復到最後刪除所有檔案時候的狀態,就需要按順序依次恢復增量一和增量二的備份內容。
到此,資料恢復成功了。