Below is a backup script that I have created for backing up vmware instances on a Linux machine. Note that it requires the quest OS to have vmware tools installed in order to suspend it.
==============Script Start =======================
#Expects the following variables to be set
#VMWARE_DIR
#VMWARE_VMX
#TAR_NAME
#REMOTE_CONNECTION
#Checks the result of our called program
function checkResult {
if \[ $? -ne 0 ]
then
echo "$1";
exit 1;
fi
}
if \[ $# -ne 3 ]
then
echo "Usage is $0 vmware-dir vmware-vmx-file tarname ";
exit 1;
fi
VMWARE_DIR="$1";
VMWARE_VMX="$VMWARE_DIR/$2";
TAR_NAME="$3";
REMOTE_CON="$4";
echo "VMWARE_DIR = $VMWARE_DIR";
echo "VMWARE_VMX = $VMWARE_VMX";
echo "TAR_NAME = $TAR_NAME";
echo "REMOTE_CON = $REMOTE_CON";
echo "Starting backup at `date`";
STATE=`vmware-cmd "$VMWARE_VMX" getstate|grep on|wc -l`
\# grep for state = on, if its there then suspend
if \[ $STATE -eq 1 ]
then
echo "Suspending vmware image '$VMWARE_VMX'";
vmware-cmd "$VMWARE_VMX" suspend;
checkResult "Unable to suspend the vmware image $VMWARE_VMX";
fi
echo "Taring VMWare directory $VMWARE_DIR";
tar cvjf "$TAR_NAME" "$VMWARE_DIR";
checkResult "Unable to create the file $TAR_NAME";
echo "Tar completed"
STATE=`vmware-cmd "$VMWARE_VMX" getstate|grep suspended|wc -l`
if \[ $STATE -eq 1 ]
then
echo "starting vmware image '$VMWARE_VMX'";
vmware-cmd "$VMWARE_VMX" start;
checkResult "Unable to resume the vmware image $VMWARE_VMX";
fi
echo "Finished backup at `date`";
echo "Output file is '$TAR_NAME'";
================= End Script ==========================
Message was edited by:
RDPetruska
Added code tags to preserve whitespace.