Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to backup, restore and repair XFS

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to backup, restore and repair XFS. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

XFS is a high-performance file system. Because of its high performance, XFS has become the first choice for many enterprise systems, especially those with large amounts of data that require structured scalability and stability. For example, RHEL/CentOS 7 and Oracle Linux use XFS as the default file system, and SUSE/openSUSE has long supported XFS.

Backup and recovery of XFS file system

The XFS file system provides the entire partition backup tool xfsdump for users to use, and users can back up the data on the XFS file system without the help of third-party software.

Create XFS partitions and test files

[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 for help): pDisk / dev/sdb: 21.5GB, 21474836480 bytes 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x08a5199d Device Boot Start End Blocks Id SystemCommand (m for help): nPartition type: P primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): pFirst sector (2048-41943039, default 2048): Using default value 2048Last sector, + sectors or + size {KJM G} (2048-41943039) Default 41943039): + 1GPartition 1 of type Linux and of size 1 GiB is setCommand (m for help): pDisk / dev/sdb: 21.5GB, 21474836480 bytes 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x08a5199d Device Boot Start End Blocks Id System/dev/sdb1 2048 2099199 1048576 83 LinuxCommand (m for help): wThe partition table has been altered calling ioctl () to re-read partition table.Syncing disks. [root@localhost ~] # partprobeWarning: Unable to open / dev / sr0 read-write (Read-only file system). / dev/sr0 has been opened read-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=512 agcount=4, agsize=65536 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 Sparse=0data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=1log = internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime = none extsz=4096 blocks=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 00" > > / etc/fstab [root@localhost ~] # mount-a [root@localhost ~] # df-hFilesystem Size Used Avail Use% Mounted on/dev/mapper/rhel-root 17G 1.9G 16G 12% / devtmpfs 901M 0901m 0% / devtmpfs 912M 0912m 0% / dev/shmtmpfs 912M 8.7m 903m 1% / runtmpfs 912M 0912m 0% / sys/fs/cgroup/dev/sr0 3.8G 3.8G 0100% / yum/dev/sda1 1014M 143M 872m 15% / boottmpfs 183M 0 183M 0% / run/user/0/dev/sdb1 1014M 33M 982M 4% / file [root@localhost ~] # cd / file/ [root@localhost file] # ls [root@localhost file] # touch file {1.. 100} [root@localhost file] # lsfile1 file16 file23 file30 file38 file45 file52 file6 file67 file74 file81 file89 file96file10 file17 file24 file31 file39 file46 file53 file60 file68 file75 file82 file9 File97file100 file18 file25 file32 file4 file47 file54 file61 file69 file76 file83 file90 file98file11 file19 file26 file33 file40 file48 file55 file62 file7 file77 file84 file91 file99file12 file2 file27 file34 file41 file49 file56 file63 file70 file78 file85 file92file13 file20 file28 file35 file42 file5 file57 file64 file71 file79 file86 file93file14 file21 file29 file36 file43 file50 file58 file65 file72 file8 file87 file94file15 file22 file3 file37 file44 file51 file59 file66 file73 file80 file88 file95

Backup XFS Partition

[root@localhost file] # mkdir / backup [root@localhost file] # yum install-yxfsdump [root@localhost file] # xfsdump-f / backup/file.bak / file# using xfsdump backup mount point / file corresponding partition xfsdump: using file dump (drive_simple) strategyxfsdump: version 3.1.4 (dump format 3.0)-type ^ C for status and control== dump label dialog = = # enter dump session label please enter label for this dump session (timeout in 300 sec)-> file.baksession Label entered: "file.bak"-end dialog-xfsdump: level 0 dump of localhost.localdomain:/filexfsdump: dump date: Thu Oct 31 22:16:02 2019xfsdump: session id: 02a1445f-5ff3-4518-ab2c-888d9e2a4c44xfsdump: session label: "file.bak" xfsdump: ino map phase 1: constructing initial dump listxfsdump: ino map phase 2: skipping (no pruning necessary) xfsdump: ino map phase 3: skipping (only one dump stream) xfsdump: ino map construction completexfsdump: estimated dump size: 52800 bytes== media label dialog = = # enter media label please enter label for media in drive 0 (timeout in 300 sec)-> filemedia label entered: "file"-- -end dialog-xfsdump: creating dump session media file 0 (media 0 File 0) xfsdump: dumping ino mapxfsdump: dumping directoriesxfsdump: dumping non-directory filesxfsdump: ending media filexfsdump: media file size 86544 bytesxfsdump: dump size (non-dir files): 0 bytesxfsdump: dump complete: 27 seconds elapsedxfsdump: Dump Summary:xfsdump: stream 0 / backup/file.bak OK (success) xfsdump: Dump Status: SUCCESS [root@localhost file] # ls / backup/# has successfully created the backup file file.bak

Recovery process

[root@localhost file] # lsfile1 file16 file23 file30 file38 file45 file52 file6 file67 file74 file81 file89 file96file10 file17 file24 file31 file39 file46 file53 file60 file68 file75 file82 file9 file97file100 file18 file25 file32 file4 file47 file54 file61 file69 file76 file83 file90 file98file11 file19 file26 file33 file40 file48 file55 file62 file7 file77 file84 file91 file99file12 file2 file27 file34 file41 file49 file56 file63 file70 file78 file85 file92file13 file20 file28 file35 file42 file5 file57 file64 file71 file79 file86 file93file14 file21 file29 file36 file43 file50 file58 file65 file72 file8 file87 file94file15 file22 file3 file37 file44 file51 file59 file66 file73 file80 file88 file95 [root@localhost file ] # rm-rf * [root@localhost file] # ls [root@localhost file] # 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@localhost file] # ls# has successfully restored the deleted file file1 file16 file23 file30 file38 file45 file52 file6 file67 file74 file81 file89 file96file10 file17 file24 file31 file39 file46 file53 file60 file68 file75 file82 file9 file97file100 file18 file25 file32 file4 file47 file54 file61 file69 file76 file83 file90 file98file11 file19 file26 file33 file40 file48 file55 file62 file7 file77 file84 file91 file99file12 file2 file27 file34 file41 file49 file56 file63 file70 file78 file85 file92file13 file20 file28 file35 file42 file5 file57 file64 file71 file79 file86 file93file14 file21 file29 file36 file43 file50 file58 file65 file72 file8 file87 file94file15 file22 file3 file37 file44 file51 file59 file66 file73 file80 file88 file95 II. Check and repair of XFS file system

Create a XFS test partition

[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 for help): pDisk / dev/sdb: 21.5GB, 21474836480 bytes 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x08a5199d Device Boot Start End Blocks Id System/dev/sdb1 2048 2099199 1048576 83 LinuxCommand (m for help): nPartition type: P primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): pPartition number (2-4, default 2): First sector (2099200-41943039) Default 2099200): Using default value 2099200Last sector, + sectors or + size {K Magna M GB G} (2099200-41943039, default 41943039): + 1GPartition 2 of type Linux and of size 1 GiB is setCommand (m for help): pDisk / dev/sdb: 21.50 GB, 21474836480 bytes 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x08a5199d Device Boot Start End Blocks Id System/dev/sdb1 2048 2099199 1048576 83 Linux/dev/sdb2 2099200 4196351 1048576 83 LinuxCommand (m for help): wThe partition table has been altered calling ioctl () to re-read partition table .WARNING: Re-reading the partition table failed with error 16: Device or resource busy.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe (8) or kpartx (8) Syncing disks. [root@localhost file] # partprobeWarning: Unable to open / dev/sr0 read-write (Read-only file system). / dev/sr0 has been opened read-only. [root@localhost file] # ls / dev/sd*/dev/sda / dev/sda1 / dev/sda2 / dev/sdb / dev/sdb1 / dev/sdb2 [root@localhost file] # mkfs.xfs / dev/sdb2meta-data=/dev/sdb2 isize=512 agcount=4, agsize=65536 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 Sparse=0data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=1log = internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime = none extsz=4096 blocks=0, rtextents=0

Check the XFS file system and list if problems are found during the inspection

[root@localhost file] # xfs_repair-n / dev/sdb2Phase 1-find and verify superblock...Phase 2-using internal log-zero log... -scan filesystem freespace and inode maps... -found root inode chunkPhase 3-for each AG... -scan (but don't 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 = 3No modify flag set, skipping phase 5Phase 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.

Automatically check and repair the XFS file system

[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 chunkPhase 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 = 3Phase 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, this is the end of the article on "how to backup, restore and repair XFS". I hope the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good. Please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report