(Linux) Centos 7 xfsdump file system backup and recovery

     XFS provides tools to help xfsdump and xfsrestore backup data XFS file system. xfsdump by inode order to back up an XFS file system.

centos7 choose xfs format as the default file system, and no longer use the previous ext, still supports ext4, xfs designed to generate large data, each single file system can support up 8eb, a single file can support 16tb, not only large amount of data, and high scalability. Can also xfsdump, xfsrestore to back up and restore.

With traditional UNIX file systems differ, XFS not need to be uninstalled before backup; the use of the XFS file system backup can be done to ensure the consistency of the mirror. XFS backup and recovery process is interrupted and can be continued without freezing file system. xfsdump even provide high performance multithreaded backup operation - dump it to split into a plurality of data streams, each data stream can be sent to different destinations

First look at the backup level xfsdump has the following two, the default is 0 (ie full backup)

0 -level representatives: full backup

1   Dao nine-level representatives: incremental backup

Extended:

Full backup: every time specified backup directory complete copy again, regardless of the file's directory has not changed;

Incremental backup: Each time before the (first, second, until the time) did change after the backup files are backed up;

There is a change files are backed up every time the first full backup since: differential backup.

4.4.1 Environmental ready

lab environment:

        The system CENTOS7.2 add a virtual hard disk (to prepare a test partition)

Use a normal disk as follows:

Add disk size: 20G à partition à formatted à Mount carried out using

 

Add the new format the hard disk:

[xuegod63 the root @ ~] # the fdisk / dev / SDB              # Specifies partition device

Welcome to the fdisk (util-linux 2.23.2).

Change will stay in memory until you decide to write the changes to disk.

Please think twice before using the write command.

Device does not contain a recognized partition table

Use disk identifier 0x06d5a427 create a new DOS disk label.

Command (input m to get help): the n-   # Create a new partition

Partition type:

    Primary (Primary 0, 0 Extended, Free. 4)    # primary partition

    Extended # extended partition      

The SELECT (the p-default): the p-   # create a primary partition

Partition number (1-4, default 1):

Starting sector (2048-41943039, the default is 2048):

We will use the default value 2048

Last sector, sector + or + size {K, M, G} (2048-41943039, default 41,943,039):. 1G +   # partition size specified

Partition 1 is set to Linux type, size to 1 GiB

Command (input m to get help): the p-     # print the partition table

Disk /dev/sdb:21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical / physical): 512 byte / 512 byte

I / O Size (minimal / optimal): 512 byte / 512 byte

Disk Label Type: dos

Disk identifier: 0x06d5a427

   设备 Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048     2099199     1048576   83  Linux

Command (input m to get help) : w   # Save

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[xuegod63 the root @ ~] # LS / dev / SDB *  # View second disk

/dev/sdb  /dev/sdb1

 

Use the new partition, format partition, and mount

[ The root xuegod63 @ ~] # the mkfs.xfs / dev / sdb1 # formatted partition

[root @ xuegod63 ~] # mkdir / sdb1 # create the mount point

[root @ xuegod63 ~] # mount / dev / sdb1 / sdb1 # mount

Ready to test the backup file

[xuegod63 the root @ ~] # CD / sdb1 /   # into the sdb1 / directory

[root @ xuegod63 sdb1] # cp / etc / passwd ./   # copy / etc / passwd file to the current directory

[root @ xuegod63 sdb1] # mkdir the Test           # Create a new folder       

[root @ xuegod63 sdb1] Touch test # / A           # Create a file in the test directory

[root @ xuegod63 sdb1] # Tree / sdb1 /           # to view the contents of the directory sdb1

[root@xuegod63 sdb1]# tree /sdb1/

/sdb1/

├── passwd

└── test

    └── a

4.4.2 Backup

1 , back up the entire partition. (This feature is like a snapshot of the virtual machine, the server is after dark, fast recovery)

xfsdump -f backup storage location or device files to the backup path

Note: The backup path can not be written here / sdb1 / may be / dev / sdb1 or / sdb1 (just mounted directory)

[root@xuegod63 sdb1]# xfsdump -f /opt/dump_sdb1  /dev/sdb1

                        xfs copy backup -f / opt / dump_adb1 (file created directly)

[root @ xuegod63 sdb1] # xfsdump -f / opt / dump_sdb1 / dev / sdb1 # at the sdb1 / dev / under or before the / dev / sdb1 mount / sdb1 back up to the root directory / opt / directory New files can be dump_sdb1

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

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

 -> dump_sdb1      # specified backup session label

session label entered: "dump_sdb1"

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

xfsdump: level 0 dump of xuegod63.cn:/sdb1

xfsdump: dump date: Fri Nov 17 12:24:53 2017

xfsdump: session id: b5a25fcd-d43d-4308-bf29-142066f89d9a

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

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

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

 -> sdb1    # specified device label, the equipment is to be backed up to make a description

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

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

xfsdump: dump complete: 46 seconds elapsed

xfsdump: Dump Summary:

xfsdump:   stream 0 /opt/dump_sdb1 OK (success)

xfsdump: Dump Status: SUCCESS    # show success means success

2 , avoid interaction when specifying backup, scheduled backup done to facilitate post

[root@xuegod63 sdb1]# xfsdump -f /opt/dump_passwd /sdb1 -L dump_passwd -M media1

-L  : xfsdump the session header record of each backup, where you can fill out a simple explanation for this file system

-M  : xfsdump can record header storage media, where you can fill out a simple explanation for this media

[root@xuegod63 opt]# xfsdump -f /opt/dump_passwd /sdb1或(/dev/sdb1) -L dump_passwd -M sdb1

xfsdump: using file dump (drive_simple) strategy

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

xfsdump: WARNING: most recent level 0 dump was interrupted, but not resuming that dump since resume (-R) option not specified

xfsdump: level 0 dump of xuegod63.cn:/sdb1

xfsdump: dump date: Sat Jun 15 13:55:04 2019

xfsdump: session id: f5ee3040-8655-4a69-9f26-bead841eb49e

xfsdump: session label: "dump_passwd"

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: 25856 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 24544 bytes

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

xfsdump: dump complete: 20 seconds elapsed

xfsdump: Dump Summary:

xfsdump:   stream 0 /opt/dump_passwd OK (success)

xfsdump: Dump Status: SUCCESS # show success means success

[root @ xuegod63 opt] # ls / opt / dump_passwd # view has been backed up successfully

/opt/dump_passwd       

3 , specify a directory partition backup only

Parameters: -s file path only specified files are backed up, when -s is specified, the path is written by a relative path (-s can be a file or directory)

[root@xuegod63 sdb1]# ls /boot/grub2/grub.cfg

/boot/grub2/grub.cfg

[root@xuegod63 sdb1]# xfsdump -f /opt/dump_grub2 -s grub2/grub.cfg /boot -L

dump_grub2 -M boot-grub2

: File location grub2 grub2 already so do not plus / boot in the root directory,

: File directory where you want to back up in the / boot # absolute path

: # Specify the backup session label

: # Specified device label, the equipment is to be backed up to make a description

[root@xuegod63 boot]# ls /opt

dump_grub2  dump_passwd  dump_sdb1  rh

[root@xuegod63 boot]#ll -hl /0pt

The total amount of 76K

-rw-r--r--  1 root root 28K 6月  15 14:40 dump_grub2

-rw-r--r--  1 root root 24K 6月  15 13:55 dump_passwd

-rw-r--r--  1 root root 24K 6月  15 12:53 dump_sdb1

drwxr-xr-x. 2 root root  6  9月   7  2017  rh

4 , see the backup information and content

See the generated log file information after the backup is successful, we will be in / var / lib / xfsdump / inventory directory

[root@xuegod63 boot]# ls /var/lib/xfsdump/inventory/

0a7b7b70-a7c0-45d8-b116-f219b15ba91a.InvIndex  69bf6c3d-2d25-48d3-b73c-1a987bbec173.StObj  b60e1056-d4f6-4683-b486-72cf8fe6aee4.InvIndex

0e52cdd2-37ff-4213-9432-38f0dfba46b6.StObj    

[root @ xuegod63 opt] # xfsdump -I more detail (uppercase i) can view this backup

Testing Recovery: Creating content before deleting

[root@xuegod63 sdb1]# ls

passwd  test

[root@xuegod63 sdb1]# pwd

/sdb1

[root@xuegod63 sdb1]# rm -rf ./*

 

4.4.3 File System Recovery

Syntax: xfsrestore -f specify the location of the file to restore the specified file stored recovery path

[root@xuegod63 opt]# xfsrestore -f /opt/dump_sdb1  /sdb1

View recovery

[root@xuegod63 ~]# ls /sdb1/

Restore a single file as follows:

[root@xuegod63 ~]# mkdir /var/test/

[xuegod63 the root @ ~] # xfsrestore -f / opt / -s dump_grub2 grub2 / the grub.cfg / var / Test / # restore files

                                Backup before then / opt / file only restore a file back to the / var / test / folder

[xuegod63 the root @ ~] # xfsrestore -f / opt / -s dump_grub2 grub2 / var / Test /   # recovery catalog

                                Backup before then / opt / file recovery to restore a directory / var / test / folder

Note:

When using xfsdump, please note the following following several limitations:
1, xfsdump does not support file system backup is not mounted! So only back up the mounted!
2, xfsdump must have privilege to operate (relationship involving the file system) root of
3, xfsdump only backup XFS file system
4, data backup xfsdump down (file or storage media) can only make xfsrestore resolve
5, xfsdump is through UUID of each file system to distinguish backup file, you can not back up two file systems with the same UUID

4.4.4 Incremental Backup

concept

       Incremental backup is a full backup after on or incremental backup, each subsequent backup only back up once the file is modified or increased as compared with the previous. This means that the object is first incremental backup is to increase and modify the generated full backup file; the second incremental backup target is to increase and modify After the first incremental backup generated files, and so on.

Advantages and disadvantages

Advantages: no duplicate backup data, the amount of data is not backed up, the backup time required is short.

Cons: Data Recovery relatively trouble, it needs a full backup and incremental backups of all content to be able to fully recover successfully, and they must be individually along the thrust reversers recovery time from order to order full backup incremental backup, so it may It will extend recovery time

 

Combat: Incremental backup file system

Prepare a backup directory backup

[root@xuegod63 sdb1]# tree  /sdb1

/sdb1/

├── passwd

└── test

    └── a

The contents of the above for the first time all equipment

[root@xuegod63 sdb1]# xfsdump -f /opt/test-full /sdb1 -L test-full -M media0

Add some content, then the first incremental backup

[root@xuegod63 ~]# touch  /sdb1/1.txt /sdb1/2.txt

[root@xuegod63 ~]# tree  /sdb1/

/sdb1/

├── 1.txt

├── 2.txt

├── passwd

└── test

└── a

[root@xuegod63 sdb1]# xfsdump -l 1 -f /opt/test-back1 /sdb1 -L test-bak1 -M media0

-l <level>  to make a Level 1 backup

Increase content again, then level 2 level incremental backups

[root@xuegod63 sdb1]# touch  /sdb1/test/a.txt  /sdb1/test/b.txt

[root@xuegod63 ~]# tree /sdb1/

/sdb1/

├── 1.txt

├── 2.txt

├── passwd

└── test

    ├── a

    ├── a.txt

└── b.txt

[root@xuegod63 sdb1]# xfsdump -l 2 -f /opt/test-back2 /sdb1 -L test-bak2 -M media0

[root @ xuegod63 ~] # RM -rf / sdb1 / *     # delete all data

 

Now to recover, to recover all the all the data, including the newly added file, how to restore?

step:

       1 , first restore a full backup   

       2 , Case 1: restore the last incremental backup (if two are level 1 incremental backup, so only need to restore the last incremental on it.

3 , Case 2: If you do the first time is a Level 1 equipment, the second stage 2 is prepared, then you will need to recover in time to restore the full backup, then the backup Level 1, Level 2 and finally prepare )

[root@xuegod63 ~]# xfsrestore -f /opt/test-full /sdb1/

[root @ xuegod63 ~] # xfsrestore -f / opt / the Test-Back2 / sdb1 /   # deliberately to restore back2, View

[root @ xuegod63 ~] # Tree / sdb1 /   # View, found no 1.txt, 2.txt

/sdb1/

├── passwd

└── test

    ├── a

    ├── a.txt

└── b.txt

[root@xuegod63 ~]# xfsrestore -f /opt/test-back1 /sdb1/  

[root@xuegod63 ~]# tree /sdb1/ 

This data recovery success.

Reproduced in: https: //www.cnblogs.com/dairen/p/11043510.html

Guess you like

Origin blog.csdn.net/weixin_33836874/article/details/93113684