网易首页 > 网易号 > 正文 申请入驻

Linux中XFS文件系统的备份,恢复,修复

0
分享至

Linux中XFS文件系统的备份,恢复,修复

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

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: dos

Disk identifier: 0x08a5199d

Device Boot Start End Blocks Id System

Command (m for help): n

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p): p

First sector (2048-41943039, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +1G

Partition 1 of type Linux and of size 1 GiB is set

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: dos

Disk identifier: 0x08a5199d

Device Boot Start End Blocks Id System

/dev/sdb1 2048 2099199 1048576 83 Linux

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@localhost ~]# partprobe

Warning: 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/sdb1

meta-data=/dev/sdb1 isize=512 agcount=4, agsize=65536 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0, sparse=0

data = bsize=4096 blocks=262144, 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@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 -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/rhel-root 17G 1.9G 16G 12% /

devtmpfs 901M 0 901M 0% /dev

tmpfs 912M 0 912M 0% /dev/shm

tmpfs 912M 8.7M 903M 1% /run

tmpfs 912M 0 912M 0% /sys/fs/cgroup

/dev/sr0 3.8G 3.8G 0 100% /yum

/dev/sda1 1014M 143M 872M 15% /boot

tmpfs 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]# ls

file1 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@localhost file]# mkdir /backup

[root@localhost file]# yum install -y xfsdump

[root@localhost file]# xfsdump -f /backup/file.bak /file

#利用xfsdump备份挂载点/file对应的分区

xfsdump: using file dump (drive_simple) strategy

xfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and control

============================= dump label dialog ==============================

#输入dump会话标签

please enter label for this dump session (timeout in 300 sec)

-> file.bak

session label entered: "file.bak"

--------------------------------- end dialog ---------------------------------

xfsdump: level 0 dump of localhost.localdomain:/file

xfsdump: dump date: Thu Oct 31 22:16:02 2019

xfsdump: session id: 02a1445f-5ff3-4518-ab2c-888d9e2a4c44

xfsdump: session label: "file.bak"

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: 52800 bytes

============================= media label dialog =============================

please enter label for media in drive 0 (timeout in 300 sec)

-> file

media label entered: "file"

--------------------------------- 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 86544 bytes

xfsdump: dump size (non-dir files) : 0 bytes

xfsdump: dump complete: 27 seconds elapsed

xfsdump: Dump Summary:

xfsdump: stream 0 /backup/file.bak OK (success)

xfsdump: Dump Status: SUCCESS

[root@localhost file]# ls /backup/

#已经成功创建备份文件

file.bak

恢复过程

[root@localhost file]# ls

file1 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

[root@localhost file]# rm -rf *

[root@localhost file]# ls

[root@localhost file]# xfsrestore -f /backup/file.bak /file

xfsrestore: using file dump (drive_simple) strategy

xfsrestore: version 3.1.4 (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: localhost.localdomain

xfsrestore: mount point: /file

xfsrestore: volume: /dev/sdb1

xfsrestore: session time: Thu Oct 31 22:16:02 2019

xfsrestore: level: 0

xfsrestore: session label: "file.bak"

xfsrestore: media label: "file"

xfsrestore: file system id: 61a5e59d-92d3-458d-ac09-7d945469cda6

xfsrestore: session id: 02a1445f-5ff3-4518-ab2c-888d9e2a4c44

xfsrestore: media id: 2d1d9f33-dff3-4cfa-a2f6-bf65bd8f242b

xfsrestore: using online session inventory

xfsrestore: searching media for directory dump

xfsrestore: reading directories

xfsrestore: 1 directories and 100 entries processed

xfsrestore: directory post-processing

xfsrestore: restoring non-directory files

xfsrestore: restore complete: 0 seconds elapsed

xfsrestore: Restore Summary:

xfsrestore: stream 0 /backup/file.bak OK (success)

xfsrestore: Restore Status: SUCCESS

[root@localhost file]# ls

#已经成功恢复被删除的文件

file1 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文件系统的检查和修复

创建XFS测试分区

[root@localhost file]# 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.

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: dos

Disk identifier: 0x08a5199d

Device Boot Start End Blocks Id System

/dev/sdb1 2048 2099199 1048576 83 Linux

Command (m for help): n

Partition type:

p primary (1 primary, 0 extended, 3 free)

e extended

Select (default p): p

Partition number (2-4, default 2):

First sector (2099200-41943039, default 2099200):

Using default value 2099200

Last sector, +sectors or +size{K,M,G} (2099200-41943039, default 41943039): +1G

Partition 2 of type Linux and of size 1 GiB is set

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: dos

Disk identifier: 0x08a5199d

Device Boot Start End Blocks Id System

/dev/sdb1 2048 2099199 1048576 83 Linux

/dev/sdb2 2099200 4196351 1048576 83 Linux

Command (m for help): w

The 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 at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@localhost file]# partprobe

Warning: 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/sdb2

meta-data=/dev/sdb2 isize=512 agcount=4, agsize=65536 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0, sparse=0

data = bsize=4096 blocks=262144, 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

检查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 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 = 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

原文来自:Linux就该这么学

原文链接:https://www.linuxprobe.com/linux-xargs-usage.html

特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。

Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.

相关推荐
热点推荐
长城这一炮,彻底炸蒙了整个汽车圈!

长城这一炮,彻底炸蒙了整个汽车圈!

户外小阿隋
2024-04-24 06:58:48
湖人G3开始前,浓眉正式下令,詹姆斯立下目标,皮尔斯落井下石

湖人G3开始前,浓眉正式下令,詹姆斯立下目标,皮尔斯落井下石

体坛大辣椒
2024-04-24 09:49:08
斩首真主党指挥官,准备撤离拉法巴勒斯坦人,哈马斯结局毫无悬念

斩首真主党指挥官,准备撤离拉法巴勒斯坦人,哈马斯结局毫无悬念

山河路口
2024-04-23 20:13:22
周星驰将首次参与综艺节目制作,网友:期待

周星驰将首次参与综艺节目制作,网友:期待

红星新闻
2024-04-23 22:09:14
最新战报!丁俊晖连战连捷,小司机仅得1分,囧哥开门红,冲7连胜

最新战报!丁俊晖连战连捷,小司机仅得1分,囧哥开门红,冲7连胜

刘姚尧的文字城堡
2024-04-23 17:48:40
长沙女生称遭同学殴打“割喉自救”,嫌疑人被传唤!检方介入

长沙女生称遭同学殴打“割喉自救”,嫌疑人被传唤!检方介入

南方都市报
2024-04-24 09:41:30
2024年第一季度全国反腐成绩单公布!

2024年第一季度全国反腐成绩单公布!

新京报
2024-04-24 09:27:16
北京东城区的教育现状(高中篇),佛系

北京东城区的教育现状(高中篇),佛系

手工制作阿爱
2024-04-24 07:35:21
我国已做好最坏打算,一旦俄战败,我们必须做好四件事,哪四件?

我国已做好最坏打算,一旦俄战败,我们必须做好四件事,哪四件?

零点历史说
2024-04-02 11:50:41
《城中之城》:一块胎记暴露周琳太脏,才懂田晓慧为何当不了吴太

《城中之城》:一块胎记暴露周琳太脏,才懂田晓慧为何当不了吴太

汤汤慢
2024-04-23 21:23:36
刘少奇最后见毛主席恳请结束文革,不然辞职回家种地,毛主席如何回复?

刘少奇最后见毛主席恳请结束文革,不然辞职回家种地,毛主席如何回复?

史论纵横
2023-04-26 21:12:18
成耀东刚从国奥下课,就迅速敲定新去向,未来将去冠军豪门挑大梁

成耀东刚从国奥下课,就迅速敲定新去向,未来将去冠军豪门挑大梁

罗掌柜体育
2024-04-23 17:48:51
浓眉暴怒:“我受够了”!末节1出手!20分钟0分...

浓眉暴怒:“我受够了”!末节1出手!20分钟0分...

篮球大图
2024-04-23 14:16:28
周琦肘击李金效面部,会不会停赛?CBA记者:可能停赛2场+罚款

周琦肘击李金效面部,会不会停赛?CBA记者:可能停赛2场+罚款

体育哲人
2024-04-24 12:50:39
你是否也曾怀念?克里斯-保罗现身快船主场观看老东家比赛

你是否也曾怀念?克里斯-保罗现身快船主场观看老东家比赛

懂球帝
2024-04-24 10:31:12
今晚开播!34集民国谍战剧来袭,这是《追风者》后我最想追的剧

今晚开播!34集民国谍战剧来袭,这是《追风者》后我最想追的剧

娱乐百灵鸟V3
2024-04-24 13:00:03
她被称为中国黄金身材,巅峰期退圈结婚,丈夫身份特殊到不方便说

她被称为中国黄金身材,巅峰期退圈结婚,丈夫身份特殊到不方便说

简读视觉
2024-04-11 20:00:03
汪小菲官宣将改变对孩子的态度,大S始料未及,或主动把孩子归还

汪小菲官宣将改变对孩子的态度,大S始料未及,或主动把孩子归还

西瓜叨娱乐
2024-04-24 00:44:49
在国米夺冠庆祝活动中,巴雷拉和恰尔汗奥卢阻止球迷们辱骂特奥

在国米夺冠庆祝活动中,巴雷拉和恰尔汗奥卢阻止球迷们辱骂特奥

直播吧
2024-04-24 06:26:09
杨颖李晨突然空降热搜,被曝十年友情已转化为爱情,评论区已乱套

杨颖李晨突然空降热搜,被曝十年友情已转化为爱情,评论区已乱套

叶二娱评
2024-04-21 14:19:43
2024-04-24 13:58:44
孙有匪
孙有匪
科技
1595文章数 2009关注度
往期回顾 全部

科技要闻

特斯拉财报差劲 但马斯克做出一个重磅表态

头条要闻

内蒙古"农民种地交钱"涉事干部被指学历造假 官方调查

头条要闻

内蒙古"农民种地交钱"涉事干部被指学历造假 官方调查

体育要闻

足智多谋的哈姆,温水里的青蛙

娱乐要闻

方媛带两女儿参加婚礼,当花童超可爱

财经要闻

周鸿祎雷军大和解,为了拯救哪吒?

汽车要闻

升级L2+级驾辅系统 2024款猛龙售16.58万起

态度原创

艺术
家居
房产
数码
公开课

艺术要闻

艺术名画︱爱尔兰画家大卫·科因的刀画作品

家居要闻

光影之间 空间暖意打造生活律动

房产要闻

供应量环跌71%!海口这个月又只发了5张证!

数码要闻

荣耀MagicBook Pro 16 HUNTER版笔记本推送AI高性能静音模式

公开课

睡前进食会让你发胖吗?

无障碍浏览 进入关怀版