digint / digint/btrbk

Check if a external drive is mounted before snapshot / backup

Open
#520 11 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Perl
Stars
2.1k
Forks
139
PR merge metrics
No merged PRs in 30d

Description

Hello there!

I had this happen to me before and is happening again. I have mine set up to make local snapshots and also backup and snapshots to a external drive.
Some times BTRBK ignores that the drive is not mounted and backups/snapshots anyway. Did I configure something wrong?

I use /btfs_pool for the snapshots /btrfs_backup for the external backup + snapshots drive. The drive is not connected right now, but it also happened many times.

```
ls /btrfs_backup/ ✘ 16 10:19:03
home.20221005T0001/ home.20221026T102727-0300/ home.20221030T000000-0300/ home.20221105T000143-0300/ root.20221008T1439/ root.20221217T000000-0300/ root.20221221T000000-0300/
home.20221009T081430-0300/ home.20221027T081940-0300/ home.20221031T000001-0300/ home.20221106T000000-0300/ root.20221106T000000-0300/ root.20221218T000002-0300/ root.20221222T000000-0300/
home.20221016T000102-0300/ home.20221028T000001-0300/ home.20221101T000000-0300/ home.20221107T092408-0300/ root.20221116T000000-0300/ root.20221219T000000-0300/ root.20221223T000000-0300/
home.20221023T083304-0300/ home.20221029T101632-0300/ home.20221102T000000-0300/ home.20221108T000000-0300/ root.20221216T084715-0300/ root.20221220T000001-0300/ root.20221224T000000-0300/
```

```
/etc/fstab
...
# BTRBK backups
UUID=3f835c73-1a8c-4bca-9646-4cbd60bc7c6d /btrfs_pool btrfs subvolid=5,compress=zstd:1,noatime,x-systemd.device-timeout=0,x-systemd.after=/ 0 0
UUID=/dev/mapper/luks-afaa1238-7ece-40e4-a069-c33b3ccf9140 /btrfs_backup btrfs subvolid=5,nofail,space_cache=v2,compress=zstd:3,noatime,x-gvfs-show,x-systemd.device-timeout=0,x-systemd.after=/ 0 0
...
~ ❯ doas btrbk list config
SOURCE_SUBVOLUME SNAPSHOT_PATH SNAPSHOT_NAME TARGET_PATH
/btrfs_pool/root /btrfs_pool/btrbk_snapshots root /btrfs_backup
/btrfs_pool/home /btrfs_pool/btrbk_snapshots home /btrfs_backup

~ ❯ doas btrbk list source
SOURCE_SUBVOLUME SNAPSHOT_PATH SNAPSHOT_NAME
/btrfs_pool/root /btrfs_pool/btrbk_snapshots root
/btrfs_pool/home /btrfs_pool/btrbk_snapshots home

~ ❯ cat /etc/btrbk/btrbk.conf
transaction_log /var/log/btrbk.log
lockfile /var/lock/btrbk.lock
timestamp_format long-iso
stream_buffer 256m
#incremental strict

snapshot_dir btrbk_snapshots
snapshot_preserve_min latest
snapshot_preserve 3h 5d 0w 0m 0y
target_preserve_min latest
target_preserve 0h 14d 6w 4m 1y
archive_preserve 0h 1d 1w 1m 1y
archive_preserve_min latest

volume /btrfs_pool
snapshot_create ondemand
target send-receive /btrfs_backup
subvolume root
subvolume home

# Enable stream buffer. Adding a buffer between the sending and
# receiving side is generally a good idea.
# NOTE: If enabled, make sure to install the "mbuffer" package!
#stream_buffer 256m
#btrfs_commit_delete yes

#snapshot_dir btrbk_snapshots
#incremental yes
#snapshot_preserve_min 18h
#snapshot_preserve 48h 7d
#target_preserve_min 6h
#target_preserve 24h 24d 24w

#volume /btrfs_pool
# snapshot_create ondemand
# incremental yes
# target send-receive /btrfs_backup
# subvolume root
# subvolume home

~ ❯ cat /usr/lib/systemd/system/btrbk.service
[Unit]
Description=btrbk backup
Documentation=man:btrbk(1)

[Service]
Type=oneshot
ExecStart=/usr/bin/btrbk run

~ ❯ cat /usr/lib/systemd/system/btrbk.timer
[Unit]
Description=btrbk daily backup

[Timer]
OnCalendar=daily
AccuracySec=10min
Persistent=true

[Install]
WantedBy=timers.target

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reported /etc/btrbk/btrbk.conf and the btrbk run entry point invoked by /usr/bin/btrbk, then review the systemd service and timer files. Reproduce a scheduled run with /btrfs_backup unmounted and compare the resulting snapshots, backups, and log output with the expected safe behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, perl
Domain
devops, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.