at_work=false
+ targets=(frodo.b8.nz)
case $HOSTNAME in
kw)
at_work=true
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"
##### 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
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
## 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