Creating Backups and Using the Btrfs Send/Receive Feature
Note:
Working with the Btrfs send/receive feature requires that you boot the system by using UEK R6 or later..
The send operation compares two subvolumes and writes a description of how to convert one subvolume, the parent subvolume, into the other subvolume, which is the sent subvolume. You would usually direct the output to a file for later use or pipe it to a receive operation for immediate use.
The simplest form of the send operation writes a complete description of a subvolume, for example:
sudo btrfs send [-v] [-f sent_file] ... subvol
You can specify many instances of the -v option to display increasing amounts of debugging output. The -f option is used to save the output to a file. Note that both of these options are implicit in the following usage examples.
The following form of the send operation writes a complete description of how to convert one subvolume to another subvolume:
sudo btrfs send -p parent_subvol sent_subvol
If a subvolume such as a snapshot of the parent volume, known as a clone source, will be available during the receive operation from which some data can be recovered, you can specify the clone source to reduce the size of the output file:
sudo btrfs send [-p parent_subvol] [-c clone_src] ... subvol
You can specify the -c option for each of the clone source that exist. If you don't specify the parent subvolume, btrfs chooses a suitable parent from the clone sources.
Use the receive operation to regenerate the sent subvolume at a specified path, for example:
sudo btrfs receive [-f sent_file] mountpoint
Creating a Reference Backup in Preparation for Creating an Incremental Backup
The following procedure describes how to create a reference backup, which is a prerequisite to setting up an incremental backup and restore process for a subvolume by using the send/receive feature.
-
Create a read-only snapshot of the subvolume to serve as an initial reference point for the backup.
sudo btrfs subvolume snapshot -r /vol /vol/backup_0
-
Ensure that the snapshot has been written to disk by running the sync command.
sudo sync
-
Create a subvolume or directory on a Btrfs file system as a backup area to receive the snapshot, for example,
/backupvol
. -
Send the snapshot to
/backupvol
.sudo btrfs send /vol/backup_0 | btrfs receive /backupvol
The previous command creates the
/backupvol/backup_0
subvolume.After creating the reference backup, you can then create incremental backups, as needed. See Creating an Incremental Backup.
Creating an Incremental Backup
The following instructions describe how to create an incremental backup by using the send/receive feature. Note that before creating an incremental backup, you must first create a reference backup. See Creating a Reference Backup in Preparation for Creating an Incremental Backup.
To create an incremental backup:
-
Create a snapshot of the subvolume.
sudo btrfs subvolume snapshot -r /vol /vol/backup_1
-
Ensure that the snapshot has been written to disk by running the sync command.
sudo sync
-
Send only the differences between the reference backup and the new backup to the backup area, for example:
sudo btrfs send -p /vol/backup_0 /vol/backup_1 | btrfs receive /backupvol
Running the previous comman creates the
/backupvol/backup_1
subvolume.