81 lines
1.8 KiB
HCL
81 lines
1.8 KiB
HCL
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 = <<EOH
|
|
AWS_ACCESS_KEY_ID={{ key "secrets/backup-consul/key_id" }}
|
|
AWS_SECRET_ACCESS_KEY={{ key "secrets/backup-consul/secret_key" }}
|
|
RESTIC_REPOSITORY={{ key "secrets/backup-consul/restic_repository" }}
|
|
RESTIC_PASSWORD={{ key "secrets/backup-consul/restic_password" }}
|
|
EOH
|
|
|
|
destination = "secrets/env_vars"
|
|
env = true
|
|
}
|
|
|
|
resources {
|
|
cpu = 200
|
|
memory = 200
|
|
}
|
|
|
|
restart {
|
|
attempts = 2
|
|
interval = "30m"
|
|
delay = "15s"
|
|
mode = "fail"
|
|
}
|
|
}
|
|
}
|
|
}
|