snapshot.sh.tmpl (698B)
1 #!/usr/bin/env sh 2 # 3 # Script to create snapshots from Nomad. 4 # Invoke with name of the service as first arg. 5 # 6 # Example: ./snapshot.sh nomad 7 8 set -o errexit 9 set -o nounset 10 set -o xtrace 11 12 mkdir -p /mnt/$1 13 cd /mnt/$1 14 15 case "$1" in 16 nomad) 17 nomad operator snapshot save 18 ;; 19 nomad-var) 20 for v in $(nomad var list -out terse); do 21 nomad var get -out json $v >> nomad-var-{{ timestamp "20060102" }}-{{ timestamp "unix" }}.dump 22 done 23 ;; 24 bao) 25 # use VAULT_TOKEN from nomad workload identity 26 bao operator raft snapshot save bao-raft-{{ timestamp "20060102" }}-{{ timestamp "unix" }}.snap 27 ;; 28 *) 29 echo "Usage: $0 nomad" 30 ;; 31 esac 32 33 find -mtime 2 -exec rm -rf {} \;