homelab-nomad/services/backups/backup.nomad

165 lines
3.4 KiB
Plaintext
Raw Normal View History

job "backup%{ if batch_node != null }-oneoff-${batch_node}%{ endif }" {
datacenters = ["dc1"]
2022-11-18 16:58:38 +00:00
priority = 90
%{ if batch_node == null ~}
type = "system"
%{ else ~}
type = "batch"
parameterized {
meta_required = ["job_name"]
meta_optional = ["task", "snapshot"]
}
meta {
task = "backup"
snapshot = "latest"
}
%{ endif ~}
%{ if batch_node == null ~}
constraint {
attribute = "$${node.unique.name}"
operator = "set_contains_any"
# Only deploy to nodes running tasks to backup
value = "n1,n2"
}
%{ else ~}
constraint {
attribute = "$${node.unique.name}"
value = "${batch_node}"
}
%{ endif ~}
group "backup" {
network {
mode = "bridge"
port "metrics" {
host_network = "wesher"
to = 8080
}
}
volume "all-volumes" {
type = "host"
2022-07-28 05:04:22 +00:00
read_only = false
source = "all-volumes"
}
service {
name = "backup"
2023-03-24 18:24:36 +00:00
provider = "nomad"
port = "metrics"
2023-03-24 18:24:36 +00:00
tags = [
"prometheus.scrape"
]
}
task "backup" {
driver = "docker"
volume_mount {
volume = "all-volumes"
destination = "/data"
2022-07-28 05:04:22 +00:00
read_only = false
}
config {
image = "iamthefij/resticscheduler"
ports = ["metrics"]
args = [
%{ if batch_node != null ~}
"-once",
"-$${NOMAD_META_task}",
"$${NOMAD_META_job_name}",
%{ endif ~}
"$${NOMAD_TASK_DIR}/node-jobs.hcl",
]
}
env = {
2022-11-04 05:17:48 +00:00
"RCLONE_CHECKERS" = "2"
"RCLONE_TRANSFERS" = "2"
"RCLONE_FTP_CONCURRENCY" = "5"
2022-07-22 02:03:40 +00:00
}
2022-07-22 02:03:40 +00:00
template {
data = <<EOF
2023-03-24 18:24:36 +00:00
{{ range nomadService 1 (env "NOMAD_ALLOC_ID") "mysql-server" -}}
MYSQL_HOST={{ .Address }}
MYSQL_PORT={{ .Port }}
{{- end }}
# TODO: Move this to new mysql root pass path
{{ with nomadVar "nomad/jobs" }}
2022-11-03 03:30:04 +00:00
MYSQL_USER=root
2023-03-24 18:24:36 +00:00
MYSQL_PASSWORD={{ .mysql_root_password }}
2022-11-03 22:10:09 +00:00
{{ end -}}
{{ with nomadVar "nomad/jobs/backup" -}}
2023-03-24 18:24:36 +00:00
BACKUP_PASSPHRASE={{ .backup_passphrase }}
RCLONE_FTP_HOST={{ .nas_ftp_host }}
RCLONE_FTP_USER={{ .nas_ftp_user }}
RCLONE_FTP_PASS={{ .nas_ftp_pass.Value | toJSON }}
2022-07-28 05:04:22 +00:00
RCLONE_FTP_EXPLICIT_TLS=true
RCLONE_FTP_NO_CHECK_CERTIFICATE=true
{{ end -}}
2022-07-22 02:03:40 +00:00
EOF
destination = "secrets/db.env"
env = true
}
2022-07-25 23:29:06 +00:00
template {
2022-07-22 02:03:40 +00:00
# Build jobs based on node
data = <<EOF
2023-03-25 06:34:23 +00:00
# Current node is {{ env "node.unique.name" }} {{ env "node.unique.id" }}
{{ range nomadService "grafana" -}}
2023-03-25 06:34:23 +00:00
# grafana .Node {{ .Node }}
{{ if eq .Node (env "node.unique.id") -}}
2022-11-03 03:30:04 +00:00
${file("${module_path}/jobs/grafana.hcl")}
{{- end }}
{{- end }}
2022-11-03 03:30:04 +00:00
{{ range nomadService "photoprism" -}}
2023-03-25 06:34:23 +00:00
# photoprism .Node {{ .Node }}
{{ if eq .Node (env "node.unique.id") -}}
2022-11-15 17:19:55 +00:00
${file("${module_path}/jobs/photoprism.hcl")}
{{- end }}
{{- end }}
2022-11-15 17:19:55 +00:00
2023-03-25 06:34:23 +00:00
{{ range nomadService "lldap" -}}
# lldap .Node {{ .Node }}
{{ if eq .Node (env "node.unique.id") -}}
${file("${module_path}/jobs/lldap.hcl")}
{{- end }}
{{- end }}
2023-03-25 06:34:23 +00:00
{{ range nomadService "sonarr" -}}
# sonarr .Node {{ .Node }}
{{ if eq .Node (env "node.unique.id") -}}
${file("${module_path}/jobs/sonarr.hcl")}
{{- end }}
{{- end }}
2023-03-25 06:34:23 +00:00
{{ range nomadService "nzbget" -}}
# nzbget .Node {{ .Node }}
{{ if eq .Node (env "node.unique.id") -}}
${file("${module_path}/jobs/nzbget.hcl")}
{{- end }}
{{- end }}
EOF
destination = "local/node-jobs.hcl"
}
resources {
cpu = 50
memory = 256
}
}
}
}