Skip to content

Instantly share code, notes, and snippets.

@kidmose
Last active April 20, 2019 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidmose/5e9b323965c8ae46a198 to your computer and use it in GitHub Desktop.
Save kidmose/5e9b323965c8ae46a198 to your computer and use it in GitHub Desktop.
Scripts for automating libvirt guest save and restore
#!/bin/bash
# restore all hosts from saved stated (ram image) and start
virsh list --all | `#list of all guest` \
tail -n +3 | head -n -1 | sed 's/\ \+/\t/g' | `#strip head and tail, use tab for seperator`\
awk '{print($2)}' | \
while read GUEST; do
echo "Restoring $GUEST"
virsh restore "/var/lib/libvirt/images/$GUEST/state" --running
echo "Marking $GUEST for autostart"
virsh autostart $GUEST
done
#!/bin/bash
# save (store ram and shutdown) all hosts
virsh list | `#list of running guest` \
tail -n +3 | head -n -1 | sed 's/\ \+/\t/g' | `#strip head and tail, use tab for seperator`\
awk '{print($2)}' | \
while read GUEST; do
echo "Un-marking $GUEST for autostart:"
virsh autostart $GUEST --disable
echo "Saving $GUEST:"
virsh save $GUEST "/var/lib/libvirt/images/$GUEST/state"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment