Skip to content

Instantly share code, notes, and snippets.

@cvrolf
Last active November 1, 2017 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvrolf/39de5f38085fa0756aea2b0ddde60f55 to your computer and use it in GitHub Desktop.
Save cvrolf/39de5f38085fa0756aea2b0ddde60f55 to your computer and use it in GitHub Desktop.
#@RunAs: Open a Terminal with user root @ Master Machine*****
###
### Bash Shell behavior
# @doc -e Exit immediately if a command returns a non-zero status.
# @doc -u Treat unset variables and parameters other than the special parameters ‘@’ or ‘*’ as an error when performing parameter expansion.
# @doc -x Print a trace of commands after they are expanded and before they are executed.
set -u
set -x
###
### Global vars
MYDOMAIN="myvmtest"
MYIPADDRESS=192.168.122.102
MYMACADDRESS=52:54:00:ff:ff:66
###
### Check you are on the correct host: Host Machine (not the VM)
hostname
whoami
if [ "`hostname`" == "${MYDOMAIN}" ]; then
echo "ABORT. This is not a session on the Host Machine"
sleep 10
exit 1
else
echo "OK. This is a session on the Host Machine"
fi
###
### Main
virsh shutdown --domain ${MYDOMAIN}
virsh shutdown --domain ${MYDOMAIN}
sleep 10
virsh list --all
SNAPSHOTNAME="${MYDOMAIN}-`date +%Y%m%d-%H%M`"
XMLFILE="makesnapshot.xml"
# TODO Add a relevant description!
echo "<domainsnapshot><name>${SNAPSHOTNAME}</name><description>$(date '+%Y-%m-%d %H:%M:%S') BACKUP AFTER CLEAN INSTALL USING THE BLOGPOST</description></domainsnapshot>" > ${XMLFILE}
cat ${XMLFILE}
virsh snapshot-create ${MYDOMAIN} ${XMLFILE} --atomic
virsh snapshot-list ${MYDOMAIN}
virsh snapshot-info ${MYDOMAIN} ${SNAPSHOTNAME}
virsh snapshot-dumpxml ${MYDOMAIN} ${SNAPSHOTNAME} --security-info | grep "<description>"
ls -l /var/lib/libvirt/qemu/snapshot/${MYDOMAIN}
virsh start --domain ${MYDOMAIN}
sleep 10
virsh list --all
if ! ping -c2 ${MYIPADDRESS}; then
echo "ERROR. Cannot ping IPV4 address ${MYIPADDRESS}"
else
echo "OK. Ping IPV4 address ${MYIPADDRESS}"
fi
if ! ping -c2 ${MYDOMAIN}; then
echo "ERROR. Cannot ping DNS Name ${MYDOMAIN}"
else
echo "OK. Ping DNS Name ${MYDOMAIN}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment