From 73d193d0a5d46244e94df504e9a56f5131934ed1 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Wed, 27 Jul 2022 17:02:29 -0700 Subject: [PATCH] Add lldap backup and templatize backup job Now oneoff and system jobs are all using the same template --- backups/backup.nomad | 73 ++++++++++++------ backups/backups.tf | 31 +++----- backups/jobs/lldap.hcl | 38 +++++++++ backups/oneoff.nomad | 171 ----------------------------------------- 4 files changed, 95 insertions(+), 218 deletions(-) create mode 100644 backups/jobs/lldap.hcl delete mode 100644 backups/oneoff.nomad diff --git a/backups/backup.nomad b/backups/backup.nomad index df79429..54eb7a8 100644 --- a/backups/backup.nomad +++ b/backups/backup.nomad @@ -1,24 +1,36 @@ -variable "nextcloud_backup" { - type = string - description = "HCL config for Restic Scheduler jobs" -} - -variable "consul_backup" { - type = string - description = "HCL config for Restic Scheduler jobs" -} - -job "backup" { +job "backup%{ if batch_node != null }-oneoff-${batch_node}%{ endif }" { datacenters = ["dc1"] + %{ if batch_node == null ~} type = "system" + %{ else ~} + type = "batch" + + parameterized { + meta_required = ["job_name"] + meta_optional = ["task", "snapshot"] - constraint { - attribute = "${node.unique.name}" - # Only node with a backup job so far - # Remove when backing up all nodes - value = "n2" } + 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 { @@ -64,7 +76,7 @@ job "backup" { } meta { - metrics_addr = "${NOMAD_ADDR_metrics}" + metrics_addr = "$${NOMAD_ADDR_metrics}" } } @@ -81,6 +93,11 @@ job "backup" { image = "iamthefij/resticscheduler" ports = ["metrics"] args = [ + %{ if batch_node != null ~} + "-once", + "-$${NOMAD_META_task}", + "$${NOMAD_META_job_name}", + %{ endif ~} "/jobs/node-jobs.hcl", ] @@ -99,8 +116,8 @@ job "backup" { } env = { - "MYSQL_HOST" = "${NOMAD_UPSTREAM_IP_mysql_server}" - "MYSQL_PORT" = "${NOMAD_UPSTREAM_PORT_mysql_server}" + "MYSQL_HOST" = "$${NOMAD_UPSTREAM_IP_mysql_server}" + "MYSQL_PORT" = "$${NOMAD_UPSTREAM_PORT_mysql_server}" } template { @@ -132,16 +149,22 @@ CONSUL_HTTP_ADDR={{ env "attr.unique.network.ip-address" }}:8500 # Build jobs based on node data = <