yodaHedgehog: backup service

This commit is contained in:
Daniel Langbein 2023-11-22 14:32:35 +01:00
parent 9a0f7cac7d
commit f66ecbd985
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
3 changed files with 33 additions and 7 deletions

View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -eu -o pipefail
# Wait until the host yodaNas is reachable with SSH.
while :; do
result="$(ssh yodaNas 'hostname')" && e=0 || e=$?
if [ "${e}" = 0 ] && [ "${result}" = 'yodaNas' ]; then
break
fi
printf '%s\n' 'Delaying due to SSH connectivity problems.'
sleep 10s
done

View File

@ -1,9 +1,10 @@
#!/usr/bin/env bash
set -eu -o pipefail
# As long as there is the file `stay-alive` at host `yodaNas`,
# this loop blocks/waits.
while :; do
result="$(ssh yodaNas 'ls stay-alive 2>&1')"
result="$(ssh yodaNas 'ls stay-alive 2>&1')" || :
case "${result}" in
*"No such file or directory")
break

View File

@ -37,16 +37,12 @@ in
timerConfig = {
OnCalendar = [
# Daily
"*-*-* 00:00:05"
"*-*-* 00:05:00"
];
WakeSystem = true;
};
};
systemd.services."daily-backup-and-suspend" = {
# If the system wakes up at 00:05, it is not directly connected to the Internet.
# Thus, `btrbk` might fail with the following error while connecting to `rootNas`:
# ssh: Could not resolve hostname p1st.de: Name or service not known
# To avoid this, we depend on the `network-online` systemd target.
after = [ "network-online.target" ];
# Packages required for this script.
# For `ssh` and `journalwatch`, there are assertions above.
@ -70,6 +66,23 @@ in
set -eu -o pipefail
#printf '%s\n' 'Starting backup script.'
# Wait until ${backup-source} is reachable.
#
# This test is necessary because of the following:
# If the system wakes up at 00:05, it is not directly connected to the Internet.
# The config option `after = [ "network-online.target" ];` does not help in this regard.
# Thus, `btrbk` might fail with the following error while connecting to ${backup-source}:
# ssh: Could not resolve hostname p1st.de: Name or service not known
#
while :; do
result="$(ssh ${backup-source} 'echo ${backup-source}')" && e=0 || e=$?
if [ "''${e}" = 0 ] && [ "''${result}" = '${backup-source}' ]; then
break
fi
printf '%s\n' 'Delaying backup due to SSH connectivity problems.'
sleep 10s
done
# Pull BTRFS snapshots from ${backup-source}.
btrbk -c /etc/btrbk/remote-backup-ssd.conf run
btrbk -c /etc/btrbk/remote-backup-hdd.conf run
@ -88,7 +101,7 @@ in
printf '%s\n' 'Delaying suspend due to SSH connectivity problems.'
;;
esac
sleep 10s
sleep 60s
done
# Wait until no BTRFS scrub service is running.