nomad-snapshots.nomad (1507B)
1 job "snapshot" { 2 datacenters = ["dc1"] 3 type = "batch" 4 5 vault { 6 role = "snapshot" 7 # export VAULT_TOKEN for use in snapshot.sh script 8 env = true 9 } 10 11 parameterized { 12 payload = "forbidden" 13 meta_required = ["service"] 14 } 15 16 periodic { 17 # At minute 12 past every hour 18 crons = [ 19 "12 */1 * * *" 20 ] 21 # prevents "volume max claim reached" on CSI volume 22 prohibit_overlap = true 23 } 24 25 group "snapshot" { 26 count = 1 27 28 volume "nomad-snapshots" { 29 type = "csi" 30 source = "nomad-snapshots" 31 access_mode = "multi-node-multi-writer" 32 attachment_mode = "file-system" 33 } 34 35 network { 36 mode = "host" 37 } 38 39 task "snapshot-save" { 40 driver = "exec" 41 42 env { 43 NOMAD_ADDR = "https://127.0.0.1:4646" 44 # only save variables from default namespace 45 NOMAD_NAMESPACE = "default" 46 NOMAD_SKIP_VERIFY = 1 47 VAULT_SKIP_VERIFY = 1 48 } 49 50 template { 51 destination = "${NOMAD_TASK_DIR}/snapshot.sh" 52 data = file("./templates/snapshot.sh.tmpl") 53 perms = 755 54 } 55 56 config { 57 command = "${NOMAD_TASK_DIR}/snapshot.sh" 58 # Note: This meta variable (the parametrized service name) 59 # could also be directly accessed inside the template 60 args = [NOMAD_META_SERVICE] 61 } 62 63 volume_mount { 64 volume = "nomad-snapshots" 65 destination = "/mnt" 66 } 67 68 resources { 69 memory = 128 70 cpu = 200 71 } 72 } 73 } 74 }