From 08a2e458b2c057ae5ead6da22263c516367821b0 Mon Sep 17 00:00:00 2001 From: Adrian Cowan Date: Sat, 17 May 2025 00:38:02 +1000 Subject: [PATCH] Initial work on db backups --- 2-nomad-config/pgbackup.nomad.hcl | 77 +++++++++++++++++++++++++++++++ 2-nomad-config/services.tf | 29 ++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 2-nomad-config/pgbackup.nomad.hcl diff --git a/2-nomad-config/pgbackup.nomad.hcl b/2-nomad-config/pgbackup.nomad.hcl new file mode 100644 index 0000000..3ac6b1b --- /dev/null +++ b/2-nomad-config/pgbackup.nomad.hcl @@ -0,0 +1,77 @@ +job "pgbackup" { + type = "batch" + periodic { + # Note: To avoid issues with daylight savings, avoid scheduling jobs at 2am +/- 1 hour + cron = "* 04 * * *" # Every day at 4am + time_zone = "Australia/Melbourne" + prohibit_overlap = true + } + + group "pgbackup" { + service { + connect { + sidecar_service { + proxy { + upstreams { + destination_name = "postgres" + local_bind_port = 5432 + } + } + } + } + } + + task "pgbackup" { + driver = "docker" + + config { + image = "postgres:latest" + command = "/bin/bash" + args = ["-c", "pg_dumpall -h localhost -U postgres > /backup/all_databases.sql"] + volumes = [ "secrets/postgres_password:/run/secrets/postgres_password" ] + } + + user = "1000" + + volume_mount { + volume = "unraid_database_dump" + destination = "/backup" + read_only = false + } + + env { + PGPASSFILE = "/run/secrets/postgres_password" + } + + template { + data = <