19.24 Backing up and Restoring XFS File Systems

The xfsdump package contains the xfsdump and xfsrestore utilities. 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.

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.

You can use the xfsdump command to create a backup of an XFS file system on a device such as a tape drive, or in a backup file on a different file system. A backup can span multiple physical media that are written on the same device, and you can write multiple backups to the same medium. You can write only a single backup to a file. The command does not overwrite existing XFS backups that it finds on physical media. You must use the appropriate command to erase a physical medium if you need to overwrite any existing backups.

For example, the following command writes a level 0 (base) backup of the XFS file system, /myxfs to the device /dev/st0 and assigns a session label to the backup:

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

You can make incremental dumps relative to an existing backup by using the command:

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

A level 1 backup records only file system changes since the level 0 backup, a level 2 backup records only the changes since the latest level 1 backup, and so on up to level 9.

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.

You use the 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. 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 c76b3156-c37c-5b6e-7564-a0963ff8ca8f /myxfs

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:

# xfsrestore -r -f /dev/st0 -v silent /myxfs

The command searches the archive looking for backups based on the level 0 backup, and prompts you to choose whether you want to restore each backup in turn. After restoring the backup that you select, the command exits. You must run this command multiple times, first selecting to restore the level 0 backup, and then subsequent higher-level backups up to and including the most recent one that you require to restore the file system data.

Note

After completing a cumulative restoration of an XFS file system, you should delete the housekeeping directory that xfsrestore creates in the destination directory.

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 /myxfs Sat Mar 2 14:47:59 GMT 2013" \
  -s profile/examples /usr/tmp

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.

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 - /myxfs | xfsrestore -J - /myxfsclone

For more information, see the xfsdump(8) and xfsrestore(8) manual pages.