Backing Up and Restoring an XFS File System
The xfsdump
package contains the xfsdump and
xfsrestore utilities. The xfsdump command
examines the files in an XFS file system, identifies files that need to be backed up, and
copies them to the storage medium. Any backups that you create by using the
xfsdump command are portable between systems with different endian
architectures. The xfsrestore command 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 several physical media that are written on the same device. Also, you can write several backups to the same medium. Note that you can write only a single backup to a file. The command doesn't overwrite existing XFS backups that are found on physical media. If you need to overwrite any existing backups, you must use the appropriate command to erase a physical medium.
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:
sudo xfsdump -l 0 -L "Backup level 0 of /myxfs `date`" -f /dev/st0 /myxfs
You can make incremental dumps that are relative to an existing backup by using the same command, for example:
sudo xfsdump -l level -L "Backup level level of /myxfs `date`" -f /dev/st0 /myxfs
A level 1 backup records only file system changes after the level 0 backup, a level 2 backup records only the changes after the latest level 1 backup, and so on up to level 9.
If you interrupt a backup by typing Ctrl-C
and you didn't specify the
-J option (suppress the dump inventory) to
xfsdump , you can resume the dump later by specifying the
-R option, for example:
sudo xfsdump -R -l 1 -L "Backup level 1 of /myxfs `date`" -f /dev/st0 /myxfs
In the previous example, the backup session label from the earlier interrupted session is overridden.
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. 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, you would use the following command:
sudo xfsrestore -f /dev/st0 -S c76b3156-c37c-5b6e-7564-a0963ff8ca8f /myxfs
Specify the -r option to cumulatively recover all the data from a level 0 backup, as well as higher-level backups that are based on that backup:
sudo xfsrestore -r -f /dev/st0 -v silent /myxfs
This command searches for backups in the archive, based on the level 0 backup, and then prompts you to choose whether you want to restore each backup, in turn. After restoring the selected backup, the command exits. Note that you must run this command several times, first selecting to restore the level 0 backup, and then later higher-level backups, including the most recent backup that you require to restore the file system data.
Note:
After completing a cumulative restoration of an XFS file system, delete the
housekeeping
directory that the xfsrestore command
creates in the destination directory.
As shown in the following example, you can recover a selected file
or subdirectory contents from the backup medium. Running the
command recovers the contents of
/myxfs/profile/examples
to
/tmp/profile/examples
, from the backup with the
specified session label:
sudo 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, for example:
sudo xfsrestore -f /dev/sr0 -i
The previous form of the command enables 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 the xfsdump and xfsrestore command by using the -J option to suppress the usual dump inventory housekeeping that the commands perform, for example:
sudo xfsdump -J - /myxfs | xfsrestore -J - /myxfsclone
For more information, see the xfsdump(8)
and
xfsrestore(8)
manual pages.