5.7 Using the Send/Receive Feature

5.7.1 Using Send/Receive to Implement Incremental Backups
Note

The send/receive feature requires that you boot the system using UEK R3.

The send operation compares two subvolumes and writes a description of how to convert one subvolume (the parent subvolume) into the other (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:

# btrfs send [-v] [-f sent_file] ... subvol

You can specify multiple instances of the -v option to display increasing amounts of debugging output. The -f option allows you to save the output to a file. 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 into another:

# 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 of the data can be recovered, you can specify the clone source to reduce the size of the output file:

# btrfs send [-p parent_subvol] -c clone_src [-c clone_src] ... subvol

You can specify the -c option multiple times if there is more than one clone source. If you do not specify the parent subvolume, btrfs chooses a suitable parent from the clone sources.

You use the receive operation to regenerate the sent subvolume at a specified path:

# btrfs receive [-f sent_file] mountpoint

5.7.1 Using Send/Receive to Implement Incremental Backups

The following procedure is a suggestion for setting up an incremental backup and restore process for a subvolume.

  1. Create a read-only snapshot of the subvolume to serve as an initial reference point for the backup:

    # btrfs subvolume snapshot -r /vol /vol/backup_0
  2. Run sync to ensure that the snapshot has been written to disk:

    # sync
  3. Create a subvolume or directory on a btrfs file system as a backup area to receive the snapshot, for example, /backupvol.

  4. Send the snapshot to /backupvol:

    # btrfs send /vol/backup_0 | btrfs receive /backupvol

    This command creates the subvolume /backupvol/backup_0.

    Having created the reference backup, you can then create incremental backups as required.

  5. To create an incremental backup:

    1. Create a new snapshot of the subvolume:

      # btrfs subvolume snapshot -r /vol /vol/backup_1
    2. Run sync to ensure that the snapshot has been written to disk:

      # sync
    3. Send only the differences between the reference backup and the new backup to the backup area:

      # btrfs send -p /vol/backup_0 /vol/backup_1 | btrfs receive /backupvol

      This command creates the subvolume /backupvol/backup_1.