xfsdump and xfsrestore are a pair of utilities that backup and restore xfs filesystem. In this article, I'll describe it's features and examples:

xfsdump and xfsrestore support the following:
  • XFS features including 64-bit inode numbers, file lengths, and holes
  • regular, directory, symbolic link, block and character special, FIFO, and socket file types
  • retain hard links.
  • multiple media types (tape, files)
  • do not affect the state of the filesystem being dumped (for example, access times are retained).
  • xfsrestore detects and bypasses media errors and recovers rapidly after encountering them.
  • xfsdump does not crossmount points, local or remote
  • support for automated and incremental backups

So, to backup or dump an XFS file system, use the xfsdump utility(not part of xfsprogs). xfsdump examines the files in an XFS file system, determines which files need to be backed up, and copies them to the storage medium. Any backups that you create using xfsdump are portable between systems with different endian architectures. xfsrestore restores a full or incremental backup of an XFS file system. You can also restore individual files and directory hierarchies from backups.

Red Hat Enterprise Linux 6 and up supports backups to tape drives or regular file images, and also allows multiple dumps to be written to the same tape.The xfsdump utility also allows a dump to span multiple tapes, although only one dump can be written to a regular file. In addition, xfsdump supports incremental backups, and can exclude files from a backup using size, subtree, or inode flags to filter them.

Note

Unlike an LVM snapshot, which immediately creates a sparse clone of a volume, xfsdump takes time to make a copy of the file system data.

xfsdump package

As mentioned above, xfsdump/xfsrestore are not part of xfsprogs, they are in xfsdump package. Which is available on most of Linux distros.

# rpm -ql xfsdump-3.1.3-2.fc20.x86_64
/usr/sbin/xfsdump
/usr/sbin/xfsinvutil
/usr/sbin/xfsrestore
/usr/share/doc/xfsdump
...

Create a base dump/backup of a XFS file system

To create a base level dump/backup, the following command writes a level 0 (base) backup of the XFS file system, /my_xfs to the device /dev/st0 and assigns a session label to the backup:

# xfsdump -l 0 -L "Backup level 0 of /my_xfs `date`" -f /dev/st0 /my_xfs

Create an incremental dumps/backup

To make an incremental XFS file system dump/backup, run the command:

# xfsdump -l level -L "Backup level level of /my_xfs `date`" -f /dev/st0 /my_xfs

Where level is between 0 to 9, 0 means a base backup, level 1 backup records only file system changes since the level 0 backup, so on to level 2 up to level 9.

Interruption and resume  a backup

If you interrupt a backup by typing Ctrl-C and you did not specify the -J option (suppress the dump inventory) to xfsdump , you can resume the dump at a later date by specifying the -R option:

# xfsdump -R -l 1 -L "Backup level 1 of /myxfs `date`" -f /dev/st0 /myxfs

In this example, the backup session label from the earlier, interrupted session is overridden.

Check dump/backup information

Use xfsrestore command to find out information about the backups you have made of an XFS file system or to restore data from a backup.

The xfsrestore -I command displays information about the available backups, including the session ID and session label.

# xfsrestore -I

xfsrestore to restore a specific backup session.

If you want to restore a specific backup session from a backup medium, you can specify either the session ID or the session label.

For example, to restore an XFS file system from a level 0 backup by specifying the session ID:

# xfsrestore -f /dev/st0 -S 2c166d04-50a4-11e7-9420-001d72e9a542 /my_xfs

Simple mode for xfsrestore

The simple mode allows users to restore an entire file system from a level 0 dump. After identifying a level 0 dump's session ID (that is, session-ID), restore it fully to /path/to/destination using:
# xfsrestore -f /dev/st0 -S session-ID /path/to/destination

Cumulative mode of xfsrestore

The cumulative mode of xfsrestore allows file system restoration from a specific incremental backup, for example, level 1 to level 9. To restore a file system from an incremental backup, simply add the -r option:
# xfsrestore -f /dev/st0 -S session-ID -r /path/to/destination

Note: If you specify the -r option, you can cumulatively recover all data from a level 0 backup and the higher-level backups that are based on that backup:

Restore a selected file or subdirectory contents from a xfs backup/dump

You can recover a selected file or subdirectory contents from the backup medium, as shown in the following example, which recovers the contents of /myxfs/profile/examples to /tmp/profile/examples from the backup with a specified session label:

# xfsrestore -f /dev/sr0 -L "Backup level 0 of /my_xfs Tue Jun 13 18:54:30 PDT 2017" \
  -s home/fibrevillage /usr/tmp

Interactive restore mode

Alternatively, you can interactively browse a backup by specifying the -i option:

# xfsrestore -f /dev/sr0 -i

This form of the command allows you browse a backup as though it were a file system. You can change directories, list files, add files, delete files, or extract files from a backup.

Duplicate a XFS file system to another

To copy the entire contents of one XFS file system to another, you can combine xfsdump and xfsrestore, using the -J option to suppress the usual dump inventory housekeeping that the commands perform:

# xfsdump -J - /my_xfs | xfsrestore -J - /my_xfs_colone
For more information about dumping and restoring XFS file systems, refer to man xfsdump and man xfsrestore.