Open msmafra opened 1 year ago
Yeah, it won't check that it's mounted.
I back up to an external USB drive, where it may or not be plugged in. I have this listed in my /etc/fstab
with nofail,x-systemd.device-timeout=10
, so if it's not plugged in at boot the system will just continue to chug along.
So, what I do is I have a script that looks like this:
#!/bin/bash
# I use `mount -U` here to mount /usb_snapshots, -U is the uuid. You can use whatever you want here, such as label etc. check `man mount`.
sudo mount -U db2f33c2-aaaa-aaaa-aaaa-9bbe19ebe734
# Here I check if /usb_snapshots is now mounted.
if mountpoint -q /usb_snapshots; then
# I then run btrbk
btrbk -c /etc/btrbk/btrbk_usb.conf -v run
#curl https://hc-ping.com/xxx # I use hc-ping as a poorman's alerting system :-)
# Unmount /usb_snapshots, I prefer this drive usually unmounted.
sudo umount /usb_snapshots
else
echo "not mounted" # probably alert here.
exit 1
fi
Yeah, it won't check that it's mounted.
I backup to an external USB drive, where it may or not be plugged in. I have this listed in my
/etc/fstab
withnofail,x-systemd.device-timeout=10
, so if it's not plugged in at boot the system will just continue to chug along.So what I do is I have a script that looks like this:
#!/bin/bash # I use `mount -a` here to mount /usb_snapshots, -a mounts all file systems defined in fstab mount -a # Here I check if /usb_snapshots is now mounted. if mountpoint -q /usb_snapshots; then # I then run btrbk btrbk -c /etc/btrbk/btrbk_usb.conf -v run #curl https://hc-ping.com/xxx # I use hc-ping as a poormans alerting system :-) # Unmount /usb_snapshots, I prefer to have this drive usually umounted. sudo umount /usb_snapshots else echo "not mounted" # probably alert here. exit 1 fi
That's a good and simple solution, I'll use it for when I run btrbk manually. To solve the service side I added the Requires parameter to the btrbk.service using the .mount unit that Systemd already creates automatically from fstab's information. So it won't run if it's not mounted. Mounting and umounting after the backup tasks are done is very good thing to do.
[Unit]
Description=Runs btrbk backup and snapshots
Documentation=man:btrbk(1)
Requires=btrbk_backups.mount
[Service]
Type=oneshot
ExecStart=/usr/bin/btrbk run
I'll mess with your script and try testing it for a while
#!/usr/bin/env bash
LC_ALL=C
LANG=C
declare MOUNT_POINT
MOUNT_POINT="/btrbk_backups"
check_space() {
# check percentage of occupied space
local available_space
local space_alert
available_space="$(df --type=btrfs ${MOUNT_POINT} --output=pcent | sed -n '/%/{ n; p }' | sed 's/\%//g' | awk '{$1=$1};1' | tee /dev/null 2>&1)"
space_alert="91"
if [[ "${available_space}" -le ${space_alert} ]]; then
printf "%s\n" "${available_space} is less 91"
else
exit 1
fi
}
run_btrbk() {
# Run BTRBK if check_space is true
local mount_exec
local mountpoint_exec
local btrbk_exec
# local btrbk_conf
local priv_exec
local umount_exec
mount_exec="$(command -v mount | tee /dev/null 2>&1)"
mountpoint_exec="$(command -v mountpoint | tee /dev/null 2>&1)"
btrbk_exec="$(command -v btrbk | tee /dev/null 2>&1)"
# btrbk_conf="/etc/btrbk/btrbk.conf"
# set the priviledges elevator to use: doas or sudo
priv_exec="$(command -v doas| tee /dev/null 2>&1)"
umount_exec="$(command -v umount | tee /dev/null 2>&1)"
# mounting the backup mounting point
"${priv_exec}" "${mount_exec}" --verbose "${MOUNT_POINT}"
# Here I check if mount_point is now mounted.
if "${mountpoint_exec}" --quiet "${MOUNT_POINT}"; then
# run btrbk with the default configuration file
"${btrbk_exec}" --verbose run
# Unmount
"${priv_exec}" "${umount_exec}" "${MOUNT_POINT}"
else
printf "%s\n" "Not mounted"
exit 1
fi
}
main() {
check_space
run_btrbk
}
main "${@}"
Yeah, it won't check that it's mounted.
Correct. The point is that btrbk cannot know if something is mounted on your "volume": if the rootfs /
is a btrfs filesystem, volume /btrfs_pool
is already a valid source.
The only thing I could do would be to somehow "pin" a volume to a filesystem device (or UUID), something like:
volume /btrfs_pool
require_mount_from /dev/sdX
or:
volume /btrfs_pool
must_be_mount_point
The latter sounds pretty straight forward, it would simply check if some btrfs file system is mounted at /btrfs_pool
.
Will put some more thoughts on that, and hope to find some time for it soon (sadly pretty busy with many other things atm...)
That would be phenomenal.
Using the systemd units did not work. Probably there is some configuration missing, something I didn't get correctly.
I did a "wrapper" of sorts and also made some changes to my .conf file. Also learned that I miss understood the commands and how to configure it, probably do not understand it completely yet. At least, I'm now using resume and snapshot instead of always using run: https://gist.github.com/msmafra/ba2d0160ac454973209c00add70eea67
Would it not make more sense to run btrbk archive command for occasionally connected target drives? And then perhaps support archive targets in conf: only if/when there is a btrfs mountpoint behind that path, archive to it, otherwise skip and only use the regular targets.
Would it not make more sense to run btrbk archive command for occasionally connected target drives?
It depends. btrbk archive
does not guarantee you that the latest common snapshot/backup. Then again, if you keep the snapshots on the sources long enough anyways, this is the way to go.
And then perhaps support archive targets in conf: only if/when there is a btrfs mountpoint behind that path, archive to it, otherwise skip and only use the regular targets.
-> adding "enhancement" tag, implement something like: https://github.com/digint/btrbk/issues/520#issuecomment-1374960899
btrbk isn't usable because of this bug
The easy "fix" is to have a target in a directory, not at the root of the external drive. Btrbk never creates the target directory itself, so if the drive is not available, it will fail.
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.