extundelete工具僅可以恢復EXT類型的文件,無法恢復CentOS 7系統默認采用xfs類型的文件。針對xfs文件系統目前也沒有比較成熟的文件恢復工具,所以建議提前做好數據備份,以避免數據丟失。
xfs類型的文件可使用xfsdump與xfsrestore工具進行備份恢復。若系統中未安裝xfsdump與xfsrestore工具,可以通過yum install -y xfsdump命令安裝。xfsdump按照inode順序備份一個xfs文件系統。
xfsdump的備份級別有兩種:0表示完全備份;1-9表示增量備份。默認為0。
用法及基本參數:
xfsdump -f 備份存放位置 要備份路徑或設備文件
-f:指定備份文件目錄 -L:指定標簽session label -M:指定設備標簽media label -s:備份單個文件,-s后面不能直接跟路徑。
使用xfsdump時,需要注意以下的幾個限制:
1.xfsdump不支持沒有掛載的文件系統備份,所以只能備份已掛載的; 2.xfsdump必須使用root的權限才能操作(涉及文件系統的關系); 3.xfsdump只能備份XFS文件系統; 4.xfsdump備份下來的數據(檔案或儲存媒體)只能讓xfsrestore解析; 5.xfsdump是透過文件系統的UUID來分辨各個備份檔的,因此不能備份兩個具有相同UUID的文件系統。
xfsrestore -f 恢復文件的位置 存放恢復后文件的路徑
測試實例
前期准備
1、准備測試分區
vm虛擬機添加一塊盤,格式化、分區
[root@master ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). 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 Building a new DOS disklabel with disk identifier 0x6af1f974. Command (m for help): n Partition number (1-128, default 1): 1 First sector (2048-41943006, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943006, default 41943006): +10G Created partition 1 Command (m for help): p Disk /dev/sdb: 21.5 GB, 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 Disk label type: gpt Disk identifier: CFF6D029-AE1C-4D43-8673-34243A25651C # Start End Size Type Name 1 2048 20973567 10G Linux filesyste Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
創建文件系統,掛載
[root@master ~]# mkfs.xfs /dev/sdb1 meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2621440, 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 [root@master ~]# mkdir /mnt/xfs/ [root@master ~]# mount -t xfs /dev/sdb1 /mnt/xfs [root@master ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 901M 0 901M 0% /dev tmpfs 911M 0 911M 0% /dev/shm tmpfs 911M 9.6M 902M 2% /run tmpfs 911M 0 911M 0% /sys/fs/cgroup /dev/sda3 98G 2.0G 96G 3% / /dev/sda1 1014M 135M 880M 14% /boot tmpfs 183M 0 183M 0% /run/user/0 /dev/sdb1 10G 33M 10G 1% /mnt/xfs
安裝軟件、創建文件
[root@master ~]# echo "1234" >> /mnt/xfs/num.txt [root@master ~]# mkdir /mnt/xfs/test [root@master ~]# echo "test" >> /mnt/xfs/test/num.txt
[root@master ~]# yum install -y xfsdump Loaded plugins: fastestmirror
備份數據
[root@master ~]# xfsdump -f /backup/dump_sdb1 /dev/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 master:/mnt/xfs xfsdump: dump date: Mon Apr 6 02:39:40 2020 xfsdump: session id: c378e1cd-7b83-4082-8c9e-23b81846a2f5 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: 29952 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 24056 bytes xfsdump: dump size (non-dir files) : 1088 bytes xfsdump: dump complete: 38 seconds elapsed xfsdump: Dump Summary: xfsdump: stream 0 /backup/dump_sdb1 OK (success) xfsdump: Dump Status: SUCCESS
查看備份信息
[root@master ~]# xfsdump -I file system 0: fs id: 3c9dc4de-31ff-4092-8540-d8eae0b2c1d3 session 0: mount point: master:/mnt/xfs device: master:/dev/sdb1 time: Mon Apr 6 02:39:40 2020 session label: "dump_sdb1" session id: c378e1cd-7b83-4082-8c9e-23b81846a2f5 level: 0 resumed: NO subtree: NO streams: 1 stream 0: pathname: /backup/dump_sdb1 start: ino 67 offset 0 end: ino 70 offset 0 interrupted: NO media files: 1 media file 0: mfile index: 0 mfile type: data mfile size: 24056 mfile start: ino 67 offset 0 mfile end: ino 70 offset 0 media label: "sdb1" media id: 32613bce-0fb1-4fd5-bd81-2166246de691 xfsdump: Dump Status: SUCCESS
模擬誤刪除數據
[root@master ~]# rm -f /mnt/xfs/* -r [root@master ~]# ll /mnt/xfs/ total 0
恢復文件
[root@master ~]# xfsrestore -f /backup/dump_sdb1 /mnt/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: master xfsrestore: mount point: /mnt/xfs xfsrestore: volume: /dev/sdb1 xfsrestore: session time: Mon Apr 6 02:39:40 2020 xfsrestore: level: 0 xfsrestore: session label: "dump_sdb1" xfsrestore: media label: "sdb1" xfsrestore: file system id: 3c9dc4de-31ff-4092-8540-d8eae0b2c1d3 xfsrestore: session id: c378e1cd-7b83-4082-8c9e-23b81846a2f5 xfsrestore: media id: 32613bce-0fb1-4fd5-bd81-2166246de691 xfsrestore: using online session inventory xfsrestore: searching media for directory dump xfsrestore: reading directories xfsrestore: 2 directories and 3 entries processed xfsrestore: directory post-processing xfsrestore: restoring non-directory files xfsrestore: restore complete: 0 seconds elapsed xfsrestore: Restore Summary: xfsrestore: stream 0 /backup/dump_sdb1 OK (success) xfsrestore: Restore Status: SUCCESS [root@master ~]# ll /mnt/xfs/ num.txt test/ [root@master ~]# ll /mnt/xfs/test/ total 4 -rw-r--r--. 1 root root 5 Apr 6 02:35 num.txt