Arvin Schnell, 11 November 2024
Btrfs provides an efficient way to transfer snapshots from one location to another using btrfs send and receive. The new program snbk uses this method to make backups of snapper snapshots either on a local or remote btrfs filesystem.
First you have to create a backup config file in /etc/snapper/backup-configs. These files are in JSON format. So far snbk supports two “target modes”: “local” and “ssh-push”.
If your backup is on a local filesystem use “local”. Here is an example backup config:
{
"config": "root",
"target-mode": "local",
"automatic": true,
"source-path": "/",
"target-path": "/backup"
}
“config” is the snapper config to use, “target-path” is the path to the btrfs filesystem where the backup are stored. Setting “automatic” to true enables an hourly backup.
Here is an example for a remote backup:
{
"config": "root",
"target-mode": "ssh-push",
"automatic": true,
"source-path": "/",
"target-path": "/backups/eberich",
"ssh-host": "192.168.1.111",
"ssh-identity": "/etc/snapper/certs/id_ecdsa"
}
Additional parameters are “ssh-user” and “ssh-port”. If you want automatic backups the ssh-identity must work without a pass phrase. For automatic backups also enable and start the snapper-backup.timer service.
snbk supports a few commands:
“snbk list-configs” list the backup configs.
# snbk list-configs
Backup Config │ Config │ Target Mode │ Automatic │ Source Path │ Target Path
──────────────┼────────┼─────────────┼───────────┼─────────────┼────────────
root-local │ root │ local │ yes │ / │ /backup
“snbk list” list the backups for all backup configs. Use the option –backup-config/-b to list the backups of a single backup config, e.g. “snbk -b root-local list”.
# snbk list
# │ Date │ Source State │ Target State
────┼──────────────────────────┼──────────────┼─────────────
11 │ Mon Sep 30 12:00:20 2024 │ read-only │ valid
18 │ Tue Oct 1 11:00:00 2024 │ read-only │ valid
29 │ Wed Oct 2 08:00:26 2024 │ read-only │ valid
57 │ Fri Oct 4 08:24:23 2024 │ │ valid
58 │ Fri Oct 4 08:25:42 2024 │ │ valid
59 │ Fri Oct 4 09:00:13 2024 │ read-only │
Here are 6 snapshots, some only on the source and some only on the target side. Snapshots with source state read-write cannot be backup-ed. If the target state is invalid the transfer from source to target was most likely interrupted.
“snbk transfer” makes backups of all read-only source snapshots.
Here running the transfer command will copy snapshot 59 to the target.
“snbk delete” removes outdated and invalid snapshots from the target.
Here running the delete command will remove snapshots 57 and 58 on the target.
“snbk transfer-and-delete” combines transfer and delete.
An additional option is –target-mode=mode which limits the commands to backup configs with the specified target mode.
For more information read the man-page.
The program snbk is available in snapper (sub-package snapper-backup) since version 0.12.0.