linux基于xfs文件系统实现数据备份和恢复

本文详细介绍了如何在Linux系统中,特别是CentOS环境下,使用xfsdump和xfsrestore工具对XFS文件系统进行备份和恢复。内容涵盖了完全备份、增量备份的概念、操作步骤以及注意事项,包括环境准备、备份级别、免交互备份、指定目录备份、恢复文件系统等关键环节。
摘要由CSDN通过智能技术生成

实战:xfs文件系统的备份和恢复

XFS文件系统

  • centos7选择xfs格式作为默认文件系统,而且不再使用以前的ext,仍然支持ext4,
  • xfs专为大数据产生,每个单个文件系统最大可以支持8eb,单个文件可以支持16tb,不仅数据量大,而且扩展性高。
  • 还可以通过xfsdump,xfsrestore来备份和恢复。

XFS备份 恢复工具

  • XFS提供了 xfsdump 和 xfsrestore 工具协助备份XFS文件系统中的数据。xfsdump 按inode顺序备份一个XFS文件系统。

  • 与传统的UNIX文件系统不同,XFS不需要在备份前被卸载;对使用中的XFS文件系统做备份就可以保证镜像的一致性。XFS的备份和恢复的过程是可以被中断然后继续的,无须冻结文件系统。xfsdump 甚至提供了高性能的多线程备份操作——它把一次dump拆分成多个数据流,每个数据流可以被发往不同的目的地

xfsdump的备份级别

首先了解一下xfsdump的备份级别有以下两种,默认为0(即完全备份)

  • 0 级别代表: 完全备份
  • 1 到9级别代表: 增量备份

扩展:

  • 完全备份:每次都把指定的备份目录完整的复制一遍,不管目录下的文件有没有变化;
  • 增量备份:每次将之前(第一次、第二次、直到前一次)做过备份之后有变化的文件进行备份;
  • 差异备份:每次都将第一次完整备份以来有变化的文件进行备份。

环境准备

实验环境

系统CetnOS8 添加一块虚拟硬盘(准备一个测试分区)
正常使用一块磁盘过程如下:
添加磁盘大小:2G ->分区->格式化->挂载

  1. 虚拟机新增2G硬盘
  2. 开机后查看设备
    使用fdisk -l查看新增硬盘
Last login: Tue Oct 20 04:13:20 2020 from 10.0.0.1
[root@C8-3 ~]# fdisk -l
Disk /dev/sda: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xbfcdb101

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1  *       2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200 41943039 39843840  19G 8e Linux LVM


Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 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
  1. 给新增硬盘分区
[root@C8-3 ~]# fdisk /dev/sdb #使用fdisk命令分区

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x467c42d4.

Command (m for help): m #查看有哪些命令可以用

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): n #选择新建一个分区
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p #创建主分区
Partition number (1-4, default 1):  #直接回车默认值
First sector (2048-4194303, default 2048):  #起始扇区,回车默认
Last sector, +sectors or +size{
   K,M,G,T,P} (2048-4194303, default 4194303):  #结束扇区,回车默认分配全部空间

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): w #将以上操作写入硬盘分区表,结束分区
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@C8-3 ~]# lsblk #查看分区是否成功
NAME        MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda           8:0    0  20G  0 disk 
├─sda1        8:1    0   1G  0 part /boot
└─sda2        8:2    0  19G  0 part 
  ├─cl-root 253:0    0  17G  0 lvm  /
  └─cl-swap 253:1    0   2G  0 lvm  [SWAP]
sdb           8:16   0   2G  0 disk 
└─sdb1        8:17   0   2G  0 part  #分区成功但未挂载

  1. 将新建分区格式化为xfs格式
    使用mkfs.xfs格式化新分区
[root@C8-3 ~]# type mkfs.xfs #查看是否有此工具
mkfs.xfs is /usr/sbin/mkfs.xfs
[root@C8-3 ~]# mkfs.xfs --help #查看命令的帮助
mkfs.xfs: invalid option -- '-'
unknown option -- 
Usage: mkfs.xfs
/* blocksize */		[-b size=num]
/* metadata */		[-m crc=0|1,finobt=0|1,uuid=xxx,rmapbt=0|1,reflink=0|1]
/* data subvol */	[-d agcount=n,agsize=n,file,name=xxx,size=num,
			    (sunit=value,swidth=value|su=num,sw=num|noalign),
			    sectsize=num
/* force overwrite */	[-f]
/* inode size */	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值