Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

14.2. Creating a Snapper Snapshot

Snapper can create the following kinds of snapshots:
Pre Snapshot
A pre snapshot serves as a point of origin for a post snapshot. The two are closely tied and designed to track file system modification between the two points. The pre snapshot must be created before the post snapshot.
Post Snapshot
A post snapshot serves as the end point to the pre snapshot. The coupled pre and post snapshots define a range for comparison. By default, every new snapper volume is configured to create a background comparison after a related post snapshot is created successfully.
Single Snapshot
A single snapshot is a standalone snapshot created at a specific moment. These can be used to track a timeline of modifications and have a general point to return to later.

14.2.1. Creating a Pre and Post Snapshot Pair

14.2.1.1. Creating a Pre Snapshot with Snapper

To create a pre snapshot, use:
# snapper -c config_name create -t pre
The -c config_name option creates a snapshot according to the specifications in the named configuration file. If the configuration file does not yet exist, see Section 14.1, “Creating Initial Snapper Configuration”.
The create -t option specifies what type of snapshot to create. Accepted entries are pre, post, or single.
For example, to create a pre snapshot using the lvm_config configuration file, as created in Section 14.1, “Creating Initial Snapper Configuration”, use:
# snapper -c SnapperExample create -t pre -p
1
The -p option prints the number of the created snapshot and is optional.

14.2.1.2. Creating a Post Snapshot with Snapper

A post snapshot is the end point of the snapshot and should be created after the parent pre snapshot by following the instructions in Section 14.2.1.1, “Creating a Pre Snapshot with Snapper”.

Procedure 14.2. Creating a Post Snapshot

  1. Determine the number of the pre snapshot:
    # snapper -c config_name list
    For example, to display the list of snapshots created using the configuration file lvm_config, use the following:
    # snapper -c lvm_config list
    Type   | # | Pre # | Date              | User | Cleanup  | Description | Userdata
    -------+---+-------+-------------------+------+----------+-------------+---------
    single | 0 |       |                   | root |          | current     |
    pre    | 1 |       | Mon 06<...>       | root |          |             |
    
    This output shows that the pre snapshot is number 1.
  2. Create a post snapshot that is linked to a previously created pre snapshot:
    # snapper -c config_file create -t post --pre-num pre_snapshot_number
    • The -t post option specifies the creation of the post snapshot type.
    • The --pre-num option specifies the corresponding pre snapshot.
    For example, to create a post snapshot using the lvm_config configuration file and is linked to pre snapshot number 1, use:
    # snapper -c lvm_config create -t post --pre-num 1 -p
    2
    
    The -p option prints the number of the created snapshot and is optional.
  3. The pre and post snapshots 1 and 2 are now created and paired. Verify this with the list command:
    # snapper -c lvm_config list
    Type   | # | Pre # | Date              | User | Cleanup  | Description | Userdata
    -------+---+-------+-------------------+------+----------+-------------+---------
    single | 0 |       |                   | root |          | current     |
    pre    | 1 |       | Mon 06<...>       | root |          |             |
    post   | 2 | 1     | Mon 06<...>       | root |          |             |
    

14.2.1.3. Wrapping a Command in Pre and Post Snapshots

You can also wrap a command within a pre and post snapshot, which can be useful when testing. See Procedure 14.3, “Wrapping a Command in Pre and Post Snapshots”, which is a shortcut for the following steps:
  1. Running the snapper create pre snapshot command.
  2. Running a command or a list of commands to perform actions with a possible impact on the file system content.
  3. Running the snapper create post snapshot command.

Procedure 14.3. Wrapping a Command in Pre and Post Snapshots

  1. To wrap a command in pre and post snapshots:
    # snapper -c lvm_config create --command "command_to_be_tracked"
    For example, to track the creation of the /lvm_mount/hello_file file:
    # snapper -c lvm_config create --command "echo Hello > /lvm_mount/hello_file"
  2. To verify this, use the status command:
    # snapper -c config_file status first_snapshot_number..second_snapshot_number
    For example, to track the changes made in the first step:
    # snapper -c lvm_config status 3..4
    +..... /lvm_mount/hello_file
    
    Use the list command to verify the number of the snapshot if needed.
    For more information on the status command, see Section 14.3, “Tracking Changes Between Snapper Snapshots”.
Note that there is no guarantee that the command in the given example is the only thing the snapshots capture. Snapper also records anything that is modified by the system, not just what a user modifies.

14.2.2. Creating a Single Snapper Snapshot

Creating a single snapper snapshot is similar to creating a pre or post snapshot, only the create -t option specifies single. The single snapshot is used to create a single snapshot in time without having it relate to any others. However, if you are interested in a straightforward way to create snapshots of LVM2 thin volumes without the need to automatically generate comparisons or list additional information, Red Hat recommends using the System Storage Manager instead of Snapper for this purpose, as described in Section 16.2.6, “Snapshot”.
To create a single snapshot, use:
# snapper -c config_name create -t single
For example, the following command creates a single snapshot using the lvm_config configuration file.
# snapper -c lvm_config create -t single
Although single snapshots are not specifically designed to track changes, you can use the snapper diff, xadiff, and status commands to compare any two snapshots. For more information on these commands, see Section 14.3, “Tracking Changes Between Snapper Snapshots”.

14.2.3. Configuring Snapper to Take Automated Snapshots

Taking automated snapshots is one of key features of Snapper. By default, when you configure Snapper for a volume, Snapper starts taking a snapshot of the volume every hour.
Under the default configuration, Snapper keeps:
  • 10 hourly snapshots, and the final hourly snapshot is saved as a “daily” snapshot.
  • 10 daily snapshots, and the final daily snapshot for a month is saved as a “monthly” snapshot.
  • 10 monthly snapshots, and the final monthly snapshot is saved as a “yearly” snapshot.
  • 10 yearly snapshots.
Note that Snapper keeps by default no more that 50 snapshots in total. However, Snapper keeps by default all snapshots created less than 1,800 seconds ago.
The default configuration is specified in the /etc/snapper/config-templates/default file. When you use the snapper create-config command to create a configuration, any unspecified values are set based on the default configuration. You can edit the configuration for any defined volume in the /etc/snapper/configs/config_name file.