Add backup job for grafana

This commit is contained in:
IamTheFij 2022-11-02 20:30:04 -07:00
parent 2d63d7e74d
commit 695567b8aa
2 changed files with 48 additions and 6 deletions

View File

@ -122,12 +122,10 @@ job "backup%{ if batch_node != null }-oneoff-${batch_node}%{ endif }" {
}
template {
# Probably want to use database credentials that have access to dump all tables
data = <<EOF
{{ with secret "kv/data/nextcloud" -}}
MYSQL_DATABASE={{ .Data.data.db_name }}
MYSQL_USER={{ .Data.data.db_user }}
MYSQL_PASSWORD={{ .Data.data.db_pass }}
{{ with secret "kv/data/mysql" }}
MYSQL_USER=root
MYSQL_PASSWORD={{ .Data.data.root_password }}
{{ end -}}
{{ with secret "kv/data/backups" -}}
BACKUP_PASSPHRASE={{ .Data.data.backup_passphrase }}
@ -167,6 +165,13 @@ ${file("${module_path}/jobs/nextcloud.hcl")}
{{ end -}}
{{ end -}}
{{ range service "grafana" -}}
# Grafana .Node {{ .Node }}
{{ if eq .Node (env "node.unique.name") -}}
${file("${module_path}/jobs/grafana.hcl")}
{{ end -}}
{{ end -}}
{{ range service "lldap" -}}
# Lldap .Node {{ .Node }}
{{ if eq .Node (env "node.unique.name") -}}

View File

@ -0,0 +1,37 @@
job "Grafana" {
schedule = "0 * * * *"
config {
repo = "rclone::ftp,env_auth:/nomad/grafana"
passphrase = env("BACKUP_PASSPHRASE")
}
task "Create local grafana dir" {
pre_script {
on_backup = "mkdir -p /local/grafana"
}
}
mysql "Backup database" {
hostname = env("MYSQL_HOST")
port = env("MYSQL_PORT")
database = "grafana"
username = env("MYSQL_USER")
password = env("MYSQL_PASSWORD")
no_tablespaces = true
dump_to = "/local/grafana/dump.sql"
}
backup {
paths = ["/local/grafana"]
# Because path is absolute
restore_opts {
Target = "/"
}
}
forget {
KeepLast = 2
Prune = true
}
}