🏡 my personal home lab
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add db backups

+83
+42
modules/immich.nix
··· 7 7 mediaLocation = "/mnt/nas/data/immich"; 8 8 secretsFile = config.sops.templates."immich.env".path; 9 9 settings = { 10 + server = { 11 + externalDomain = "https://photos.goo.garden"; 12 + }; 10 13 oauth = { 11 14 enabled = true; 12 15 autoRegister = true; ··· 21 24 systemd.services.immich-server = { 22 25 after = [ "mnt-nas.mount" ]; 23 26 requires = [ "mnt-nas.mount" ]; 27 + }; 28 + 29 + services.postgresqlBackup = { 30 + enable = true; 31 + databases = [ "immich" ]; 32 + location = "/mnt/nas/backup/immich/db"; 33 + startAt = "daily"; 34 + }; 35 + 36 + # Rotate immich db backups: keep 14 daily, 1 per month after that 37 + systemd.services.immich-db-backup-rotate = { 38 + description = "Rotate Immich DB backups"; 39 + after = [ 40 + "postgresqlBackup-immich.service" 41 + "mnt-nas.mount" 42 + ]; 43 + requires = [ "mnt-nas.mount" ]; 44 + wantedBy = [ "postgresqlBackup-immich.service" ]; 45 + serviceConfig = { 46 + Type = "oneshot"; 47 + ExecStart = toString [ 48 + "/run/current-system/sw/bin/bash" 49 + "-c" 50 + '' 51 + dir=/mnt/nas/backup/immich/db 52 + # keep first of each month 53 + for f in "$dir"/immich.sql.gz.*; do 54 + [ -f "$f" ] || continue 55 + age=$(( ($(date +%s) - $(date -r "$f" +%s)) / 86400 )) 56 + day=$(date -r "$f" +%d) 57 + if [ "$age" -gt 14 ] && [ "$day" != "01" ]; then 58 + rm -f "$f" 59 + elif [ "$age" -gt 90 ]; then 60 + rm -f "$f" 61 + fi 62 + done 63 + '' 64 + ]; 65 + }; 24 66 }; 25 67 26 68 sops.templates."immich.env".content = ''
+41
modules/kitchenowl.nix
··· 77 77 sops.secrets.kitchenowl-oidc-client-id = { }; 78 78 sops.secrets.kitchenowl-oidc-client-secret = { }; 79 79 80 + systemd.services.kitchenowl-db-backup = { 81 + description = "Backup KitchenOwl PostgreSQL database"; 82 + after = [ 83 + "podman-kitchenowl-db.service" 84 + "mnt-nas.mount" 85 + ]; 86 + requires = [ "mnt-nas.mount" ]; 87 + serviceConfig = { 88 + Type = "oneshot"; 89 + ExecStart = toString [ 90 + "/run/current-system/sw/bin/bash" 91 + "-c" 92 + '' 93 + dir=/mnt/nas/backup/kitchenowl/db 94 + mkdir -p "$dir" 95 + f="$dir/kitchenowl-$(date +%F).dump" 96 + ${config.virtualisation.podman.package}/bin/podman exec kitchenowl-db pg_dump -Fc -U kitchenowl kitchenowl > "$f.tmp" && mv "$f.tmp" "$f" 97 + # rotate: keep 14 daily, first of month for 90 days 98 + for old in "$dir"/kitchenowl-*.dump; do 99 + [ -f "$old" ] || continue 100 + age=$(( ($(date +%s) - $(date -r "$old" +%s)) / 86400 )) 101 + day=$(date -r "$old" +%d) 102 + if [ "$age" -gt 14 ] && [ "$day" != "01" ]; then 103 + rm -f "$old" 104 + elif [ "$age" -gt 90 ]; then 105 + rm -f "$old" 106 + fi 107 + done 108 + '' 109 + ]; 110 + }; 111 + }; 112 + 113 + systemd.timers.kitchenowl-db-backup = { 114 + wantedBy = [ "timers.target" ]; 115 + timerConfig = { 116 + OnCalendar = "daily"; 117 + Persistent = true; 118 + }; 119 + }; 120 + 80 121 networking.firewall.allowedTCPPorts = [ 9080 ]; 81 122 }