a bit more robust backups; not done yet

This commit is contained in:
Motiejus Jakštys 2023-01-22 16:31:18 +02:00
parent b6e854b1c3
commit f4d306cd7d

View File

@ -5,7 +5,10 @@
{ config, pkgs, lib, ... }:
let
snapshot_dirs = [ "/var" "/var/lib" ];
snapshot_dirs = {
"/var/log" = "rpool/nixos/var/log";
"/var/lib" = "rpool/nixos/var/lib";
};
ssh_pubkeys = {
motiejus = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC+qpaaD+FCYPcUU1ONbw/ff5j0xXu5DNvp/4qZH/vOYwG13uDdfI5ISYPs8zNaVcFuEDgNxWorVPwDw4p6+1JwRLlhO4J/5tE1w8Gt6C7y76LRWnp0rCdva5vL3xMozxYIWVOAiN131eyirV2FdOaqTwPy4ouNMmBFbibLQwBna89tbFMG/jwR7Cxt1I6UiYOuCXIocI5YUbXlsXoK9gr5yBRoTjl2OfH2itGYHz9xQCswvatmqrnteubAbkb6IUFYz184rnlVntuZLwzM99ezcG4v8/485gWkotTkOgQIrGNKgOA7UNKpQNbrwdPAMugqfSTo6g8fEvy0Q+6OXdxw5X7en2TJE+BLVaXp4pVMdOAzKF0nnssn64sRhsrUtFIjNGmOWBOR2gGokaJcM6x9R72qxucuG5054pSibs32BkPEg6Qzp+Bh77C3vUmC94YLVg6pazHhLroYSP1xQjfOvXyLxXB1s9rwJcO+s4kqmInft2weyhfaFE0Bjcoc+1/dKuQYfPCPSB//4zvktxTXud80zwWzMy91Q4ucRrHTBz3PrhO8ys74aSGnKOiG3ccD3HbaT0Ff4qmtIwHcAjrnNlINAcH/A2mpi0/2xA7T8WpFnvgtkQbcMF0kEKGnNS5ULZXP/LC8BlLXxwPdqTzvKikkTb661j4PhJhinhVwnQ==";
vno1_root = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMiWb7yeSeuFCMZWarKJD6ZSxIlpEHbU++MfpOIy/2kh";
@ -62,7 +65,7 @@ let
lsof
file
htop
ncdu
#ncdu
sqlite
ripgrep
binutils
@ -113,7 +116,7 @@ let
autoprune = true;
};
datasets."rpool/nixos/home".use_template = [ "prod" ];
datasets."rpool/nixos/var".use_template = [ "prod" ];
datasets."rpool/nixos/var/log".use_template = [ "prod" ];
datasets."rpool/nixos/var/lib".use_template = [ "prod" ];
extraArgs = [ "--verbose" ];
};
@ -123,27 +126,25 @@ let
paths = [
"/var/lib/.snapshot-latest/gitea"
"/var/lib/.snapshot-latest/headscale"
"/var/.snapshot-latest/log/caddy/access-beta.jakstys.lt.log-*.zst"
"/var/log/.snapshot-latest/caddy/access-beta.jakstys.lt.log-*.zst"
];
repository = "sftp:zh2769@zh2769.rsync.net:hel1-a.servers.jakst";
initialize = true;
passwordFile = "/var/src/secrets/restic/password";
pruneOpts = [
"--keep-daily 7"
"--keep-weekly 5"
];
backupPrepareCommand = ''
set -euo pipefail
'' + lib.concatMapStringsSep "\n" (e: ''
${pkgs.util-linux}/bin/umount ${e}/.snapshot-latest || :
mkdir -p ${e}/.snapshot-latest
${pkgs.util-linux}/bin/mount -t zfs $(${pkgs.zfs}/bin/zfs list -H -t snapshot -o name ${e} | sort | tail -1) ${e}/.snapshot-latest
'') snapshot_dirs;
backupCleanupCommand = ''
set -euo pipefail
'' + lib.concatMapStringsSep "\n" (e: ''
${pkgs.util-linux}/bin/umount ${e}/.snapshot-latest
backupPrepareCommand = let
prepLines = lib.mapAttrsToList (name: value: ''
${pkgs.util-linux}/bin/umount ${name}/.snapshot-latest || : &>/dev/null
mkdir -p ${name}/.snapshot-latest
${pkgs.util-linux}/bin/mount -t zfs $(${pkgs.zfs}/bin/zfs list -H -t snapshot -o name ${value} | sort | tail -1) ${name}/.snapshot-latest
'') snapshot_dirs;
in "set -euo pipefail\n" + lib.concatStringsSep "\n" prepLines;
backupCleanupCommand = let
cleanupLines = lib.mapAttrsToList (name: value: "${pkgs.util-linux}/bin/umount ${name}/.snapshot-latest") snapshot_dirs;
cleanupString = lib.concatStringsSep "\n" cleanupLines;
in "set -euo pipefail\n" + cleanupString;
timerConfig = {
OnCalendar = "00:10";
RandomizedDelaySec = "1h";
@ -281,6 +282,9 @@ let
};
};
# TODO: compress static stuff
#${pkgs.findutils}/bin/find ${pkgs.gitea.data} -name '*.css' -exec ${pkgs.brotli}/bin/brotli {} \+
networking = {
hostName = "hel1-a";
firewall = {