Backup and restore of xfs type files in Linux
Restore files of type XFS
First of all, we need to delete a file clearly. We don't actually erase the inode node and block data, but delete the file name in the block in the parent directory of the file. Linux controls file deletion through the number of Link, and only when a file does not have any Link will it be deleted. So when the file is accidentally deleted by us, as long as the file is backed up, we can still restore the file.
I. commands used
Xfsdump command format
Xfsdump-f backup location path or device file to be backed up
Xfsdump backup level (default is 0)
0: full backup
1-9: incremental backup
Common options for xfsdump:-f,-L,-M,-s
Xfsrestore command format:
Xfsrsetore-f location of recovery files to store the location of recovered files
Install xfsdump,xfsrestore software tools and make backup
1. Confirm whether the xfsdump,xfsrestore software is installed. It is not installed using yum install. It is installed by default in centos7.
[root@localhost ~] # rpm-Q xfsdump to see if xfsdump is installed
[root@localhost ~] # rpm-Q xfsrestore to see if xfsrestore is installed
2. Create a new disk by simulation, format the partition and mount it
[root@localhost ~] # fdisk / dev/sdb create partition
[root@localhost ~] # mkfs.xfs / dev/sdb1 format disk
[root@localhost ~] # mkdir data
[root@localhost ~] # mount / dev/sdb1 / data
3. Create a file directory under the / data directory, back it up using xfsdump, and back it up to / opt/xfs_dump
[root@localhost data] # cp / etc/passwd. / copy the files under / etc/passwd to data
[root@localhost data] # mkdir test create a new directory
[root@localhost data] # touch test/a01.txt create a new file
[root@localhost data] # xfsdump-f / opt/xfs_dump / dev/sdb1 use the xfsdump command to backup files to / dev/sdb1 disk to / opt/xfs_dump
4. Simulate deletion and perform restore operation
1), delete all files under / data
2) use xfsrestore to recover files
3) the recovery can be completed by viewing the backup file
[root@localhost ~] # rm-rf / data/* Delete all files under / data
[root@localhost ~] # xfsrestore-f / opt/xfs_dump / data/ uses xfsrestore to recover files
It can also be restored successfully if the inode node is occupied.