XFS文件系统

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

建议在RHEL7/CentOS7系统上操作

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

XFS文件系统文件恢复与备份相关推荐

  1. 【Windows数据恢复】Fat32和NTFS文件系统文件恢复

    目录 一.磁盘存储结构 (一)分区表 1.MBR 分区表(主引导记录Master Boot Record , mbr) 小实验:将磁盘改为活动分区 2.GPT 分区表(全局唯一标识分区表GUID Pa ...

  2. linux xfs文件误删除恢复_linux系统文件误删除恢复

    在linux系统运维工作中,经常会遇到因操作不慎,操作错误等导致文件数据丢失的情况.这里所指的是彻底删除,即已经不能通过"回收站"找回的情况,比如使用"rm -rf&qu ...

  3. Oracle 【IT实验室】数据库备份与恢复之:如何对Oracle数据库文件进行恢复与备份...

    任何数据库在长期使用过程中,都会存在一定的安全隐患.对于数据库管理员来说不能仅寄希望于计算机操作系统的安全运行,而是要建立一整套的数据库备份与恢复机制.当数据库发生故障后,希望能重新建立一个完整的数据 ...

  4. win10误删文件怎么恢复

    win10误删文件怎么恢复?长时间使用电脑,误删文件这是我们难以避免的.可能是自己看错而删除的,或者是点错文件而误删的.但不管如何,只要删除了对自己有一定重要性的文件,就希望能够把它找回.那要如何做才 ...

  5. 【AWSL】之Linux文件系统与日志分析(inode、恢复EXT类型的文件、恢复XFS类型的文件)

    序言 这里我主要介绍Linux文件系统与日志分析 文件系统与日志分析 序言 一.inode与block 1. 概述 ①inode的内容 ②inode号码 ③文件存储 ④inode的大小 ⑤inode的 ...

  6. 远程linux还原本地bak文件,Linux -- 服务器数据备份恢复策略

    一.Linux 备份恢复基础 1.什么是备份 最简单的讲,备份数据的过程就是拷贝重要的数据到其他的介质之上(通常是可移动的),以保证在原始数据丢失的情况下可以恢复数据.一次备份可能是简单的 cp命令, ...

  7. Linux之XFS文件恢复

    xfs类型文件备份恢复 我们使用的centos 7 默认使用的是xfs 类型文件系统,可以用xfsdump 与 xfsrestore 工具进行备份恢复. xfsdump 的备份级别:0 :表示完全备份 ...

  8. undo表空间文件丢失恢复(4)--无备份无recover的情况下恢复

    undo表空间的数据文件丢失,如果没有备份的情况下,而且丢失的undo文件可以置为offline状态后(注意是offline不是recover状态),则可以如下恢复,下边给出一个例子. undo表空间 ...

  9. ORACLE基础学习-RMAN应用之(归档模式无备份,丢失数据文件的恢复)

    二.归档模式无备份,丢失数据文件的恢复: 首先要意识到,这种恢复是有条件的,只有在某些特定条件下,才有可能在没有备份的情况下恢复丢失的数据文件. 同时又需意识到不是所有丢失的文件都是可以被成功恢复的. ...

最新文章

  1. vs2005格式化代码
  2. python趣味编程_第6章 旋转的方块(《Python趣味创意编程》教学视频)
  3. 【Kaggle】Intermediate Machine Learning(缺失值+文字特征处理)
  4. 通过Nginx反向代理,实现远程调试本机代码
  5. union all查询统计总数量
  6. 演说之禅:演说中的图效优势
  7. 菜鸟谷歌浏览器打印组件技术分析
  8. Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”:报错解决
  9. 第十六篇:关于Unity开发WebGL遇到的坑
  10. svn提示没有设置冲突_SVN冲突解决方法大全
  11. php面试题大全及答案
  12. Android应用推广渠道分享
  13. python matplotlib x轴日期显示问题。matplotlib 坐标轴设置文本间隔,matplotlib 坐标轴过于密集、无法实现其他功能。
  14. 学生信息管理系统-web项目实训(基于JAVA)
  15. U-Boot参数设置 .
  16. ubuntu20.04虚拟机使用水星mw150us无线usb接口网卡
  17. java设计校园网登录界面_java毕业设计_springboot框架的校园网的大学生社交网站...
  18. 这可能是你们都在找的:React 纯原生纯hook多标签微前端
  19. 【WINDOWS / DOS 批处理】for命令详解(八)
  20. 上市公司内控信息披露指数(2000-2018年)

热门文章

  1. 博客园电子期刊2012年10月刊发布啦
  2. Android ToolBar设定为ifRoom的menu不显示图标的问题
  3. 中国人保为北京洁美克工贸有限公司承保产品责任险,为消费者保驾护航
  4. 大话设计模式学习笔记(6)——装饰模式
  5. 使用golang每天给自己发送一封天气预报的邮件
  6. 访问学者申请关于免签和返签
  7. 企业生产网计算机网络时间同步(NTP授时服务器)
  8. 多人过河问题C语言贪心算法,贪心算法----过河问题
  9. 彻底实现Linux TCP的Pacing发送逻辑-普通timer版
  10. 人脸识别套件中在线版人脸识别与离线版人脸识别的区别