From eb467a15cbd126a67e88cf619e3126ac30304aee Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Wed, 17 Feb 2021 01:30:11 -0500 Subject: [PATCH] btrbk fixes --- btrbk-run | 31 ++++++++++++++++--------------- mount-latest-subvol | 12 ++++++++---- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/btrbk-run b/btrbk-run index 9587ce9..2b21e82 100644 --- a/btrbk-run +++ b/btrbk-run @@ -164,6 +164,7 @@ if [[ ! -v targets && ! $source ]]; then at_work=false + targets=(frodo.b8.nz) case $HOSTNAME in kw) at_work=true @@ -182,21 +183,21 @@ if [[ ! -v targets && ! $source ]]; then fi ;;& kw) - targets=($home x3) + targets+=($home x3) ;; x2|x3) - targets=($home kw.office.fsf.org) + targets+=($home kw.office.fsf.org) ;; kd) - # todo: add frodo when it comes back online - targets=(x2.b8.nz frodo.b8.nz) + targets+=(x2.b8.nz) # might not be connected to the vpn if timeout -s 9 6 ssh kw.office.fsf.org :; then targets+=(kw.office.fsf.org) fi ;; frodo) - : # no targets + # no targets + targets=() ;; *) die "error: no default targets for this host, use -t" @@ -266,7 +267,7 @@ echo "mountpoints: ${mountpoints[*]}" ##### end command line parsing ######## if [[ $source ]]; then - if [[ $(ssh $source systemctl is-active btrbk.service) != inactive ]]; then + if [[ $(ssh $source ps --no-headers -o comm 1) == systemd && $(ssh $source systemctl is-active btrbk.service) != inactive ]]; then echo "$0: error: cron btrbk is running on source. exiting out of caution" mexit 1 fi @@ -425,15 +426,15 @@ EOF fi done -# if $amy; then -# # to manually backup amy, -# # bbk -e -s amy -m root_ubuntubionic -# cat >>/etc/btrbk.conf <<'EOF' -# volume ssh://amy/mnt/root -# subvolume root_ubuntubionic -# target send-receive /mnt/root/btrbk -# EOF -# fi +if $amy; then + # to manually backup amy, + # bbk -e -s amy -m root_ubuntubionic + cat >>/etc/btrbk.conf <<'EOF' +volume ssh://amy/mnt/root +subvolume root_ubuntubionic +target send-receive /mnt/root/btrbk +EOF +fi # todo: umount first to ensure we don't have any errors # todo: do some kill fuser stuff to make umount more reliable diff --git a/mount-latest-subvol b/mount-latest-subvol index 04cca81..64e22f1 100644 --- a/mount-latest-subvol +++ b/mount-latest-subvol @@ -335,13 +335,17 @@ for vol in q a o i; do ## begin expire leaf vols ## leaf_vols=($vol.leaf.*) - count=1 + count=${#leaf_vols[@]} + leaf_limit_time=$(( $(date +%s) - 60*60*24*60 )) # 60 days + leaf_new_limit_time=$(( $(date +%s) - 60*60*24 )) # 1 day + # this goes backwards from oldest. leaf_new_limit_time is just in case + # the order gets screwed up or something. for leaf in ${leaf_vols[@]}; do - leaf_secs=$(date -d ${leaf#$vol.leaf.} +%s) - if (( $(date +%s) - 60*60*24*60 > leaf_secs || count > 100 )); then # 60 days + leaf_time=$(date -d ${leaf#$vol.leaf.} +%s) + if (( leaf_limit_time > leaf_time || ( leaf_new_limit_time > leaf_time && count > 100 ) )); then x btrfs sub del $leaf fi - count=$((count+1)) + count=$((count-1)) done ## end expire leaf vols ## fi -- 2.30.2