mirror of
https://codeberg.org/privacy1st/nix-git
synced 2024-11-21 22:03:19 +01:00
yodaHedgehog: WIP backup service
This commit is contained in:
parent
6687d387df
commit
e18ae48dd6
12
examples/block-opensmtpd-queue.sh
Normal file
12
examples/block-opensmtpd-queue.sh
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo -e "Subject: Test\n\nHi there, this is some test." | sendmail -f langbein@mail.de daniel@systemli.org
|
||||||
|
while :; do
|
||||||
|
# Note: smtpctl requires root privileges.
|
||||||
|
queue="$(smtpctl show queue)"
|
||||||
|
if [ "${queue}" = "" ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
printf '%s\n' 'Delaying suspend due to non-empty smtpd email queue.'
|
||||||
|
sleep 5s
|
||||||
|
done
|
@ -9,8 +9,12 @@
|
|||||||
# 2.6W suspended, with 1 RAM, 1 SSD, 2 HDDs
|
# 2.6W suspended, with 1 RAM, 1 SSD, 2 HDDs
|
||||||
# 18.9W idle, with 1 RAM, 1 SSD, 2 HDDs
|
# 18.9W idle, with 1 RAM, 1 SSD, 2 HDDs
|
||||||
|
|
||||||
|
# View service log:
|
||||||
# journalctl -u daily-backup-and-suspend
|
# journalctl -u daily-backup-and-suspend
|
||||||
|
|
||||||
|
# Print unit file:
|
||||||
|
# cat "$(systemctl show -P FragmentPath daily-backup-and-suspend.service)"
|
||||||
|
|
||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
let
|
let
|
||||||
backup-source = "rootNas";
|
backup-source = "rootNas";
|
||||||
@ -42,10 +46,12 @@ in
|
|||||||
# Packages required for this script.
|
# Packages required for this script.
|
||||||
# For `ssh` and `journalwatch`, there are assertions above.
|
# For `ssh` and `journalwatch`, there are assertions above.
|
||||||
path = with pkgs; [
|
path = with pkgs; [
|
||||||
# Provides `echo`, `sleep`, `printf`.
|
|
||||||
coreutils
|
|
||||||
# Provides `ssh`
|
# Provides `ssh`
|
||||||
openssh
|
openssh
|
||||||
|
# Provides `awk`, `grep`, `sleep`, `printf`, `echo`, 'sendmail'
|
||||||
|
busybox
|
||||||
|
# Provides `smtpctl`
|
||||||
|
opensmtpd
|
||||||
];
|
];
|
||||||
# Script to execute as main process.
|
# Script to execute as main process.
|
||||||
script = ''
|
script = ''
|
||||||
@ -56,8 +62,8 @@ in
|
|||||||
|
|
||||||
# Don't suspend as long as `${backup-source}:${stay-awake-file}` exists.
|
# Don't suspend as long as `${backup-source}:${stay-awake-file}` exists.
|
||||||
while :; do
|
while :; do
|
||||||
result="$(ssh ${backup-source} 'ls ${stay-awake-file} 2>&1')"
|
result="$(ssh ${backup-source} 'ls ${stay-awake-file} 2>&1')" ||:
|
||||||
case "$${result}" in
|
case "''${result}" in
|
||||||
*"No such file or directory")
|
*"No such file or directory")
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
@ -72,21 +78,36 @@ in
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Wait until no BTRFS scrub service is running.
|
# Wait until no BTRFS scrub service is running.
|
||||||
while systemctl list-units --type=service --plain --quiet | awk '{ print $1 }' | grep '^btrfs-scrub'; do
|
while :; do
|
||||||
|
running_services="$(systemctl list-units --type=service --plain --quiet | awk '{ print $1 }')"
|
||||||
|
if ! printf '%s' "''${running_services}" | grep '^btrfs-scrub'; then
|
||||||
|
break;
|
||||||
|
fi
|
||||||
printf '%s\n' 'Delaying suspend due to running BTRFS scrub service.'
|
printf '%s\n' 'Delaying suspend due to running BTRFS scrub service.'
|
||||||
sleep 60s
|
sleep 60s
|
||||||
done
|
done
|
||||||
|
|
||||||
# Send filtered journal by email.
|
# Send filtered journal by email.
|
||||||
systemctl start journalwatch.service ||:
|
systemctl start journalwatch.service ||:
|
||||||
# Short delay to let sendmail send the email.
|
# Send notification by email.
|
||||||
|
printf '%s\n\n%s' 'Subject: ${config.networking.hostName}' 'Finished backup.' | sendmail -f langbein@mail.de daniel@systemli.org
|
||||||
|
|
||||||
|
# Let sendmail send emails.
|
||||||
|
#while :; do
|
||||||
|
# # TODO: Plain usage of `smtpctl` gives the error:
|
||||||
|
# # smtpctl: this program must be setgid smtpq
|
||||||
|
# queue="$(smtpctl show queue)"
|
||||||
|
# if [ "''${queue}" = "" ]; then
|
||||||
|
# break
|
||||||
|
# fi
|
||||||
|
# printf '%s\n' 'Delaying suspend due to non-empty smtpd email queue.'
|
||||||
|
# sleep 1s
|
||||||
|
#done
|
||||||
sleep 15s
|
sleep 15s
|
||||||
|
|
||||||
printf '%s\n' 'Finished backup script.'
|
printf '%s\n' 'Finished backup script.'
|
||||||
|
|
||||||
# Suspend to save power.
|
# Suspend to save power.
|
||||||
# TODO
|
systemctl suspend
|
||||||
#systemctl suspend
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user