linux implements data backup and recovery based on xfs file system

Actual Warfare: Backup and Recovery of xfs File System

XFS file system

  • centos7 chooses the xfs format as the default file system and no longer uses the previous ext but still supports ext4.
  • xfs are designed for large data generation. Each single file system can support up to 8eb, and a single file can support 16tb, which is not only data intensive but also scalable.
  • You can also back up and restore through xfsdump, xfsrestore.

XFS Backup Recovery Tool

  • XFS provides xfsdump and xfsrestore tools to assist in backing up data in the XFS file system. xfsdump backs up an XFS file system in inode order.

  • Unlike traditional UNIX file systems, XFS does not need to be uninstalled before backup; backing up an active XFS file system ensures image consistency. The backup and recovery process of XFS can be interrupted and continued without freezing the file system xfsdump.It even provides a high-performance multithreaded backup operation - it splits a dump into multiple data streams, each of which can be sent to a different destination

Backup level of xfsdump

First understand that there are two backup levels for xfsdump, defaulting to 0 (full backup)

  • Level 0 representative: full backup
  • Levels 1 to 9: Incremental backup

Extensions:

  • Full backup: A full copy of the specified backup directory is made every time, regardless of changes in the files under the directory;
  • Incremental backup: Make backups of files that have changed since they were backed up before (first, second, and last time) each time;
  • Differential backup: Files that have changed since the first full backup are backed up each time.

Environmental preparation

Experimental environment

System CetnOS8 adds a virtual hard disk (prepare a test partition)
The normal use of a disk follows:
Add Disk Size: 2G -> Partition -> Format -> Mount

  1. Virtual Machine Add 2G Hard Drive
  2. View device after power on
    Use fdisk-l to view new hard disks
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. Add a partition to the new hard disk
[root@C8-3 ~]# fdisk /dev/sdb #Partition using fdisk command

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 #See what commands are available

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 #Select to create a new partition
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p #create primary partition
Partition number (1-4, default 1):  #Direct Enter Default
First sector (2048-4194303, default 2048):  #Start sector, return default
Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303):  #End sector, return allocates all space by default

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

Command (m for help): w #Write the above actions to the hard disk partition table to end the partition
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@C8-3 ~]# lsblk #Check partition success
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  #Partition succeeded but not mounted

  1. Format the new partition into xfs format
    Format new partitions using mkfs.xfs
[root@C8-3 ~]# type mkfs.xfs #Check to see if this tool is available
mkfs.xfs is /usr/sbin/mkfs.xfs
[root@C8-3 ~]# mkfs.xfs --help #View help for commands
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 */	[-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,
			    projid32bit=0|1,sparse=0|1]
/* no discard */	[-K]
/* log subvol */	[-l agnum=n,internal,size=num,logdev=xxx,version=n
			    sunit=value|su=num,sectsize=num,lazy-count=0|1]
/* label */		[-L label (maximum 12 characters)]
/* naming */		[-n size=num,version=2|ci,ftype=0|1]
/* no-op info only */	[-N]
/* prototype file */	[-p fname]
/* quiet */		[-q]
/* realtime subvol */	[-r extsize=num,size=num,rtdev=xxx]
/* sectorsize */	[-s size=num]
/* version */		[-V]
			devicename
<devicename> is required unless -d name=xxx is given.
<num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),
      xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).
<value> is xxx (512 byte blocks).
[root@C8-3 ~]# mkfs.xfs -V #View Command Version
mkfs.xfs version 5.0.0
[root@C8-3 ~]# mkfs.xfs /dev/sdb1 #Format New Partition
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=131008 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=524032, 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
  1. View new partitions
    View partitions and file systems using lsblk and parameter-f
    *-f, --fs output info about filesystems*
[root@C8-3 ~]# lsblk -f
NAME        FSTYPE      LABEL UUID                                   MOUNTPOINT
sda                                                                  
├─sda1      ext4              8df39f81-d4b1-4881-9bb4-51f8f6ee964a   /boot
└─sda2      LVM2_member       mQQNpB-AMy6-Ad3M-3RNh-NeRf-8tf9-OmosY7 
  ├─cl-root xfs               8dbc40ac-24cf-45c9-8c53-d07ac9cee558   /
  └─cl-swap swap              ffc54438-efdc-45d7-a244-b9e9bfef4930   [SWAP]
sdb                                                                  
└─sdb1      xfs               d549d0dd-23a2-4223-abe5-96055a8f737a 
  1. Create a directory and mount the new partition sdb1 to it
[root@C8-3 ~]# mkdir /xfsTest
[root@C8-3 ~]# mount /dev/sdb1 /xfsTest/
[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 /xfsTest

Create test files and folders

[root@C8-3 ~]# rm -rf /xfsTest/*
[root@C8-3 ~]# ls /xfsTest/
[root@C8-3 ~]# cp /etc/passwd /xfsTest/
[root@C8-3 ~]# touch /xfsTest/file{1..3}{a..b}.txt
[root@C8-3 ~]# mkdir -p /xfsTest/m{1..3}/n{a..b}
[root@C8-3 ~]# tree /xfsTest/
/xfsTest/
├── file1a.txt
├── file1b.txt
├── file2a.txt
├── file2b.txt
├── file3a.txt
├── file3b.txt
├── m1
│   ├── na
│   └── nb
├── m2
│   ├── na
│   └── nb
├── m3
│   ├── na
│   └── nb
└── passwd

9 directories, 7 files

backups

Backup using xfsdump command

View xfsdump help first

[root@C8-3 ~]# type xfsdump 
xfsdump is /usr/sbin/xfsdump
[root@C8-3 ~]# xfsdump --help
xfsdump: version 3.1.8 (dump format 3.0)
xfsdump: usage: xfsdump [ -a (dump DMF dualstate files as offline) ]
......

Back up the entire partition. (This function is like a snapshot of a virtual machine, which can be quickly restored after the server is black.)

[ -f <destination> ... ]
Xfsdump-f backup storage location Backup path or device file
Note: The backup path cannot be written as / xfsTest/. It can be / dev/sdb1 or / xfsTest

[root@C8-3 ~]# xfsdump -f /opt/dump_sdb1 /dev/sdb1
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control

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

please enter label for this dump session (timeout in 300 sec)
 -> dump_sdb1 #Prompt for input, specify backup session label
session label entered: "dump_sdb1"

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

xfsdump: level 0 dump of C8-3:/xfsTest
xfsdump: dump date: Tue Oct 20 08:09:38 2020
xfsdump: session id: 3fdced05-235f-4926-9409-7c7e4081da84
xfsdump: session label: "dump_sdb1"
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: 30016 bytes

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

please enter label for media in drive 0 (timeout in 300 sec)
 -> sdb1 #Prompt for input and specify device label to describe the device to be backed up
media label entered: "sdb1"

 --------------------------------- 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 32936 bytes
xfsdump: dump size (non-dir files) : 1568 bytes
xfsdump: dump complete: 70 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /opt/dump_sdb1 OK (success)
xfsdump: Dump Status: SUCCESS

Automatically backup snapshots like virtual machines without interaction

  • If the partition is large and there is a lot of data, it may take a long time before you jump out of the interface to prompt for input, so unreliable and insignificant hints can be interrupted for a long time.
  • Interaction-free is true automation. Specify backup-free Interoperability for later scheduled backups
[root@C8-3 ~]# time xfsdump -f /opt/dump_sdb1_3 /dev/sdb1 -L dump_1_3 -M 1_3
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control
xfsdump: level 0 dump of C8-3:/xfsTest
xfsdump: dump date: Tue Oct 20 08:21:12 2020
xfsdump: session id: 5308f2ab-6d0e-476f-9160-a72a37e56ca9
xfsdump: session label: "dump_1_3"
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: 30016 bytes
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 32936 bytes
xfsdump: dump size (non-dir files) : 1568 bytes
xfsdump: dump complete: 10 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /opt/dump_sdb1_3 OK (success)
xfsdump: Dump Status: SUCCESS

real	0m10.058s
user	0m0.000s
sys	0m0.004s

-L:xfsdump records the session header for each backup, where you can fill in a brief description of the file system
-M:xfsdump can record the header of the stored media, here you can fill in a brief description of the media

Backup specified directory

Parameters: -s File Path backs up only the specified files, -s specifies that the path writes the path relative to the root of the file system (-s can be a file or a directory)
To back up the directory m2/nb under / xfsTest (full path is / xfsTest/m2/nb write this directly), use the -s parameter

[root@C8-3 ~]# xfsdump -f /opt/dump_m2nb -s m2/nb /xfsTest   -L dump_m2nb -M m2nb 
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control
xfsdump: level 0 dump of C8-3:/xfsTest
xfsdump: dump date: Tue Oct 20 10:04:58 2020
xfsdump: session id: 4cd18dc2-9a10-4538-b93c-3d4169c13eae
xfsdump: session label: "dump_m2nb"
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: 21440 bytes
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 22592 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 10 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /opt/dump_m2nb OK (success)
xfsdump: Dump Status: SUCCESS

View backup information and content

[root@C8-3 xfsTest]# xfsdump -I
file system 0:
	fs id:		d549d0dd-23a2-4223-abe5-96055a8f737a
	session 0:
		mount point:	C8-3:/xfsTest
		device:		C8-3:/dev/sdb1
		time:		Tue Oct 20 08:09:38 2020
		session label:	"dump_sdb1"
		session id:	3fdced05-235f-4926-9409-7c7e4081da84
		level:		0
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/opt/dump_sdb1
			start:		ino 131 offset 0
			end:		ino 138 offset 0
			interrupted:	NO
			media files:	1
			media file 0:
				mfile index:	0
				mfile type:	data
				mfile size:	32936
				mfile start:	ino 131 offset 0
				mfile end:	ino 138 offset 0
				media label:	"sdb1"
				media id:	77e98c40-d588-4562-b801-6ba7dd2425bf
	session 1:
		mount point:	C8-3:/xfsTest
		device:		C8-3:/dev/sdb1
		time:		Tue Oct 20 08:17:18 2020
		session label:	"dump_passwd"
		session id:	e9970178-7a24-4c9d-b9c0-7e13f8d43c48
		level:		0
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/opt/dump_sdb1
			start:		ino 0 offset 0
			end:		ino 0 offset 0
			interrupted:	YES
			media files:	0
	session 2:
		mount point:	C8-3:/xfsTest
		device:		C8-3:/dev/sdb1
		time:		Tue Oct 20 08:19:23 2020
		session label:	"dump_12"
		session id:	391b7c46-47f6-4760-b454-c7835045db09
		level:		0
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/opt/dump_sdb1
			start:		ino 0 offset 0
			end:		ino 0 offset 0
			interrupted:	YES
			media files:	0
	session 3:
		mount point:	C8-3:/xfsTest
		device:		C8-3:/dev/sdb1
		time:		Tue Oct 20 08:20:12 2020
		session label:	"dump_12"
		session id:	d6613e91-8c68-4f40-b68b-e836fdf35568
		level:		0
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/opt/dump_sdb1_1
			start:		ino 131 offset 0
			end:		ino 138 offset 0
			interrupted:	NO
			media files:	1
			media file 0:
				mfile index:	0
				mfile type:	data
				mfile size:	32936
				mfile start:	ino 131 offset 0
				mfile end:	ino 138 offset 0
				media label:	"12"
				media id:	f85b0aff-d362-429c-9804-0ca1071f812f
	session 4:
		mount point:	C8-3:/xfsTest
		device:		C8-3:/dev/sdb1
		time:		Tue Oct 20 08:21:12 2020
		session label:	"dump_1_3"
		session id:	5308f2ab-6d0e-476f-9160-a72a37e56ca9
		level:		0
		resumed:	NO
		subtree:	NO
		streams:	1
		stream 0:
			pathname:	/opt/dump_sdb1_3
			start:		ino 131 offset 0
			end:		ino 138 offset 0
			interrupted:	NO
			media files:	1
			media file 0:
				mfile index:	0
				mfile type:	data
				mfile size:	32936
				mfile start:	ino 131 offset 0
				mfile end:	ino 138 offset 0
				media label:	"1_3"
				media id:	78304c29-4353-4edc-a3cb-63454d898918
xfsdump: Dump Status: SUCCESS

Delete backed up files

[root@C8-3 xfsTest]# cd
[root@C8-3 ~]# rm -rf /xfsTest/*
[root@C8-3 ~]# ls -a /xfsTest/

Restore File System

Syntax: xfsrestore -f Specifies the location of the recovered file Specifies the path to store the recovered file

[root@C8-3 ~]# mkdir /xfsTest-re #Create recovery folders in other partitions
[root@C8-3 ~]# xfsrestore -f /opt/dump_sdb1 /xfsTest-re
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.8 (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: C8-3
xfsrestore: mount point: /xfsTest
xfsrestore: volume: /dev/sdb1
xfsrestore: session time: Tue Oct 20 08:09:38 2020
xfsrestore: level: 0
xfsrestore: session label: "dump_sdb1"
xfsrestore: media label: "sdb1"
xfsrestore: file system id: d549d0dd-23a2-4223-abe5-96055a8f737a
xfsrestore: session id: 3fdced05-235f-4926-9409-7c7e4081da84
xfsrestore: media id: 77e98c40-d588-4562-b801-6ba7dd2425bf
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 10 directories and 16 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /opt/dump_sdb1 OK (success)
xfsrestore: Restore Status: SUCCESS
[root@C8-3 ~]# ll /xfsTest-re/ #View recovered files
total 4
-rw-r--r--. 1 root root    0 Oct 20 07:58 file1a.txt
-rw-r--r--. 1 root root    0 Oct 20 07:58 file1b.txt
-rw-r--r--. 1 root root    0 Oct 20 07:58 file2a.txt
-rw-r--r--. 1 root root    0 Oct 20 07:58 file2b.txt
-rw-r--r--. 1 root root    0 Oct 20 07:58 file3a.txt
-rw-r--r--. 1 root root    0 Oct 20 07:58 file3b.txt
drwxr-xr-x. 4 root root   26 Oct 20 07:59 m1
drwxr-xr-x. 4 root root   26 Oct 20 07:59 m2
drwxr-xr-x. 4 root root   26 Oct 20 07:59 m3
-rw-r--r--. 1 root root 1469 Oct 20 07:58 passwd
[root@C8-3 ~]# tree /xfsTest #Nothing to compare source directories
/xfsTest

0 directories, 0 files
[root@C8-3 ~]# tree /xfsTest-re/ #The directory structure was rebuilt in the restored directory
/xfsTest-re/
├── file1a.txt
├── file1b.txt
├── file2a.txt
├── file2b.txt
├── file3a.txt
├── file3b.txt
├── m1
│   ├── na
│   └── nb
├── m2
│   ├── na
│   └── nb
├── m3
│   ├── na
│   └── nb
└── passwd

9 directories, 7 files

Note:

When using xfsdump, note the following limitations:

  1. xfsdump does not support unmounted file system backups! So only mounted files can be backed up!
  2. xfsdump must use root privileges to operate (involving file system relationships)
  3. xfsdump can only back up the XFS file system
  4. The data (files or storage media) backed up by xfsdump can only be parsed by xfsrestore
  5. xfsdump distinguishes individual backup files through the UUID of the file system, so it is not possible to back up two file systems with the same UUID

Incremental backup

concept

Incremental backup means that after a full backup or the last incremental backup, each subsequent backup only needs to back up the files that have been added or modified since the previous one. This means that the object of the first incremental backup is the added and modified files resulting from the full backup; the object of the second incremental backup is the increase and modification resulting from the first incremental backup.Files, and so on.  

Advantages and disadvantages

  • Advantages: There is no duplicate backup data, so the amount of data backed up is small and the backup time is short.
  • Disadvantages: Data recovery is relatively cumbersome, it requires the contents of the last full backup and all incremental backups to fully recover successfully, and they must be recovered one by one in the sequence from full backup to incremental backup, so recovery time may be prolonged

Prepare a directory that needs backup

[root@C8-3 ~]# tree /xfsTest
/xfsTest
├── m1
│   ├── na
│   └── nb
├── m2
│   ├── na
│   └── nb
├── m3
│   ├── na
│   └── nb
└── passwd

Make a full backup

[root@C8-3 ~]# xfsdump -f /opt/xFull /xfsTest -L xF1 -M x1
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control
xfsdump: level 0 dump of C8-3:/xfsTest
xfsdump: dump date: Tue Oct 20 10:43:59 2020
xfsdump: session id: 4bc4262b-afa1-493f-8b21-33428325961d
xfsdump: session label: "xF1"
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: 28096 bytes
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 29000 bytes
xfsdump: dump size (non-dir files) : 1568 bytes
xfsdump: dump complete: 10 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /opt/xFull OK (success)
xfsdump: Dump Status: SUCCESS

Add something in

[root@C8-3 ~]# echo hellow >> /xfsTest/passwd
[root@C8-3 ~]# touch /xfsTest/nb3.txt

Delete something

[root@C8-3 ~]# rm -rf /xfsTest/m2
[root@C8-3 ~]# ls /xfsTest
m1  m3  nb3.txt  passwd
[root@C8-3 ~]# ll /xfsTest
total 4
drwxr-xr-x. 4 root root   26 Oct 20 07:59 m1
drwxr-xr-x. 4 root root   26 Oct 20 07:59 m3
-rw-r--r--. 1 root root    0 Oct 20 10:47 nb3.txt
-rw-r--r--. 1 root root 1476 Oct 20 10:46 passwd

Make the first incremental backup

[root@C8-3 ~]# xfsdump -l 1 -f /opt/xBL1 /xfsTest -L xBL1 -M xB1

Make a second incremental backup

Add something, delete something

[root@C8-3 ~]# mkdir /xfsTest/xBl2
[root@C8-3 ~]# rm -rf /xfsTest/m3

Then do a 2-level incremental backup after stubble

[root@C8-3 ~]# xfsdump -l 2 -f /opt/xBL2 /xfsTest -L xBL2 -M xB2

Delete all backed up data

[root@C8-3 ~]# rm -rf /xfsTest/*
[root@C8-3 ~]# ll /xfsTest
total 0

Restore data

Now for recovery, how do you recover all data, including newly added files?
Steps:
1. Restore full backup first
2. Situation 1: Restore the last incremental backup (if both incremental backups are level 1, you only need to restore the last increment).
3. Situation 2: If you make a first-level reserve and a second-level reserve, you need to restore a full backup first, then a first-level reserve and finally a second-level reserve when you recover.

#####Restore the last incremental backup directly

[root@C8-3 ~]# xfsrestore -f /opt/xBL2 /xfsTest
[root@C8-3 ~]# tree /xfsTest
/xfsTest
└── xBl2

Found that only the last folder created was restored

Direct recovery of first incremental backup

[root@C8-3 ~]# rm -rf /xfsTest/*
[root@C8-3 ~]# ll /xfsTest
total 0
[root@C8-3 ~]# xfsrestore -f /opt/xBL1 /xfsTest
[root@C8-3 ~]# tree /xfsTest
/xfsTest
├── nb3.txt
└── passwd

Only files and folders added and modified before the first incremental backup were recovered

Restore the first full backup directly

[root@C8-3 ~]# xfsrestore -f /opt/xFull /xfsTest
[root@C8-3 ~]# tree /xfsTest
/xfsTest
├── m1
│   ├── na
│   └── nb
├── m2
│   ├── na
│   └── nb
├── m3
│   ├── na
│   └── nb
└── passwd

9 directories, 1 file
[root@C8-3 ~]# ll /xfsTest
total 4
drwxr-xr-x. 4 root root   26 Oct 20 07:59 m1
drwxr-xr-x. 4 root root   26 Oct 20 07:59 m2
drwxr-xr-x. 4 root root   26 Oct 20 07:59 m3
-rw-r--r--. 1 root root 1469 Oct 20 07:58 passwd

This restores to the state before the first incremental backup

If you want to restore to the state when all files were last deleted, you need to restore incremental one and incremental two backups in sequence.

At this point, data recovery was successful.

Tags: Linux Operation & Maintenance CentOS

Posted on Wed, 08 Sep 2021 12:54:18 -0400 by stringman