jobs: configure local backups

This commit is contained in:
Michele Guerini Rocco 2024-03-19 14:09:33 +01:00
parent b853f2523e
commit 73f26c0186
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450

View File

@ -55,17 +55,12 @@ with lib;
''; '';
}; };
system.fsPackages = [ pkgs.nfs-utils ];
systemd.mounts = lib.singleton systemd.mounts = lib.singleton
{ {
description = "backup NFS volume"; description = "backup volume";
after = [ "network-online.target" ]; what = "/dev/mapper/backup-maxwell";
where = "/mnt/backup";
what = "192.168.1.3:/maxwell"; partOf = [ "backup.service" ];
where = "/mnt/backup";
type = "nfs";
options = "nolock";
}; };
systemd.services.backup = systemd.services.backup =
@ -86,8 +81,8 @@ with lib;
in { in {
description = "system backup"; description = "system backup";
after = [ "network-online.target" "mnt-backup.mount" ]; after = [ "mnt-backup.mount" ];
bindsTo = [ "mnt-backup.mount" ]; requires = [ "mnt-backup.mount" ];
startAt = "*-*-* 03:00"; # every day at 3:00 startAt = "*-*-* 03:00"; # every day at 3:00
onFailure = [ "notify-failed@backup.service" ]; onFailure = [ "notify-failed@backup.service" ];
@ -109,15 +104,16 @@ with lib;
# build indices and save # build indices and save
while read -r dir; do while read -r dir; do
name=$(basename "$dir") {
name=$(basename "$dir")
echo indexing $name...
bup index "$dir" --exclude-from="${excluded}"
echo done
echo indexing $name... echo saving $name...
bup index "$dir" --exclude-from="${excluded}" bup save -n "$name" "$dir" || true
echo done echo done
} || true
echo saving $name...
bup save -n "$name" "$dir"
echo done
done < "${saved}" done < "${saved}"
# postgresql backup # postgresql backup
@ -125,7 +121,7 @@ with lib;
mkdir -p "$dir" mkdir -p "$dir"
echo dumping databases... echo dumping databases...
sudo -u postgres pg_dumpall | gzip > "$dir"/db.bak sudo -u postgres pg_dumpall > "$dir"/db.bak
echo done echo done
echo saving... echo saving...
@ -133,6 +129,10 @@ with lib;
bup save -n postgresql "$dir" --strip-path=/tmp bup save -n postgresql "$dir" --strip-path=/tmp
echo done echo done
echo generating par2 files...
bup fsck -j 8 -g
echo done
# prune backups every week # prune backups every week
if test $(( $(date +%s) / 86400 % 7 )) -eq 0; then if test $(( $(date +%s) / 86400 % 7 )) -eq 0; then
echo pruning... echo pruning...