Skip to content

Instantly share code, notes, and snippets.

@jfrancoa
Created August 24, 2017 07:49
Show Gist options
  • Save jfrancoa/ea4852e40515c5dced2a4094a2014a92 to your computer and use it in GitHub Desktop.
Save jfrancoa/ea4852e40515c5dced2a4094a2014a92 to your computer and use it in GitHub Desktop.
Bash functions for snapshots
#!/bin/bash
# If argument specified then it will be used as snapshot name.
# For example: $ restore fresh-install; will restore all snapshots named $domain-fresh-install
function restore() {
vms=( $(virsh list --all | grep running | awk '{print $2}') )
for i in "${vms[@]}";
do
virsh shutdown $i
sleep 120
virsh snapshot-revert --domain $i --snapshotname $i-$1 --running
done
}
function snapshot() {
vms=( $(virsh list --all | grep running | awk '{print $2}') )
for i in "${vms[@]}";
do
virsh snapshot-create-as --domain "$i" --name "$i"-$1 --description "$i"-$1 --atomic
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment