How to use the command snapper (with examples)
- Linux
- December 25, 2023
The snapper
command is a filesystem snapshot management tool that allows users to manage and manipulate snapshots of a given directory or filesystem. This tool is particularly useful for system administrators who need to easily create, manage, and delete snapshots.
Use case 1: List snapshot configs
Code:
snapper list-configs
Motivation:
This use case is useful when you want to retrieve a list of all available snapshot configurations. It helps to understand the existing configurations that can be used with other snapper
commands.
Explanation:
The list-configs
option is used with the snapper
command to display a list of all available snapshot configurations.
Example output:
Config | Subvolume
-------+----------
1 | /
2 | /home
3 | /var
This output shows the available configurations with their corresponding subvolumes.
Use case 2: Create snapper config
Code:
snapper -c config create-config path/to/directory
Motivation:
This use case is useful when you want to create a new snapshot configuration for a specific directory. It is a prerequisite for creating and managing snapshots within that directory.
Explanation:
The create-config
option is used with the snapper
command to create a snapper configuration for a given directory. The path/to/directory
argument specifies the directory for which the configuration is created.
Example output:
Created configuration for path '/path/to/directory'.
This output confirms the successful creation of the snapper configuration for the specified directory.
Use case 3: Create a snapshot with a description
Code:
snapper -c config create -d "snapshot_description"
Motivation:
This use case is useful when you want to create a new snapshot with a descriptive comment or label in order to better identify and manage the snapshots later.
Explanation:
The create
option is used with the snapper
command to create a new snapshot. The -c config
argument specifies the configuration to use for creating the snapshot. The -d "snapshot_description"
argument is optional and can be used to provide a description for the snapshot.
Example output:
Created snapshot snapshot_number.
This output confirms the successful creation of the snapshot, along with its corresponding snapshot number.
Use case 4: List snapshots for a config
Code:
snapper -c config list
Motivation:
This use case is useful when you want to view a list of all the snapshots available for a specific configuration. It provides an overview of the existing snapshots and their details.
Explanation:
The list
option is used with the snapper
command to display a list of all the snapshots available for a particular configuration. The -c config
argument specifies the configuration for which the snapshots should be listed.
Example output:
# | Type | Pre # | Filename
--+--------+-------+------------------
0 | single | | /path/to/snapshot
1 | single | | /path/to/another/snapshot
2 | single | | /path/to/yet/another/snapshot
This output shows the list of snapshots available for the specified configuration, along with their corresponding types, previous snapshot numbers (if any), and filenames.
Use case 5: Delete a snapshot
Code:
snapper -c config delete snapshot_number
Motivation:
This use case is useful when you want to delete a specific snapshot within a configuration. It provides a way to remove unnecessary snapshots and free up disk space.
Explanation:
The delete
option is used with the snapper
command to delete a specific snapshot. The -c config
argument specifies the configuration from which the snapshot should be deleted, and the snapshot_number
argument specifies the snapshot to be deleted.
Example output:
Deleted snapshot snapshot_number.
This output confirms the successful deletion of the specified snapshot.
Use case 6: Delete a range of snapshots
Code:
snapper -c config delete snapshot_X-snapshot_Y
Motivation:
This use case is useful when you want to delete a range of snapshots within a configuration. It allows for batch deletion of multiple snapshots at once.
Explanation:
The delete
option is used with the snapper
command to delete a range of snapshots. The -c config
argument specifies the configuration from which the snapshots should be deleted, and the snapshot_X-snapshot_Y
argument specifies the range of snapshots to be deleted, from snapshot_X
to snapshot_Y
.
Example output:
Deleted range of snapshots from snapshot_X to snapshot_Y.
This output confirms the successful deletion of the specified range of snapshots.
Conclusion:
The snapper
command provides a powerful set of tools for managing and manipulating filesystem snapshots. By using the various options and arguments provided by the command, users can easily create, manage, and delete snapshots for different configurations. This allows for efficient snapshot management and enables system administrators to easily track changes and revert to previous states if necessary.