怎么对XFS进行备份、恢复、修复
这篇文章将为大家详细讲解有关怎么对XFS进行备份、恢复、修复,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
XFS是高性能文件系统,由于它的高性能,XFS成为了许多企业级系统的首选,特别是有大量数据,需要结构化伸缩性和稳定性的。例如,RHEL/CentOS 7 和Oracle Linux将XFS作为默认文件系统,SUSE/openSUSE已经为XFS做了长期支持。
一、XFS文件系统的备份与恢复XFS文件系统提供了整个分区备份的工具xfsdump供用户使用,用户可以在不借助第三方软件的情况下对XFS文件系统上的数据实施备份。
创建XFS分区及测试文件
[root@localhost~]#ls/dev/sd*/dev/sda/dev/sda1/dev/sda2/dev/sdb[root@localhost~]#fdisk/dev/sdbWelcometofdisk(util-linux2.23.2).Changeswillremaininmemoryonly,untilyoudecidetowritethem.Becarefulbeforeusingthewritecommand.Command(mforhelp):pDisk/dev/sdb:21.5GB,21474836480bytes,41943040sectorsUnits=sectorsof1*512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:0x08a5199dDeviceBootStartEndBlocksIdSystemCommand(mforhelp):nPartitiontype:pprimary(0primary,0extended,4free)eextendedSelect(defaultp):pFirstsector(2048-41943039,default2048):Usingdefaultvalue2048Lastsector,+sectorsor+size{K,M,G}(2048-41943039,default41943039):+1GPartition1oftypeLinuxandofsize1GiBissetCommand(mforhelp):pDisk/dev/sdb:21.5GB,21474836480bytes,41943040sectorsUnits=sectorsof1*512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:0x08a5199dDeviceBootStartEndBlocksIdSystem/dev/sdb120482099199104857683LinuxCommand(mforhelp):wThepartitiontablehasbeenaltered!Callingioctl()tore-readpartitiontable.Syncingdisks.[root@localhost~]#partprobeWarning:Unabletoopen/dev/sr0read-write(Read-onlyfilesystem)./dev/sr0hasbeenopenedread-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/sdb1isize=512agcount=4,agsize=65536blks=sectsz=512attr=2,projid32bit=1=crc=1finobt=0,sparse=0data=bsize=4096blocks=262144,imaxpct=25=sunit=0swidth=0blksnaming=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/filexfsdefaults00">>/etc/fstab[root@localhost~]#mount-a[root@localhost~]#df-hFilesystemSizeUsedAvailUse%Mountedon/dev/mapper/rhel-root17G1.9G16G12%/devtmpfs901M0901M0%/devtmpfs912M0912M0%/dev/shmtmpfs912M8.7M903M1%/runtmpfs912M0912M0%/sys/fs/cgroup/dev/sr03.8G3.8G0100%/yum/dev/sda11014M143M872M15%/boottmpfs183M0183M0%/run/user/0/dev/sdb11014M33M982M4%/file[root@localhost~]#cd/file/[root@localhostfile]#ls[root@localhostfile]#touchfile{1..100}[root@localhostfile]#lsfile1file16file23file30file38file45file52file6file67file74file81file89file96file10file17file24file31file39file46file53file60file68file75file82file9file97file100file18file25file32file4file47file54file61file69file76file83file90file98file11file19file26file33file40file48file55file62file7file77file84file91file99file12file2file27file34file41file49file56file63file70file78file85file92file13file20file28file35file42file5file57file64file71file79file86file93file14file21file29file36file43file50file58file65file72file8file87file94file15file22file3file37file44file51file59file66file73file80file88file95
备份XFS分区
[root@localhostfile]#mkdir/backup[root@localhostfile]#yuminstall-yxfsdump[root@localhostfile]#xfsdump-f/backup/file.bak/file#利用xfsdump备份挂载点/file对应的分区xfsdump:usingfiledump(drive_simple)strategyxfsdump:version3.1.4(dumpformat3.0)-type^Cforstatusandcontrol=============================dumplabeldialog==============================#输入dump会话标签pleaseenterlabelforthisdumpsession(timeoutin300sec)->file.baksessionlabelentered:"file.bak"---------------------------------enddialog---------------------------------xfsdump:level0dumpoflocalhost.localdomain:/filexfsdump:dumpdate:ThuOct3122:16:022019xfsdump:sessionid:02a1445f-5ff3-4518-ab2c-888d9e2a4c44xfsdump:sessionlabel:"file.bak"xfsdump:inomapphase1:constructinginitialdumplistxfsdump:inomapphase2:skipping(nopruningnecessary)xfsdump:inomapphase3:skipping(onlyonedumpstream)xfsdump:inomapconstructioncompletexfsdump:estimateddumpsize:52800bytes=============================medialabeldialog=============================#输入媒体标签pleaseenterlabelformediaindrive0(timeoutin300sec)->filemedialabelentered:"file"---------------------------------enddialog---------------------------------xfsdump:creatingdumpsessionmediafile0(media0,file0)xfsdump:dumpinginomapxfsdump:dumpingdirectoriesxfsdump:dumpingnon-directoryfilesxfsdump:endingmediafilexfsdump:mediafilesize86544bytesxfsdump:dumpsize(non-dirfiles):0bytesxfsdump:dumpcomplete:27secondselapsedxfsdump:DumpSummary:xfsdump:stream0/backup/file.bakOK(success)xfsdump:DumpStatus:SUCCESS[root@localhostfile]#ls/backup/#已经成功创建备份文件file.bak
恢复过程
[root@localhostfile]#lsfile1file16file23file30file38file45file52file6file67file74file81file89file96file10file17file24file31file39file46file53file60file68file75file82file9file97file100file18file25file32file4file47file54file61file69file76file83file90file98file11file19file26file33file40file48file55file62file7file77file84file91file99file12file2file27file34file41file49file56file63file70file78file85file92file13file20file28file35file42file5file57file64file71file79file86file93file14file21file29file36file43file50file58file65file72file8file87file94file15file22file3file37file44file51file59file66file73file80file88file95[root@localhostfile]#rm-rf*[root@localhostfile]#ls[root@localhostfile]#xfsrestore-f/backup/file.bak/filexfsrestore:usingfiledump(drive_simple)strategyxfsrestore:version3.1.4(dumpformat3.0)-type^Cforstatusandcontrolxfsrestore:searchingmediafordumpxfsrestore:examiningmediafile0xfsrestore:dumpdescription:xfsrestore:hostname:localhost.localdomainxfsrestore:mountpoint:/filexfsrestore:volume:/dev/sdb1xfsrestore:sessiontime:ThuOct3122:16:022019xfsrestore:level:0xfsrestore:sessionlabel:"file.bak"xfsrestore:medialabel:"file"xfsrestore:filesystemid:61a5e59d-92d3-458d-ac09-7d945469cda6xfsrestore:sessionid:02a1445f-5ff3-4518-ab2c-888d9e2a4c44xfsrestore:mediaid:2d1d9f33-dff3-4cfa-a2f6-bf65bd8f242bxfsrestore:usingonlinesessioninventoryxfsrestore:searchingmediafordirectorydumpxfsrestore:readingdirectoriesxfsrestore:1directoriesand100entriesprocessedxfsrestore:directorypost-processingxfsrestore:restoringnon-directoryfilesxfsrestore:restorecomplete:0secondselapsedxfsrestore:RestoreSummary:xfsrestore:stream0/backup/file.bakOK(success)xfsrestore:RestoreStatus:SUCCESS[root@localhostfile]#ls#已经成功恢复被删除的文件file1file16file23file30file38file45file52file6file67file74file81file89file96file10file17file24file31file39file46file53file60file68file75file82file9file97file100file18file25file32file4file47file54file61file69file76file83file90file98file11file19file26file33file40file48file55file62file7file77file84file91file99file12file2file27file34file41file49file56file63file70file78file85file92file13file20file28file35file42file5file57file64file71file79file86file93file14file21file29file36file43file50file58file65file72file8file87file94file15file22file3file37file44file51file59file66file73file80file88file95二、XFS文件系统的检查和修复
创建XFS测试分区
[root@localhostfile]#fdisk/dev/sdbWelcometofdisk(util-linux2.23.2).Changeswillremaininmemoryonly,untilyoudecidetowritethem.Becarefulbeforeusingthewritecommand.Command(mforhelp):pDisk/dev/sdb:21.5GB,21474836480bytes,41943040sectorsUnits=sectorsof1*512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:0x08a5199dDeviceBootStartEndBlocksIdSystem/dev/sdb120482099199104857683LinuxCommand(mforhelp):nPartitiontype:pprimary(1primary,0extended,3free)eextendedSelect(defaultp):pPartitionnumber(2-4,default2):Firstsector(2099200-41943039,default2099200):Usingdefaultvalue2099200Lastsector,+sectorsor+size{K,M,G}(2099200-41943039,default41943039):+1GPartition2oftypeLinuxandofsize1GiBissetCommand(mforhelp):pDisk/dev/sdb:21.5GB,21474836480bytes,41943040sectorsUnits=sectorsof1*512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:0x08a5199dDeviceBootStartEndBlocksIdSystem/dev/sdb120482099199104857683Linux/dev/sdb220992004196351104857683LinuxCommand(mforhelp):wThepartitiontablehasbeenaltered!Callingioctl()tore-readpartitiontable.WARNING:Re-readingthepartitiontablefailedwitherror16:Deviceorresourcebusy.Thekernelstillusestheoldtable.Thenewtablewillbeusedatthenextrebootorafteryourunpartprobe(8)orkpartx(8)Syncingdisks.[root@localhostfile]#partprobeWarning:Unabletoopen/dev/sr0read-write(Read-onlyfilesystem)./dev/sr0hasbeenopenedread-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/sdb2isize=512agcount=4,agsize=65536blks=sectsz=512attr=2,projid32bit=1=crc=1finobt=0,sparse=0data=bsize=4096blocks=262144,imaxpct=25=sunit=0swidth=0blksnaming=version2bsize=4096ascii-ci=0ftype=1log=internallogbsize=4096blocks=2560,version=2=sectsz=512sunit=0blks,lazy-count=1realtime=noneextsz=4096blocks=0,rtextents=0
检查XFS文件系统,如果检查过程中发现问题将会列出
[root@localhostfile]#xfs_repair-n/dev/sdb2Phase1-findandverifysuperblock...Phase2-usinginternallog-zerolog...-scanfilesystemfreespaceandinodemaps...-foundrootinodechunkPhase3-foreachAG...-scan(butdon'tclear)agiunlinkedlists...-processknowninodesandperforminodediscovery...-agno=0-agno=1-agno=2-agno=3-processnewlydiscoveredinodes...Phase4-checkforduplicateblocks...-settingupduplicateextentlist...-checkforinodesclaimingduplicateblocks...-agno=0-agno=1-agno=2-agno=3Nomodifyflagset,skippingphase5Phase6-checkinodeconnectivity...-traversingfilesystem...-traversalfinished...-movingdisconnectedinodestolost+found...Phase7-verifylinkcounts...Nomodifyflagset,skippingfilesystemflushandexiting.
自动检查并修复XFS文件系统
[root@localhostfile]#xfs_repair/dev/sdb2Phase1-findandverifysuperblock...Phase2-usinginternallog-zerolog...-scanfilesystemfreespaceandinodemaps...-foundrootinodechunkPhase3-foreachAG...-scanandclearagiunlinkedlists...-processknowninodesandperforminodediscovery...-agno=0-agno=1-agno=2-agno=3-processnewlydiscoveredinodes...Phase4-checkforduplicateblocks...-settingupduplicateextentlist...-checkforinodesclaimingduplicateblocks...-agno=0-agno=1-agno=2-agno=3Phase5-rebuildAGheadersandtrees...-resetsuperblock...Phase6-checkinodeconnectivity...-resettingcontentsofrealtimebitmapandsummaryinodes-traversingfilesystem...-traversalfinished...-movingdisconnectedinodestolost+found...Phase7-verifyandcorrectlinkcounts...done
关于“怎么对XFS进行备份、恢复、修复”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。