How to use the command 'btrbk' (with examples)
- Linux
- December 25, 2023
The ‘btrbk’ command is a tool that allows users to create snapshots and remote backups of btrfs subvolumes. It is a versatile backup solution specifically designed for file systems using Btrfs. It provides features such as configurable retention policies, efficient incremental backups, and remote backup capability.
Use case 1: Print statistics about configured subvolumes and snapshots
Code:
sudo btrbk stats
Motivation: When using the ‘btrbk’ command, it is essential to have an understanding of the current state of the configured subvolumes and snapshots. By printing statistics about these, you can easily monitor the backup status, identify potential issues, and assess storage usage.
Explanation: The ‘stats’ subcommand is used to request statistics about the configured subvolumes and snapshots. By running the command with ‘sudo’ privileges, it ensures that the necessary permissions are granted to access and retrieve the required information.
Example output:
Total size of all snapshots: 512 GB
Total number of snapshots: 15
Number of snapshots per subvolume:
- Subvolume 1: 5 snapshots
- Subvolume 2: 10 snapshots
Use case 2: List configured subvolumes and snapshots
Code:
sudo btrbk list
Motivation: To effectively manage backups, it is crucial to have visibility into the configured subvolumes and snapshots. By listing them, users can confirm the correct setup, check the naming conventions, and ensure that all required subvolumes are included in the backup routines.
Explanation: The ’list’ subcommand is used to display the configured subvolumes and snapshots. Running the command with ‘sudo’ privileges ensures that the necessary permissions are available to access the relevant information from the file system.
Example output:
Configured subvolumes:
- Subvolume 1: /mnt/btrfs/subvolume1
- Subvolume 2: /mnt/btrfs/subvolume2
Snapshots of subvolumes:
- Subvolume 1:
- Snapshot 1: /mnt/btrfs/backups/2021-10-01_00:00:01
- Snapshot 2: /mnt/btrfs/backups/2021-10-02_00:00:01
- Subvolume 2:
- Snapshot 1: /mnt/btrfs/backups/2021-10-01_00:00:01
- Snapshot 2: /mnt/btrfs/backups/2021-10-02_00:00:01
Use case 3: Print what would happen in a run without making the displayed changes
Code:
sudo btrbk --verbose dryrun
Motivation: Before actually running the backup routines and potentially making changes to the file system, it is important to be able to preview what would occur without actually performing the actions. This allows users to verify the correctness of the setup and ensure that the desired changes will be made.
Explanation: The ‘–verbose dryrun’ option instructs the ‘btrbk’ command to simulate a backup run and display what actions would be taken without making any changes. By adding ‘sudo’ at the beginning, the command is executed with elevated privileges.
Example output:
The following actions would be performed in the backup run:
- Take snapshot of Subvolume 1: /mnt/btrfs/backups/2021-10-03_00:00:01
- Take snapshot of Subvolume 2: /mnt/btrfs/backups/2021-10-03_00:00:01
- Copy snapshots to remote backup server: 192.168.0.100:/backup/btrfs/
Use case 4: Run backup routines verbosely, show progress bar
Code:
sudo btrbk --progress --verbose run
Motivation: When performing backup routines, it can be helpful to have real-time feedback on the progress of the backup process. By enabling the progress bar and verbose mode, users can track the backup operation, view detailed information, and ensure that the backup is running smoothly.
Explanation: The ‘–progress’ option enables the display of a progress bar during the backup run, providing visual feedback on the completion status. The ‘–verbose’ option enables verbose mode, which displays detailed information about the backup progress. Running the command with ‘sudo’ grants the necessary permissions to execute the backup routines.
Example output:
Running backup routines:
[== ] 5% Estimated time remaining: 2 hours
[===== ] 10% Estimated time remaining: 1 hour 30 minutes
[======== ] 15% Estimated time remaining: 1 hour 15 minutes
...
[========================= ] 50% Estimated time remaining: 45 minutes
...
[==================================================] 100% Backup completed successfully
Use case 5: Only create snapshots for configured subvolumes
Code:
sudo btrbk snapshot
Motivation: Creating snapshots is a vital part of the backup process. By exclusively initiating snapshots for the configured subvolumes, users can focus specifically on this aspect of backup management. This can be useful when wanting to separate the snapshot creation step from other backup operations.
Explanation: The ‘snapshot’ subcommand is used to create snapshots for the configured subvolumes. By running the command with ‘sudo’ privileges, the necessary permissions are granted to create the snapshots in the specified destinations.
Example output:
Snapshots created:
- Snapshot of Subvolume 1: /mnt/btrfs/backups/2021-10-03_00:00:01
- Snapshot of Subvolume 2: /mnt/btrfs/backups/2021-10-03_00:00:01
Conclusion:
The ‘btrbk’ command provides a comprehensive and efficient solution for creating snapshots and remote backups of Btrfs subvolumes. With its various use cases, from printing statistics to creating snapshots and running backup routines, users can easily manage and monitor their backup processes. By leveraging the power of ‘btrbk’, users can ensure the safety and integrity of their critical data.