modify repair remove选哪个

厚德l留学网 0

XFS文件系统是硅谷图形公司(Silicon Graphics Inc,简称SGI)开发的用于IRIX(一个UNIX操作系统)的文件系统,后将XFS移植到Linux操作系统上。XFS是高级日志文件系统,其特点极具伸缩性,同时也很健壮。2000年5月XFS通过GNU通用公共许可证移植到Linux系统上,通过十多年的不断修改已经成为一款非常成熟的文件系统。在多项针对XFS的性能测试上,XFS都取得了不俗的成绩,高并发环境下甚至已经超过ext4。

一、XFS文件系统的备份与恢复

XFS文件系统提供了整个分区备份的工具xfsdump供用户使用,用户可以在不借助第三方软件的情况下对XFS文件系统上的数据实施备份。

创建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

Www.SpEAkkEy.cOm

备份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.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/已经成功创建备份文件file.bak

恢复过程

[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已经成功恢复被删除的文件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文件系统的检查和修复

Www.SpEAkkEy.cOm

创建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文件系统,如果检查过程中发现问题将会列出

[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.

自动检查并修复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