Welcome to my website


Archive
Danish VMware User Group domain name is now online
28 September 2006 21:15
www.vmug.dk aka Danish VMware User Group is now online and is a link to the VMware user forum until a real website comes online..

Very cool :-)

Tooms @ 28 September 2006 21:15 | Comment | Direct link
UPS shutdown script for VMware ESX 3.0
11 September 2006 21:24
Just setup APC UPS software on the ESX 3.0 and was needing a good shutdown script but do not find any that i like, so i have now made my own..

what i need was a script there:

  1. Try soft shutdown of all VM's there is power on and only them.
  2. If soft shutdown fails then hard shutdown
  3. Wait for the VM's to shutdown and timeout after 300 sec.
  4. If a VM is not off within the 300 sec. then do hard power off
  5. Shutdown the ESX to halt mode

The script below do this, just copy it into a file on the ESX.

#####################################################################
#!/bin/sh
#
#  UPS shutdown script for VMware ESX 3.0
#
# 20060911 First version by tooms@tooms.dk
#


#####################################################################
# set the paths that the vmware tools need
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"


#####################################################################
# try do a nice shutdown of VM there is power
count_vm_on=0
for vm in `vmware-cmd -l` ; do
  #echo "VM: " $vm
  for VMstate in `vmware-cmd "$vm" getstate` ; do
  #echo $VMstate

  # If the VM is power ON
  if [ $VMstate = "on" ] ; then
     echo " "
     echo "VM: " $vm
     echo "State: is on and will now tell it to shut down"
     echo "Shutting down: " $vm
     vmware-cmd "$vm" stop trysoft
     vmwarecmd_exitcode=$(expr $?)
     if [ $vmwarecmd_exitcode -ne 0 ] ; then
         echo "exitcode: $vmwarecmd_exitcode so will now turn it off hard"
         vmware-cmd "$vm" stop hard
     fi
     count_vm_on=$count_vm_on+1
    sleep 2
  # if the VM is power OFF
  elif [ $VMstate = "off" ] ; then
     echo " "
     echo "VM: " $vm
     echo "State: is off, so i skip it"
  # if the VM is power suspended
  elif [ $VMstate = "suspended" ] ; then
     echo " "
     echo "VM: " $vm
     echo "State: is suspended, so i skip it"
  # if state is getstate or =
  else
     printf ""
    #echo "unknown state: " $VMstate
  fi

  done
done


########################################################################
# wait for up to 5 min for the VM to shutd
#
if [ $count_vm_on = 0 ] ; then
  echo " "
  echo "All VM is off or suspended"
else
  echo " "
  vm_time_out=300
  count_vm_on=0
  echo "Waiting for VMware virtual machines."
  for (( second=0; second<$vm_time_out; second=second+5 )); do
     sleep 5
     printf "."
     count_vm_on=0
     for vm in `vmware-cmd -l` ; do
        for VMstate in `vmware-cmd "$vm" getstate` ; do
        if [ $VMstate = "on" ] ; then
           count_vm_on=$(expr $count_vm_on + 1)
        fi
     done
  done
  if [ $count_vm_on = 0 ] ; then
     #echo "exit for"
     break
  fi
  done
  #echo $VMstate
fi
#echo $count_vm_on


#####################################################################
# checking if all the VM are off and if not then turn them off
for vm in `vmware-cmd -l` ; do
  #echo "VM: " $vm
  for VMstate in `vmware-cmd "$vm" getstate` ; do
    # If the VM is power ON
    if [ $VMstate = "on" ] ; then
      echo " "
      echo "Found this VM: " $vm
      echo "it is stille on but now i will turn it off"
      vmware-cmd "$vm" stop hard
      sleep 2
    fi
  done
done


#####################################################################
# Will now shutdown the ESX server as all VM are now off
echo " "
echo "now all VM is down, so will shutdown ESX host now"
echo " "
shutdown -h now
 
Tooms @ 11 September 2006 21:24 | Comment | Direct link
How to install Backup Exec Linux agent on the VMware ESX 3.0
9 September 2006 22:48
Just made a article about how to install the BE linux agent on a ESX 3.0 server and how to use it.

It can be found here
http://www.tooms.dk/articles_tutorials/backupexec_agent_on_esx3/
Tooms @ 9 September 2006 22:48 | Comment | Direct link
VMware ESX 3.0 VM Backup script made by Tooms
6 September 2006 18:34
I was looking around the internet for a backup script to backup the VM guests on a standalone ESX 3.0 and was not finding any so I start to make my own.

Things I need the script to-do was.

  • HOT Backup of all VM guest on the server
  • Backup of VM guests in any power state
  • Backup to a local folder on the server where the remote backup server will pick them from and put it to tapes
  • Auto cleanup of old backup log and VM files (older then 1 day)
  • Execute one script if there was a error and another if there was no error
  • No SAN, work on a standalone ESX server with local storage

and yes I know esxRanger 2.0 for ESX 3.0 can do all this, but that product was not finish and public when I start to make this script, maybe I will change to esxRanger but that will time tell or maybe I will use them both


Please be nice as this is my first Linux bash script and I am just a windows admin ;-) so there is for sure a number of error and smarter ways to do thing, but it works for me.. and if you give me feedback I will fix the script.



Here is the script and how to use it

1. login
login as root on the ESX 3.0 console


2. edit backuptools.conf
First edit the /etc/vmware/backuptools.conf file by running the command "nano /etc/vmware/backuptools.conf"
This is need in order for the vmware backup tools to work...
Out comment the red lines and put in the blue lines


#
# URL for the VC SDK instance to connect to. The format is
# [:port]
#
# VCHOST=myvirtualcenter.company.com
VCHOST=localhost

#
# Username to use for VC SDK authentication
#
# USERNAME=backup
USERNAME=root

#
# Password to user for VC SDK authentication
# WARNING: It is recommended that you don't specify the
# password in the configuration file.
#
# PASSWORD=XXX
PASSWORD=YourPassword

note the best thing will be to make a account for backup and not use the root account.

3. make a folder for the backup script
make a folder with the command "mkdir /etc/esxbackup"


4. backup script
make the script by using the command "nano
/etc/esxbackup/backup.bash" and copy the script below into it.
change the $TOfolder to be where you like the backup to be put.

###########################################################################
#!/bin/bash
#
# ESX 3.0 Backup script build by Tooms@tooms.dk
#
# 20060905 Minor fixs by tooms
# 20060830 First version by tooms
#
# Change the $TOfolder to be the folder where the backup files will be placed in
#
#


###########################################################################
# Path the vmware apps need.
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"


###########################################################################
# the base Path where the backup will be placed
# Change this path to match your setup
TOfolder=/vmfs/volumes/storage1/backup


############################################################################
# make the sub folder name ready from date/time
DTfolder=$(date '+%Y%m%d-%H%M')


############################################################################
# making the base folders ready if not exist
if test ! -x "$TOfolder" ; then
  mkdir -p $TOfolder
fi


############################################################################
# make a log file ready
rm -f $TOfolder/backup.log
Backuplog=$TOfolder/backup.log
echo " " >>$Backuplog
echo "The Date/time is $(date '+%Y%m%d-%H%M%S')" >>$Backuplog
echo " " >>$Backuplog


############################################################################
# making the sub-folders ready if there not exist
if test ! -x "$TOfolder/$DTfolder" ; then
  echo "Make folder: $TOfolder/$DTfolder" >>$Backuplog
  mkdir -p $TOfolder/$DTfolder
fi
if test ! -x "$TOfolder/$DTfolder/vm" ; then
  echo "Make folder: $TOfolder/$DTfolder/vm" >>$Backuplog
  mkdir -p $TOfolder/$DTfolder/vm
fi
if test ! -x "$TOfolder/$DTfolder/log" ; then
  echo "Make folder: $TOfolder/$DTfolder/log" >>$Backuplog
  mkdir -p $TOfolder/$DTfolder/log
fi


############################################################################
# move backup log to the new subfolder
mv $TOfolder/backup.log $TOfolder/$DTfolder/log/
Backuplog=$TOfolder/$DTfolder/log/backup.log
echo " " >>$Backuplog
echo "Move backup log to $Backuplog" >>$Backuplog


############################################################################
# build content log of $TOfolder before backup and cleanup
echo " " >>$Backuplog
echo "Build content_before.log of $TOfolder before backup and cleanup" >>$Backuplog
ls -R -la $TOfolder >>$TOfolder/$DTfolder/log/content_before.log


############################################################################
# Delete content from the $TOfolder there is older then 1 day
echo " " >>$Backuplog
echo "Delete content from the $TOfolder there is older then 1 day" >>$Backuplog
find $TOfolder/* -type d -maxdepth 0 -mtime +1 -exec rm -d -r -f -v {} >>$Backuplog \;


############################################################################
# Delete old vcbSnapAll logfiles from /var/log/vmware/ there is older then 1 day
echo " " >>$Backuplog
echo "Delete old vcbSnapAll logfiles from /var/log/vmware/ there is older then 5 min." >>$Backuplog
find /var/log/vmware/vcbSnapAll-* -type d -maxdepth 0 -mtime +1 -exec rm -d -r -f -v {} >>$Backuplog \;


############################################################################
# make the VM export/backup
echo " " >>$Backuplog
echo "Laver export af alle VM" >>$Backuplog
vcbSnapAll -a any -r $TOfolder/$DTfolder/vm/ -L 6 >>$Backuplog


############################################################################
# Getting the exitcode from vcbSnapAll
vcbSnapAll_exitcode=$(expr $?)
echo " " >>$Backuplog
echo "The exitcode is $vcbSnapAll_exitcode" >>$Backuplog


############################################################################
# copy the vcbSnapAll logfiles to the logfolder
echo " " >>$Backuplog
echo "copy the vcbSnapAll logfiles to $TOfolder/$DTfolder/log/" >>$Backuplog
cp -r -v /var/log/vmware/vcbSnapAll-* $TOfolder/$DTfolder/log/ >>$Backuplog


############################################################################
# build content log of $TOfolder after backup and cleanup
echo " " >>$Backuplog
echo "Build content_after.log of $TOfolder after backup and cleanup" >>$Backuplog
ls -R -la $TOfolder >>$TOfolder/$DTfolder/log/content_after.log


############################################################################
# write end time in logfile
echo " " >>$Backuplog
echo "The Date/time is $(date '+%Y%m%d-%H%M%S')" >>$Backuplog


############################################################################
# Checking for errors
echo " " >>$Backuplog
if [ $vcbSnapAll_exitcode = 0 ]; then
  echo "Error: none" >>$Backuplog
  echo " " >>$Backuplog
  #run script if all okey !
else
  echo "Error: got exitcode $vcbSnapAll_exitcode" >>$Backuplog
  echo " " >>$Backuplog
  #run script if there is a error !
fi



5. Make it a script
run this command "chmod 777 /etc/esxbackup/backup.bash" to make it a script there can be run from the commandline


6. When to run the backup
edit the crontap fil with the command "nano /etc/crontap" to run the script at 21:00 every evening
Add the line mark with blue

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
00 21 * * * root /etc/esxbackup/backup.bash
 


7. Try the script
Try the script by running the command "/etc/esxbackup/backup.bash"


8. Look at the backup log
Look at the backup log with the command "nano /vmfs/volumes/storage1/backup/20060905-1800/log/backup.log"
note that the path will offcource not be the same when you use it...


9. Backup to tape
Now setup your remote backup server to backup any thing in the /vmfs/volumes/storage1/backup folder, I use Backup Exec 10D on a windows server with the backup exec 9.1 linux agent installed in the ESX 3.0 server COS.
That works very well with backup speed at around 1500mb/min over a 1gbit network with a LTO3 24 tape autoloader from Dell on the windows server.



And yes before you ask how to restore a VM from the backup folder......
First turn off the VM there need to be restore and do like this

[root@ESX3 root]# vcbRestore -s /vmfs/volumes/storage1/backup/20060905-1800/vm/vm01/ -b overwrite
[2006-09-06 18:30:00.140 'App' 3076448384 info] Current working directory: /root
[2006-09-06 18:30:00.157 'BaseLibs' 11344816 warning] [Vmdb_Unset] Unsetting unknown path: /vmomi/

Converting "/vmfs/volumes/storage2//VM_vm01/vm01.vmdk" (VMFS (flat)):
0%=====================50%=====================100%
**************************************************

[root@ESX3 root]#
 

Now turn on the VM that is just restore and verify it is working.


hope this help you on the way and works on your box, let me know in the forum if you have any smart things there need to be add to the backup script and I will then update it from time to time...


not bad from a windows admin with only a very little linux skills ;-)
 

Tooms @ 6 September 2006 18:34 | Comment | Direct link


Arkive list
2015 - November
2014 - August
2014 - April
2014 - March
2014 - February
2014 - January
2013 - December
2013 - November
2013 - October
2013 - August
2013 - June
2012 - December
2012 - September
2012 - August
2012 - May
2012 - April
2011 - November
2011 - October
2011 - September
2010 - May
2010 - March
2010 - January
2009 - December
2009 - November
2009 - October
2009 - August
2009 - July
2009 - May
2009 - April
2009 - March
2009 - February
2009 - January
2008 - December
2008 - November
2008 - August
2008 - January
2007 - December
2007 - November
2007 - October
2007 - August
2007 - July
2007 - April
2007 - March
2007 - February
2007 - January
2006 - December
2006 - November
2006 - September
2006 - August
2006 - July
2006 - May
2006 - April
2006 - March
2006 - February
2006 - January
2005 - December
2005 - November
2005 - October
2005 - September
2005 - August