How to use the command rusnapshot (with examples)
- Linux
- November 5, 2023
Rusnapshot is a BTRFS snapshotting utility written in Rust. It is used to create, list, delete, restore, and manage BTRFS snapshots. BTRFS is a modern Linux filesystem that supports efficient snapshots, allowing users to take an instant copy of a filesystem at a specific point in time. Rusnapshot leverages BTRFS snapshots to provide these functionalities.
Use case 1: Create a snapshot using a config file
Code:
sudo rusnapshot --config path/to/config.toml --cr
Motivation: This use case is useful when you want to create a snapshot based on the configurations defined in a specific config file. It allows a user to quickly create a snapshot without having to specify all the parameters manually.
Explanation:
sudo
: This command is run with superuser privileges.rusnapshot
: The rusnapshot command.--config path/to/config.toml
: Specifies the path to the config file containing the snapshot configurations.--cr
: Creates a read-only snapshot.
Example Output:
Snapshot created successfully.
Use case 2: List created snapshots
Code:
sudo rusnapshot -c path/to/config.toml --list
Motivation: This use case allows users to list all the snapshots created based on the configurations specified in the config file. It provides a convenient way to view and manage existing snapshots.
Explanation:
sudo
: This command is run with superuser privileges.rusnapshot
: The rusnapshot command.-c path/to/config.toml
: Specifies the path to the config file containing the snapshot configurations.--list
: Lists all the created snapshots.
Example Output:
Snapshot ID Name Date
---------------------------------------------------------------------
1 snapshot1 2022-01-01 12:00:00
2 snapshot2 2022-01-02 12:00:00
Use case 3: Delete a snapshot by ID or the name of the snapshot
Code:
sudo rusnapshot -c path/to/config.toml --del --id snapshot_id
Motivation: This use case allows users to delete a specific snapshot based on its ID or name. It provides a flexible way to remove unnecessary snapshots to free up disk space.
Explanation:
sudo
: This command is run with superuser privileges.rusnapshot
: The rusnapshot command.-c path/to/config.toml
: Specifies the path to the config file containing the snapshot configurations.--del
: Deletes the specified snapshot.--id snapshot_id
: Specifies the ID of the snapshot to be deleted.
Example Output:
Snapshot with ID 1 deleted successfully.
Use case 4: Delete all hourly
snapshots
Code:
sudo rusnapshot -c path/to/config.toml --list --keep 0 --clean --kind hourly
Motivation: This use case allows users to delete all the hourly
snapshots created based on the configurations specified in the config file. It can be useful when you want to clean up old unnecessary snapshots and only keep the most recent ones.
Explanation:
sudo
: This command is run with superuser privileges.rusnapshot
: The rusnapshot command.-c path/to/config.toml
: Specifies the path to the config file containing the snapshot configurations.--list
: Lists all the created snapshots.--keep 0
: Specifies to keep 0 snapshots.--clean
: Cleans up the specified snapshots.--kind hourly
: Specifies the kind of snapshots to delete. In this case, all snapshots with the kindhourly
will be deleted.
Example Output:
All hourly snapshots deleted successfully.
Use case 5: Create a read-write snapshot
Code:
sudo rusnapshot -c path/to/config.toml --cr --rw
Motivation: This use case allows users to create a read-write snapshot. Read-write snapshots provide a way to make changes to a snapshot without modifying the original filesystem. It can be useful for testing or experimenting without affecting the production system.
Explanation:
sudo
: This command is run with superuser privileges.rusnapshot
: The rusnapshot command.-c path/to/config.toml
: Specifies the path to the config file containing the snapshot configurations.--cr
: Creates a read-only snapshot.--rw
: Creates a read-write snapshot.
Example Output:
Snapshot created successfully.
Use case 6: Restore a snapshot
Code:
sudo rusnapshot -c path/to/config.toml --id snapshot_id --restore
Motivation: This use case allows users to restore a specific snapshot based on its ID. It provides a way to revert the filesystem to a previous state, effectively undoing any changes made after the snapshot was created.
Explanation:
sudo
: This command is run with superuser privileges.rusnapshot
: The rusnapshot command.-c path/to/config.toml
: Specifies the path to the config file containing the snapshot configurations.--id snapshot_id
: Specifies the ID of the snapshot to be restored.--restore
: Restores the specified snapshot.
Example Output:
Snapshot with ID 1 restored successfully.
Conclusion
Rusnapshot is a powerful and flexible command-line tool for managing BTRFS snapshots. It provides a convenient way to create, list, delete, and restore snapshots, giving users control over the filesystem’s state. By utilizing BTRFS snapshots, rusnapshot enables efficient and reliable filesystem backup and recovery operations.