Postgres backup cronjob.
This commit is contained in:
37
services/postgres-backup.hcl
Normal file
37
services/postgres-backup.hcl
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
job "postgres-backup" {
|
||||||
|
datacenters = ["alo"]
|
||||||
|
type = "batch"
|
||||||
|
|
||||||
|
periodic {
|
||||||
|
cron = "22 22 * * * *"
|
||||||
|
prohibit_overlap = true
|
||||||
|
}
|
||||||
|
|
||||||
|
group "db" {
|
||||||
|
task "backup" {
|
||||||
|
driver = "raw_exec"
|
||||||
|
|
||||||
|
config {
|
||||||
|
command = "/bin/sh"
|
||||||
|
args = [ "local/script.sh" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
template {
|
||||||
|
destination = "local/script.sh"
|
||||||
|
data = <<EOH
|
||||||
|
set -e
|
||||||
|
/run/current-system/sw/bin/nomad alloc exec -job -task=postgres postgres \
|
||||||
|
pg_dumpall -U postgres > /data/compute/appdata/db-backups/postgresql/backup.sql
|
||||||
|
EOH
|
||||||
|
}
|
||||||
|
|
||||||
|
template {
|
||||||
|
destination = "secrets/file.env"
|
||||||
|
env = true
|
||||||
|
data = <<EOH
|
||||||
|
{{- with nomadVar "secrets/postgresql" -}}PGPASSWORD="{{ .postgres_password }}"{{- end -}}
|
||||||
|
EOH
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user