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