46 lines
1.1 KiB
HCL
46 lines
1.1 KiB
HCL
job "postgres-backup" {
|
|
datacenters = ["alo"]
|
|
type = "batch"
|
|
|
|
periodic {
|
|
crons = ["22 22 * * * *"]
|
|
prohibit_overlap = true
|
|
}
|
|
|
|
group "db" {
|
|
# Run on primary storage node (zippy) where postgres runs
|
|
constraint {
|
|
attribute = "${meta.storage_role}"
|
|
value = "primary"
|
|
}
|
|
|
|
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/services/db-backups/postgresql/backup.sql && \
|
|
echo "last_success $(date +%s)" | \
|
|
/run/current-system/sw/bin/curl --data-binary @- http://pushgateway.service.consul:9091/metrics/job/postgres_backup
|
|
EOH
|
|
}
|
|
|
|
template {
|
|
destination = "secrets/file.env"
|
|
env = true
|
|
data = <<EOH
|
|
{{- with nomadVar "secrets/postgresql" -}}PGPASSWORD="{{ .postgres_password }}"{{- end -}}
|
|
EOH
|
|
}
|
|
}
|
|
}
|
|
}
|