feat: 10min incremental snapshots/backups
This commit is contained in:
parent
3a66e5958a
commit
e6b4cc8619
9 changed files with 139 additions and 51 deletions
47
services/backup-postgres.nix
Normal file
47
services/backup-postgres.nix
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
serviceName = "backup-postgres";
|
||||
in
|
||||
{
|
||||
environment.systemPackages = [
|
||||
pkgs.restic
|
||||
];
|
||||
|
||||
systemd.timers."${serviceName}" = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnBootSec = "10m";
|
||||
OnUnitActiveSec = "10m";
|
||||
Unit = "${serviceName}.service";
|
||||
};
|
||||
};
|
||||
systemd.services."${serviceName}"= {
|
||||
script = ''
|
||||
set -euo pipefail
|
||||
|
||||
cd /var/lib/hexname/postgres
|
||||
${config.services.postgresql.package}/bin/pg_dumpall \
|
||||
--exclude-database=roundcube \
|
||||
--exclude-database=template0 \
|
||||
--exclude-database=template1 \
|
||||
--exclude-database=postgres \
|
||||
--clean \
|
||||
--file ./postgres.out
|
||||
'';
|
||||
wants = [ "restic-backups-postgres.service" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "postgres";
|
||||
Group = "postgres";
|
||||
RemainAfterExit = true; # Don't start the service on every rebuild
|
||||
};
|
||||
};
|
||||
|
||||
# Overwrite the restic backup service so that it's triggered after `pg_dump`
|
||||
systemd.services.restic-backups-postgres = {
|
||||
after = [ "backup-postgres.service" ];
|
||||
# requires = [ "backup-postgres.service" ];
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue