diff --git a/apps/backup/backup-daily.hcl b/apps/backup/backup-daily.hcl new file mode 100644 index 0000000..85a8b30 --- /dev/null +++ b/apps/backup/backup-daily.hcl @@ -0,0 +1,81 @@ +job "backup-daily" { + datacenters = [ "zuma-house", "mayel-house", "gribse-house" ] + type = "batch" + priority = "60" + + periodic { + crons = [ "@daily" ] + prohibit_overlap = true + } + + group "backup-consul" { + task "consul-kv-export" { + driver = "docker" + + lifecycle { + hook = "prestart" + sidecar = false + } + + config { + image = "hashicorp/consul:1.21.5" + network_mode = "host" + entrypoint = [ "/bin/sh", "-c" ] + args = [ "/bin/consul kv export > $NOMAD_ALLOC_DIR/consul.json" ] + } + + env { + CONSUL_HTTP_ADDR = "http://consul.service.filouterie.consul:8500" + CONSUL_HTTP_SSL = "false" + } + + resources { + cpu = 200 + memory = 200 + } + + restart { + attempts = 2 + interval = "30m" + delay = "15s" + mode = "fail" + } + } + + task "restic-backup" { + driver = "docker" + + config { + image = "restic/restic:0.18.1" + entrypoint = [ "/bin/sh", "-c" ] + network_mode = "host" + args = [ "restic backup $NOMAD_ALLOC_DIR/consul.json && restic forget --group-by paths --keep-within 1m1d --keep-within-weekly 3m --keep-within-monthly 1y && restic prune --max-unused 50% --max-repack-size 2G && restic check" ] + } + + + template { + data = <