21.7.1 Using snapper with Btrfs Subvolumes

You can use the snapper utility to create and manage snapshots of btrfs subvolumes.

To set up the snapper configuration for an existing mounted btrfs subvolume:

# snapper -c config_name create-config -f btrfs fs_name

Here config_name is the name of the configuration and fs_name is the path of the mounted btrfs subvolume. The command adds an entry for config_name to /etc/sysconfig/snapper, creates the configuration file /etc/snapper/configs/config_name, and sets up a .snapshots subvolume for the snapshots.

For example, the following command sets up the snapper configuration for a btrfs root file system:

# snapper -c root create-config -f btrfs /

By default, snapper sets up a cron.hourly job to create snapshots in the .snapshot subdirectory of the subvolume and a cron.daily job to clean up old snapshots. You can edit the configuration file to disable or change this behavior. For more information, see the snapper-configs(5) manual page.

There are three types of snapshot that you can create using snapper:

post

You use a post snapshot to record the state of a subvolume after a modification. A post snapshot should always be paired with a pre snapshot that you take immediately before you make the modification.

pre

You use a pre snapshot to record the state of a subvolume before a modification. A pre snapshot should always be paired with a post snapshot that you take immediately after you have completed the modification.

single

You can use a single snapshot to record the state of a subvolume but it does not have any association with other snapshots of the subvolume.

For example, the following commands create pre and post snapshots of a subvolume:

# snapper -c config_name create -t pre -p
N
... Modify the subvolume's contents...
# snapper -c config_name create -t post --pre-num N -p
N'

The -p option causes snapper to display the number of the snapshot so that you can reference it when you create the post snapshot or when you compare the contents of the pre and post snapshots.

To display the files and directories that have been added, removed, or modified between the pre and post snapshots, use the status subcommand:

# snapper -c config_name status N..N'

To display the differences between the contents of the files in the pre and post snapshots, use the diff subcommand:

# snapper -c config_name diff N..N'

To list the snapshots that exist for a subvolume:

# snapper -c config_name list

To delete a snapshot, specify its number to the delete subcommand:

# snapper -c config_name delete N''

To undo the changes in the subvolume from post snapshot N' to pre snapshot N:

# snapper -c config_name undochange N..N'

For more information, see the snapper(8) manual page.