#first, stop "Venus"
if [ -x /usr/bin/vmware ]
  then  
    ESXV3=`/usr/bin/vmware -v | grep "ESX Server 3"`
    if [ -n "$ESXV3" ]
    then
        # Get the VM list and grep on Venus
      VMLIST=`/usr/bin/vmware-cmd -l | grep Venus`
        for VM in $VMLIST
        do
          # Get the VM state
              VMSTATE=`/usr/bin/vmware-cmd "$VM" getstate -q`
        # Guest OS shutdown if VMSTATE is equal to "on"
        if [ "$VMSTATE" == "on" ]
        then
          echo "Stopping Venus ($VM)"
          /usr/bin/vmware-cmd "$VM" stop trysoft
          sleep 2
        fi
      done
      # Delay for 1,5 minute to give the VMs more time
      # to cleanly shutdown
      sleep 90
    fi
  fi
#see if Venus has shut down
VMLIST=`/usr/bin/vmware-cmd -l | grep Venus`
for VM in $VMLIST
  do
  VMSTATE=`/usr/bin/vmware-cmd "$VM" getstate -q`
  if [ "$VMSTATE" == "off" ]
        then
        #remove the old backup folder
        /bin/rm /vmfs/volumes/SAN_os_Storage_170Gb/backups/Venus -rf >>/var/log/backup.log
        #create a new backup folder
        /bin/mkdir /vmfs/volumes/SAN_os_Storage_170Gb/backups/Venus >>/var/log/backup.log
        #copy all files to the backup folder
        /bin/cp /vmfs/volumes/storage1/Venus/* /vmfs/volumes/SAN_os_Storage_170Gb/backups/Venus -R >>/var/log/backup.log
  fi
done
#start Venus again
  if [ -x /usr/bin/vmware ]
  then  
    ESXV3=`/usr/bin/vmware -v | grep "ESX Server 3"`
    if [ -n "$ESXV3" ]
    then
        # Get the VM list and grep on Venus
      VMLIST=`/usr/bin/vmware-cmd -l | grep Venus`
        for VM in $VMLIST
        do
          # Get the VM state
              VMSTATE=`/usr/bin/vmware-cmd "$VM" getstate -q`
        # Guest OS shutdown if VMSTATE is equal to "off"
        if [ "$VMSTATE" == "off" ]
        then
          echo "Starting Venus ($VM)"
          /usr/bin/vmware-cmd "$VM" start
          sleep 2
        fi
      done
    fi
  fi




/usr/bin/perl /usr/local/bin/vmbk.pl -d /vmfs/volumes/SAN_os_Storage_170Gb/backups -1 -4 -c -C /vmfs/volumes/storage1/hercules/vmbk-hercules.conf -x /vmfs/volumes/storage1/hercules/hercules.vmx
/usr/bin/perl /usr/local/bin/vmbk.pl -d /vmfs/volumes/SAN_os_Storage_170Gb/backups -1 -4 -c -C /vmfs/volumes/storage1/apollo/vmbk-apollo.conf -x /vmfs/volumes/storage1/apollo/apollo.vmx 
