VM Backup: Difference between revisions

From KlavoWiki
Jump to navigationJump to search
New page: The following script will make a compressed tar.gz file for each existing virtual computer. The compressed file is saved in /root/vmbackup/%date% <pre> #!/bin/bash # Variables used by sc...
(No difference)

Revision as of 00:18, 1 August 2008

The following script will make a compressed tar.gz file for each existing virtual computer. The compressed file is saved in /root/vmbackup/%date%

#!/bin/bash
# Variables used by script
strCurDate=$(date +%Y%m%d)
strVMWareDir="/var/lib/vmware/Virtual Machines"
strTempDir="/root/vmbackup/$strCurDate/"
strLogFile="/root/vmbackup/$strCurDate/vmbackup.log"

mkdir -p $strTempDir

echo "!!! Starting VMWare backup of $strVMWareDir/" >> $strLogFile
cd "$strVMWareDir"

find "$strVMWareDir"/ -iname *.vmx | while read FILE
do
   echo "*** Suspend: $FILE" >> $strLogFile
   vmware-cmd "$FILE" suspend >> $strLogFile

   echo "*** ZIP: $FILE" >> $strLogFile
   strZipName=`echo "$FILE" | awk -F/ '{print $6}'`.tar.gz
   tar -cvzf $strTempDir/$strZipName `echo "$FILE" | awk -F/ '{print $6}'`/* >> $strLogFile

   echo "*** Start: $FILE" >> $strLogFile
   vmware-cmd "$FILE" start >> $strLogFile
done

echo "!!! Backup Complete"