mysql backup cron

This commit is contained in:
2024-01-15 10:14:03 +00:00
parent 30c88ea579
commit 7dbd5652ed
4 changed files with 39 additions and 52 deletions

37
services/mysql-backup.hcl Normal file
View File

@@ -0,0 +1,37 @@
job "mysql-backup" {
datacenters = ["alo"]
type = "batch"
periodic {
cron = "23 23 * * * *"
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=mysqld mysql \
mysqldump -u root --password="$MYSQL_ROOT_PASS" --all-databases > /data/compute/appdata/db-backups/mysql/backup.sql
EOH
}
template {
destination = "secrets/file.env"
env = true
data = <<EOH
{{- with nomadVar "secrets/mysql" -}}MYSQL_ROOT_PASS="{{ .root_password }}"{{- end -}}
EOH
}
}
}
}