Install a script to snapshot the k8s bhyve virtual machines and persistent volume space.
This commit is contained in:
45
ansible/roles/mrmanager/files/k8s_snapshot.bash
Normal file
45
ansible/roles/mrmanager/files/k8s_snapshot.bash
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Kill the virtual machines, take a snapshot, and start the virtual machines up again.
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
############## Setup #########################
|
||||
|
||||
function die {
|
||||
local status_code="$1"
|
||||
shift
|
||||
(>&2 echo "${@}")
|
||||
exit "$status_code"
|
||||
}
|
||||
|
||||
function log {
|
||||
(>&2 echo "${@}")
|
||||
}
|
||||
|
||||
############## Program #########################
|
||||
|
||||
function main {
|
||||
snapshot_name="$1"
|
||||
kill_all_bhyve
|
||||
log "Taking snapshot $1"
|
||||
for worker in worker0 worker1 worker2 controller0 controller1 controller2; do
|
||||
doas zfs snapshot -r zdata/vm/${worker}/disk0@${snapshot_name}
|
||||
done
|
||||
doas zfs snapshot zdata/k8spersistent@${snapshot_name}
|
||||
launch_all_bhyve
|
||||
log "Done."
|
||||
}
|
||||
|
||||
function kill_all_bhyve {
|
||||
log "Killing all virtual machines."
|
||||
doas killall bhyve; while true; do tmux ls || break; sleep 2; done;
|
||||
}
|
||||
|
||||
function launch_all_bhyve {
|
||||
log "Launching all virtual machines."
|
||||
for vm in poudriere controller0 controller1 controller2 worker0 worker1 worker2; do tmux new -d -s $vm doas bhyve_netgraph_bridge start $vm zdata/vm/$vm /vm/$vm; sleep 5; done
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user