I am running a VMWare workstation on Ubuntu 10.10. I have a series of virtual machines that I clone every week.
I wrote a bash script that cycles through each of the virtual machines, gently pauses it, clones it and then tries to resume it.
The problem is that the virtual machine does not resume, so I have to manually resume them. I am trying to figure out how I can change the script that I wrote in order to resume virtual machines. I included a script and a sample of the generated log file displaying an error message.
#!/bin/bash
BACKUPDEST="/nas"
HOST=`hostname`
DATEFILE=`/bin/date +%G%m%d`
VMLIST=`vmrun list | grep '/' | cut -d'/' -f3 | cut -d'.' -f1`
COUNTER=1
VMARRAY=( `vmrun list | grep '/'` )
function startScript {
echo
echo "----------------------------------------------------"
echo "START - ${VM}"
echo "Host: ${HOST}"
echo "Date: `date`"
echo
}
function suspendVM {
echo "Attempting to softly suspend "${VM}" . . ."
vmrun suspend ${VMARRAY[${COUNTER}]} soft
echo "${VM} Suspended on `date`"
echo
}
function doBackup {
if [ ! -d ${BACKUPDEST}/${VM} ]; then
echo "${BACKUPDEST}/${VM} does not exist, creating . . ."
mkdir "${BACKUPDEST}/${VM}"
echo
fi
echo "Backup of "${VM}" began: `date`"
echo "Backup to ${BACKUPDEST}/${VM}/BACKUP/${DATEFILE} . . ."
mkdir ${BACKUPDEST}/${VM}/BACKUP/${DATEFILE}
vmrun clone ${VMARRAY[${COUNTER}]} ${BACKUPDEST}/${VM}/BACKUP/${DATEFILE}/${VM}.vmx full
echo "Backup of "${VM}" ended: `date`"
echo
}
function doStart {
echo "Attempting to resume "${VM}" . . ."
vmrun start ${VMARRAY[${COUNTER}]}
echo "${VM} Resumed on `date`"
echo
}
function finishScript {
echo "FINISH - ${VM}"
echo "Host: ${HOST}"
echo "Date: `date`"
echo "----------------------------------------------------"
echo
}
for VM in ${VMLIST}
do
sleep 1
startScript
suspendVM
sleep 3
doBackup
sleep 3
doStart
sleep 3
finishScript
COUNTER=${COUNTER}+1
done | tee "${BACKUPDEST}/logs/VMClone_${DATEFILE}.log"
exit
The following is an example of a generated log file for each virtual machine.
START - vmname
Host: servername
Date: Sat Feb 19 12:30:29 CST 2011
Attempting to softly suspend vmname . . .
vmname Suspended on Sat Feb 19 12:30:44 CST 2011
Backup of vmname began: Sat Feb 19 12:30:47 CST 2011
Backup to /nas/vmname/BACKUP/20110219 . . .
Backup of vmname ended: Sat Feb 19 12:43:16 CST 2011
Attempting to resume vmname . . .
Error: Cannot launch the UI because no display server is present in the current environment
vmname Resumed on Sat Feb 19 12:43:20 CST 2011
FINISH - vmname
Host: servername
Date: Sat Feb 19 12:43:23 CST 2011
: ,