Backup workflow improvements
* move tunnel for nextcloud-web into separate file * add script to check for running backups and shutdown server otherwise
This commit is contained in:
parent
e10f277854
commit
60ca29289e
|
@ -7,6 +7,8 @@ in
|
|||
{
|
||||
imports = [
|
||||
./configuration.nix
|
||||
./nextcloud-web-tunnel.nix
|
||||
./restic-backup.nix
|
||||
];
|
||||
|
||||
config = {
|
||||
|
@ -27,26 +29,6 @@ in
|
|||
}
|
||||
];
|
||||
|
||||
services.openssh.knownHosts = {
|
||||
"cloud.pub.solar".publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIABPJSwr9DfnqV0KoL23BcxlWtRxuOqQpnFnCv4SG/LW";
|
||||
};
|
||||
|
||||
systemd.services.ssh-tunnel-cloud-pub-solar = {
|
||||
unitConfig = {
|
||||
Description = "Reverse SSH connection to enable backups from IPv4-only to IPv6-only host";
|
||||
After = [ "network.target" ];
|
||||
};
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
ExecStart = "${pkgs.openssh}/bin/ssh -vvv -g -N -T -o 'ServerAliveInterval 10' -o 'ExitOnForwardFailure yes' -R 127.0.0.1:22022:localhost:22 root@cloud.pub.solar";
|
||||
User = psCfg.user.name;
|
||||
Group = "users";
|
||||
Restart = "always";
|
||||
RestartSec = "5s";
|
||||
};
|
||||
wantedBy = [ "default.target" ];
|
||||
};
|
||||
|
||||
services.ddclient = {
|
||||
enable = true;
|
||||
ipv6 = true;
|
||||
|
|
25
hosts/droppie/nextcloud-web-tunnel.nix
Normal file
25
hosts/droppie/nextcloud-web-tunnel.nix
Normal file
|
@ -0,0 +1,25 @@
|
|||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
config = {
|
||||
services.openssh.knownHosts = {
|
||||
"cloud.pub.solar".publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIABPJSwr9DfnqV0KoL23BcxlWtRxuOqQpnFnCv4SG/LW";
|
||||
};
|
||||
|
||||
systemd.services.ssh-tunnel-cloud-pub-solar = {
|
||||
unitConfig = {
|
||||
Description = "Reverse SSH connection to enable backups from IPv4-only to IPv6-only host";
|
||||
After = [ "network.target" ];
|
||||
};
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
ExecStart = "${pkgs.openssh}/bin/ssh -vvv -g -N -T -o 'ServerAliveInterval 10' -o 'ExitOnForwardFailure yes' -R 127.0.0.1:22022:localhost:22 root@cloud.pub.solar";
|
||||
User = psCfg.user.name;
|
||||
Group = "users";
|
||||
Restart = "always";
|
||||
RestartSec = "5s";
|
||||
};
|
||||
wantedBy = [ "default.target" ];
|
||||
};
|
||||
};
|
||||
}
|
50
hosts/droppie/restic-backup.nix
Normal file
50
hosts/droppie/restic-backup.nix
Normal file
|
@ -0,0 +1,50 @@
|
|||
{ pkgs, ... }:
|
||||
|
||||
let
|
||||
shutdownWaitMinutes = 15;
|
||||
shutdownScript = pkgs.writeScript "shutdown" ''
|
||||
STATUS_FILES="/media/internal/backups-pub-solar/status"
|
||||
|
||||
running=""
|
||||
|
||||
for f in $STATUS_FILES; do
|
||||
declare started
|
||||
declare finished
|
||||
|
||||
started=$(source $f ; echo ''${BACKUP_STARTED})
|
||||
finished=$(source $f ; echo ''${BACKUP_FINISHED})
|
||||
|
||||
if [ -z "''${finished}" ]; then
|
||||
echo "backup $(dirname $f) still running"
|
||||
running="yes"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "''${running}" ] && [ "''${running}" = "yes" ]; then
|
||||
echo "backups are still running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "WARNING: System will be shut down within the next 15 minutes" | wall
|
||||
|
||||
sleep 10
|
||||
|
||||
shutdown -P +${builtins.toString shutdownWaitMinutes}
|
||||
'';
|
||||
in
|
||||
{
|
||||
systemd.services."shutdown-after-backup" = {
|
||||
enable = true;
|
||||
serviceConfig = {
|
||||
ExecStart = shutdownScript;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers."shutdown-after-backup" = {
|
||||
enable = true;
|
||||
serviceConfig = {
|
||||
OnCalendar = "3..9:*";
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue