From a7e276c6371d4c68ee7733e8e2f3ae186d60fe15 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 21 Jul 2022 20:24:50 -0700 Subject: [PATCH] WIP: Write a consul backup job --- nomad/backups/jobs/consul.hcl | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 nomad/backups/jobs/consul.hcl diff --git a/nomad/backups/jobs/consul.hcl b/nomad/backups/jobs/consul.hcl new file mode 100644 index 0000000..3478848 --- /dev/null +++ b/nomad/backups/jobs/consul.hcl @@ -0,0 +1,45 @@ +job "Consul" { + schedule = "0 0 * * *" + + config { + # TODO: Backup to a meaningful location, this is just for testing + repo = "/local/repo" + # Read from secret file + passphrase = env("BACKUP_PASSPHRASE") + } + + # Remove when using a proper backup destination + task "Create dir for repo" { + pre_script { + on_backup = "echo 'Backing up something'" + } + pre_script { + on_backup = "mkdir -p /local/repo" + } + } + + task "Use consul snapshots" { + pre_script { + on_backup = "mkdir -p /local/consul" + } + pre_script { + on_backup = "consul snapshot save /local/consul/backup.snap" + } + post_script { + on_restore = "consul snapshot restore /local/consul/backup.snap" + } + } + + backup { + paths = ["/local/consul"] + # Because path is absolute + restore_opts { + Target = "/" + } + } + + forget { + KeepLast = 2 + Prune = true + } +}