XFS文件系統是硅谷圖形公司(Silicon Graphics Inc,簡(jiǎn)稱(chēng)SGI)開(kāi)發(fā)的用于IRIX(一個(gè)UNIX操作系統)的文件系統,后將XFS移植到Linux操作系統上。XFS是高級日志文件系統,其特點(diǎn)極具伸縮性,同時(shí)也很健壯。2000年5月XFS通過(guò)GNU通用公共許可證移植到Linux系統上,通過(guò)十多年的不斷修改已經(jīng)成為一款非常成熟的文件系統。在多項針對XFS的性能測試上,XFS都取得了不俗的成績(jì),高并發(fā)環(huán)境下甚至已經(jīng)超過(guò)ext4。
一、XFS文件系統的備份與恢復
XFS文件系統提供了整個(gè)分區備份的工具xfsdump供用戶(hù)使用,用戶(hù)可以在不借助第三方軟件的情況下對XFS文件系統上的數據實(shí)施備份。
創(chuàng )建XFS分區及測試文件
[root@localhost ~]ls /dev/sd*/dev/sda /dev/sda1 /dev/sda2 /dev/sdb
[root@localhost ~]fdisk /dev/sdbWelcome 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.
Command (m forhelp): p
Disk /dev/sdb:21.5GB,21474836480bytes,41943040sectors
Units = sectorsof1*512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisk labeltype: dos
Disk identifier:0x08a5199dDevice BootStartEndBlocksIdSystemCommand (mforhelp): nPartitiontype:
p primary (0primary,0extended,4free)
eextendedSelect(defaultp): pFirstsector (2048-41943039,default2048):Usingdefaultvalue2048Lastsector, +sectorsor+size{K,M,G} (2048-41943039,default41943039): +1GPartition1oftypeLinuxandofsize1GiBissetCommand (mforhelp): p
Disk /dev/sdb:21.5GB,21474836480bytes,41943040sectors
Units = sectorsof1*512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisk labeltype: dos
Disk identifier:0x08a5199dDevice BootStartEndBlocksIdSystem/dev/sdb120482099199104857683Linux
Command (mforhelp): w
Thepartitiontablehas been altered!Callingioctl()tore-readpartitiontable.
Syncing disks.
[root@localhost ~]partprobeWarning: Unabletoopen/dev/sr0read-write (Read-onlyfilesystem). /dev/sr0 has been openedread-only.
[root@localhost ~]ls /dev/sd*/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1
[root@localhost ~]mkfs.xfs -f /dev/sdb1meta-data=/dev/sdb1 isize=512agcount=4, agsize=65536blks
= sectsz=512attr=2, projid32bit=1= crc=1finobt=0,sparse=0data= bsize=4096blocks=262144, imaxpct=25= sunit=0swidth=0blks
naming =version2bsize=4096ascii-ci=0ftype=1log=internallogbsize=4096blocks=2560,version=2= sectsz=512sunit=0blks, lazy-count=1realtime =noneextsz=4096blocks=0, rtextents=0[root@localhost ~]blkid /dev/sdb1/dev/sdb1:UUID="61a5e59d-92d3-458d-ac09-7d945469cda6"TYPE="xfs"[root@localhost ~]mkdir /file[root@localhost ~]echo "/dev/sdb1 /file xfs defaults 0 0" >> /etc/fstab[root@localhost ~]mount -a[root@localhost ~]df -hFilesystemSizeUsed AvailUse% Mountedon/dev/mapper/rhel-root17G1.9G16G12% /
devtmpfs901M0901M0% /dev
tmpfs912M0912M0% /dev/shm
tmpfs912M8.7M903M1% /run
tmpfs912M0912M0% /sys/fs/cgroup
/dev/sr03.8G3.8G0100% /yum
/dev/sda11014M143M872M15% /boot
tmpfs183M0183M0% /run/user/0/dev/sdb11014M33M982M4% /file[root@localhost ~]cd /file/[root@localhostfile]ls[root@localhostfile]touch file{1..100}[root@localhostfile]lsfile1 file16 file23 file30 file38 file45 file52 file6 file67 file74 file81 file89 file96
file10 file17 file24 file31 file39 file46 file53 file60 file68 file75 file82 file9 file97
file100 file18 file25 file32 file4 file47 file54 file61 file69 file76 file83 file90 file98
file11 file19 file26 file33 file40 file48 file55 file62 file7 file77 file84 file91 file99
file12 file2 file27 file34 file41 file49 file56 file63 file70 file78 file85 file92
file13 file20 file28 file35 file42 file5 file57 file64 file71 file79 file86 file93
file14 file21 file29 file36 file43 file50 file58 file65 file72 file8 file87 file94
file15 file22 file3 file37 file44 file51 file59 file66 file73 file80 file88 file95
備份XFS分區
[root@localhostfile]mkdir/backup[root@localhostfile]yuminstall-yxfsdump[root@localhostfile]xfsdump-f/backup/file.bak/file利用xfsdump備份掛載點(diǎn)/file對應的分區xfsdump:usingfiledump(drive_simple)strategyxfsdump:version3.1.4(dumpformat3.0)-type^Cforstatusandcontrol=============================dumplabeldialog==============================輸入dump會(huì )話(huà)標簽pleaseenterlabelforthisdumpsession(timeoutin300sec)->file.baksession label entered:"file.bak"---------------------------------enddialog---------------------------------xfsdump:level0dumpoflocalhost.localdomain:/filexfsdump: dump date:ThuOct3122:16:022019xfsdump: session id:02a1445f-5ff3-4518-ab2c-888d9e2a4c44xfsdump: session label:"file.bak"xfsdump: ino map phase 1:constructinginitialdumplistxfsdump: ino map phase 2:skipping(nopruningnecessary)xfsdump: ino map phase 3:skipping(onlyonedumpstream)xfsdump:inomapconstructioncompletexfsdump: estimated dump size:52800bytes=============================medialabeldialog=============================輸入媒體標簽pleaseenterlabelformediaindrive0(timeoutin300sec)->filemedia label entered:"file"---------------------------------enddialog---------------------------------xfsdump:creatingdumpsessionmediafile0(media0,file0)xfsdump:dumpinginomapxfsdump:dumpingdirectoriesxfsdump:dumpingnon-directoryfilesxfsdump:endingmediafilexfsdump:mediafilesize86544bytesxfsdump:dumpsize(non-dirfiles):0bytesxfsdump: dump complete:27secondselapsedxfsdump: Dump Summary:xfsdump:stream0/backup/file.bakOK(success)xfsdump: Dump Status:SUCCESS[root@localhostfile]ls/backup/已經(jīng)成功創(chuàng )建備份文件file.bak
恢復過(guò)程
[root@localhostfile] lsfile1file16 file23 file30 file38 file45 file52 file6 file67 file74 file81 file89 file96file10file17 file24 file31 file39 file46 file53 file60 file68 file75 file82 file9 file97file100file18 file25 file32 file4 file47 file54 file61 file69 file76 file83 file90 file98file11file19 file26 file33 file40 file48 file55 file62 file7 file77 file84 file91 file99file12file2 file27 file34 file41 file49 file56 file63 file70 file78 file85 file92file13file20 file28 file35 file42 file5 file57 file64 file71 file79 file86 file93file14file21 file29 file36 file43 file50 file58 file65 file72 file8 file87 file94file15file22 file3 file37 file44 file51 file59 file66 file73 file80 file88 file95[root@localhostfile] rm -rf *[root@localhostfile] ls[root@localhostfile] xfsrestore -f /backup/file.bak /filexfsrestore:using file dump (drive_simple) strategyxfsrestore:version 3.1.4 (dump format 3.0) - type ^C for status and controlxfsrestore:searching media for dumpxfsrestore:examining media file 0xfsrestore:dump description:xfsrestore:hostname: localhost.localdomainxfsrestore:mount point: /filexfsrestore:volume: /dev/sdb1xfsrestore:session time: Thu Oct 31 22:16:02 2019xfsrestore:level: 0xfsrestore:session label: "file.bak"xfsrestore:media label: "file"xfsrestore:file system id: 61a5e59d-92d3-458d-ac09-7d945469cda6xfsrestore:session id: 02a1445f-5ff3-4518-ab2c-888d9e2a4c44xfsrestore:media id: 2d1d9f33-dff3-4cfa-a2f6-bf65bd8f242bxfsrestore:using online session inventoryxfsrestore:searching media for directory dumpxfsrestore:reading directoriesxfsrestore:1 directories and 100 entries processedxfsrestore:directory post-processingxfsrestore:restoring non-directory filesxfsrestore:restore complete: 0 seconds elapsedxfsrestore:Restore Summary:xfsrestore:stream 0 /backup/file.bak OK (success)xfsrestore:Restore Status: SUCCESS[root@localhostfile] ls已經(jīng)成功恢復被刪除的文件file1file16 file23 file30 file38 file45 file52 file6 file67 file74 file81 file89 file96file10file17 file24 file31 file39 file46 file53 file60 file68 file75 file82 file9 file97file100file18 file25 file32 file4 file47 file54 file61 file69 file76 file83 file90 file98file11file19 file26 file33 file40 file48 file55 file62 file7 file77 file84 file91 file99file12file2 file27 file34 file41 file49 file56 file63 file70 file78 file85 file92file13file20 file28 file35 file42 file5 file57 file64 file71 file79 file86 file93file14file21 file29 file36 file43 file50 file58 file65 file72 file8 file87 file94file15file22 file3 file37 file44 file51 file59 file66 file73 file80 file88 file95
二、XFS文件系統的檢查和修復
創(chuàng )建XFS測試分區
[root@localhost file]fdisk /dev/sdbWelcome 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.
Command (m forhelp): p
Disk /dev/sdb:21.5GB,21474836480bytes,41943040sectors
Units = sectorsof1*512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisk labeltype: dos
Disk identifier:0x08a5199dDevice BootStartEndBlocksIdSystem/dev/sdb120482099199104857683Linux
Command (mforhelp): nPartitiontype:
p primary (1primary,0extended,3free)
eextendedSelect(defaultp): pPartitionnumber(2-4,default2):Firstsector (2099200-41943039,default2099200):Usingdefaultvalue2099200Lastsector, +sectorsor+size{K,M,G} (2099200-41943039,default41943039): +1GPartition2oftypeLinuxandofsize1GiBissetCommand (mforhelp): p
Disk /dev/sdb:21.5GB,21474836480bytes,41943040sectors
Units = sectorsof1*512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisk labeltype: dos
Disk identifier:0x08a5199dDevice BootStartEndBlocksIdSystem/dev/sdb120482099199104857683Linux
/dev/sdb220992004196351104857683Linux
Command (mforhelp): w
Thepartitiontablehas been altered!Callingioctl()tore-readpartitiontable.WARNING: Re-reading thepartitiontablefailedwitherror16: Deviceorresourcebusy.
The kernel still uses theoldtable. Thenewtablewill be usedatthenextrebootorafteryou run partprobe(8)orkpartx(8)
Syncing disks.
[root@localhostfile]partprobeWarning: Unabletoopen/dev/sr0read-write (Read-onlyfilesystem). /dev/sr0 has been openedread-only.
[root@localhostfile]ls /dev/sd*/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdb2
[root@localhostfile]mkfs.xfs /dev/sdb2meta-data=/dev/sdb2 isize=512agcount=4, agsize=65536blks
= sectsz=512attr=2, projid32bit=1= crc=1finobt=0,sparse=0data= bsize=4096blocks=262144, imaxpct=25= sunit=0swidth=0blks
naming =version2bsize=4096ascii-ci=0ftype=1log=internallogbsize=4096blocks=2560,version=2= sectsz=512sunit=0blks, lazy-count=1realtime =noneextsz=4096blocks=0, rtextents=0
檢查XFS文件系統,如果檢查過(guò)程中發(fā)現問(wèn)題將會(huì )列出
[root@localhost file] xfs_repair -n /dev/sdb2
Phase 1 - find and verify superblock...
Phase 2 - using internal log-zero log...-scan filesystem freespace and inode maps...-found root inode chunk
Phase 3 - for each AG...-scan (but dont clear) agi unlinked lists...-process known inodes and perform inode discovery...-agno = 0-agno = 1-agno = 2-agno = 3-process newly discovered inodes...
Phase 4 - check for duplicate blocks...-setting up duplicate extent list...-check for inodes claiming duplicate blocks...-agno = 0-agno = 1-agno = 2-agno = 3
No modify flag set, skipping phase 5
Phase 6 - check inode connectivity...-traversing filesystem ...-traversal finished ...-moving disconnected inodes to lost+found ...
Phase 7 - verify link counts...
No modify flag set, skipping filesystem flush and exiting.
自動(dòng)檢查并修復XFS文件系統
[root@localhost file] xfs_repair /dev/sdb2
Phase 1 - find and verify superblock...
Phase 2 - using internal log-zero log...-scan filesystem freespace and inode maps...-found root inode chunk
Phase 3 - for each AG...-scan and clear agi unlinked lists...-process known inodes and perform inode discovery...-agno = 0-agno = 1-agno = 2-agno = 3-process newly discovered inodes...
Phase 4 - check for duplicate blocks...-setting up duplicate extent list...-check for inodes claiming duplicate blocks...-agno = 0-agno = 1-agno = 2-agno = 3
Phase 5 - rebuild AG headers and trees...-reset superblock...
Phase 6 - check inode connectivity...-resetting contents of realtime bitmap and summary inodes-traversing filesystem ...-traversal finished ...-moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done