Install a script to snapshot the k8s bhyve virtual machines and persistent volume space.

This commit is contained in:
Tom Alexander 2023-07-18 15:31:52 -04:00
parent bdff61d8e9
commit 808b087a82
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 56 additions and 0 deletions

View 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 "$@"

View File

@ -39,3 +39,14 @@
group: wheel
loop:
- /k8spersistent
- name: Install scripts
copy:
src: "files/{{ item.src }}"
dest: "{{ item.dest }}"
mode: 0755
owner: root
group: wheel
loop:
- src: "k8s_snapshot.bash"
dest: /usr/local/bin/k8s_snapshot