ghettoVCB Log-2-Email, Version 1.00
Last Update: 2/1/2016

Download The Package

I developed the attached Windows batch file for use with VMware (I use ESXi 4/5/6) and ghettoVCB.  When used in conjuction with ghettoVCB’s log file, it will:

  1. Pull the logfile out of your ESXi datastore using WGET.EXE.
  2. Detect if:
    a. There is a “Final status: ERROR” message in the log (error condition).
    b. The backup process ran with no errors.
    c. The backup log contained neither a good or bad backup indication (blank/empty file handling).
  3. After checking the above, the script will e-mail you the log file/result using BLAT.EXE mailer.  It will clearly tell you in the subject if the backup was successful or not.  If your logfile does not exist (job never ran) it  sends an e-mail alerting you to this as well.
  4. After e-mailing, the logs are rotated and the script will keep up to 6 backups of past logs should you need to trace an older backup.  The filenames will be “Backup1.log” – “Backup6.log”.  “Backup1.log” being the newest backup log rotated, and “Backup6.log” being the oldest.

gvlog2em Installation and Setup Instructions:

  • Ensure that your ghettoVCB command line (cronjob) redirects to the same logfile using “>”, if you use “-L” or “>>” you are appending to the same file.  For instance my rc.local injection looks like this:
    — For ESXi 4 – 5.0
    /bin/kill $(cat /var/run/crond.pid)
    /bin/echo “0 6 * * 0 /vmfs/volumes/datastore1/Tools/ghettoVCB.sh -a > /vmfs/volumes/datastore2/Logs/backup.log” >> /var/spool/cron/crontabs/root
    /bin/busybox crond

    — For ESXi 5.1+
    /bin/kill $(cat /var/run/crond.pid)
    /bin/echo “0 6 * * 0 /vmfs/volumes/datastore1/Tools/ghettoVCB.sh -a > /vmfs/volumes/datastore2/Logs/backup.log” >> /var/spool/cron/crontabs/root
    /usr/lib/vmware/busybox/bin/busybox crond
  • Download the gvLog2Em package here.  Extract to a folder/directory of your choosing.
  • Edit the environment variables in gvlog2em.bat to match your environment.

Note: Make sure NOT to use quotations (even for long file paths) in defining variables.
Also make sure there are NO SPACES between the variable and the string “var=string”.

set usewget=1    <– Use WGET.EXE to pull the LOG file?  If 0/no then we just parse and rotate.
set vmwserver=192.168.100.201   <– Your server IP
set vmwroot=root   <– root or user with access to browse datastores over HTTPS
set vmwrootpw=rootpassword
set logvmwdstore=datastore2    <– Logfile datastore
set logvmwpath=/VMBackups/Logs/backup.log     <– Path to logfile on datastore above

set progpath=c:\gvlog2em     <– The path to BLAT.EXE mailer & WGET.EXE / local or network
set logpath=c:\gvlog2em\log      <– The path to your logfiles (or to store them using WGET.EXE) / local or network
set logfile=backup.log  <– The name of your logfile (cosmetic if using WGET)
set temppath=%temp% <– Writable path to store temp mailbody text file.  Usually you can leave it as-is.

set emailfrom=vmware@yourdomain.com  <– Backup log “From” email address.
set emailto=you@yourdomain.com  <– Backup log “To” email address.

set emailsmtp=mail.yourdomain.com  <– Your SMTP server
set emailport=25  <– Your SMTP port

set emailauth=1  <– 1 = on, 0  = off
set emailauthu=username  <– SMTP auth username
set emailauthp=password  <– SMTP auth password

set esxiserver=myesxi.yourdomain.com  <– The name of your ESX(i) server, used in SUBJECT line (cosmetic).

  • Make sure the Windows machine running this script has read, write and execute access to the logfile path (usually a local path)
  • Test the operation of the script/batch in your environment, checking for errors in the console output.
  • Once confirmed working, schedule a Windows task to run after your ghettoVCB backup.  (I use an XP virtual machine running on my ESXi server).

Tip: To enable logging of the batch file so you can troubleshoot your automated process, simply redirect it to a file when scheduling the automated task (after interactive testing), like this:

gvlog2em.bat > \\computer\share\path\gvlog2em.log

or really get nuts and put a date stamp at the end:

gvlog2em.bat > \\computer\share\path\gvlog2em_%date:~12,2%-%date:~4,2%-%date:~7,2%.log

 

How I use it:

  • I run a LOCAL cronjob on the ESXi server calling William Lam’s ghettoVCB.sh
  • I scheduled a Windows task to run the script 6 hours after my ghettoVCB backup (mine takes approx 2 hours to complete).

My (current) environment:

  • VMware ESXi 5.5 & 6
  • ghettoVCB.sh (latest) running locally within ESXi via rc.local injection cronjob.
  • ghettoVCB backs up to a secondary hard drive/datastore.  My backup happens once a week on Sunday.
  • Windows XP Professional VM on same server runs the task at 6:00am on Sunday.

Please let me know if you experience any issues or have improvements in mind!  I will continue to update this script as I receive feedback.

Changelog:

1.00 – Final Release

0.99 – Redesigned functionality; added log pulling functionality to the script.

0.95 (3) – Added WGET instructions, program and sample batch file to pull log directly from datastore, via VMware web datastore browser.

0.95 (2) – Fixed minor issue with feature introduced in 0.95, where the log would not be included if error or success conditions were not found.

0.95 – Handling of blank log files that do not indicate good or bad backup – will send an error message email.  Usually blank logs are due to ghettoVCB version issues.

0.94 – Better handling of non-existant/offline NFS systems/logpath shares.  Changed failure e-mail body bug that would not send an error e-mail if the logpath was not found.  New variable introduced “tempvar”.  See revision in the parameters section of the installation tutorial above.

0.93 – Minor cosmetic changes.

0.92 – Changed find behavior to look for final status error messages only, so that NFS sleep errors are not reported for successful backups.

0.91 – Added SMTP high priority flag to BLAT.EXE command line for unsuccessful backups.  Succesful backups are sent with the normal priority.  5/11/2010

0.90 – Initial Release  5/11/2010

 

Thanks to:

  • William Lam for creating ghettoVCB.  The “Rolls-Royce” of ghetto VMware backup solutions.
  • BLAT, one of the handiest utilities for Windows in my toolbox.. and all the folks who brought it to fruition!
ERROR: Could not find the BLAT.EXE mailer at ..
ERROR: Without BLAT.EXE I can’t continue!


Tagged with:  

23 Responses to E-mail ghettoVCB Backup Logs for Windows & VMware ESX/ESXi

  1. Alex G. says:

    Hi Mike,

    thank you for your reply on http://communities.vmware.com/docs/DOC-8760.

    I tried this script and it does, what i missed all the time: I get a backup result via email. Now my Backup Solution is perfect, ghettoVCB backup my machines and your script informs me about the backup result.

    Great job.

    Best regards,
    Alex

  2. Mathijs says:

    thanks for the scripts! exactly what I was looking for

  3. Christian says:

    Hi I have a few problems with the script:

    Found BLAT at C:\ESXi-Script\gvlog2em\blat.exe..

    Found WGET at C:\ESXi-Script\gvlog2em\wget.exe..

    Running WGET.EXE to retrieve /sbin/ghettovcb/ghettoVCB.log from Host01 on host01
    .xxxxx.loc
    –2011-03-22 14:32:36– https://host01.xxxxxx.loc/folder/sbin/ghettovcb/ghettoV
    CB.log?dcPath=ha-datacenter&dsName=Host01
    Resolving host01.xxxxx.loc… 172.20.22.191

    Connecting to host01.xxxxx.loc|172.20.22.191|:443… connected.

    WARNING: cannot verify host01.xxxxx.loc’s certificate, issued by `/O=VMware Ins
    taller’:
    Unable to locally verify the issuer’s authority.
    HTTP request sent, awaiting response… 401 Unauthorized

    Connecting to host01.xxxxxx.loc|172.20.22.191|:443… connected.

    WARNING: cannot verify host01.xxxxx.loc’s certificate, issued by `/O=VMware Ins
    taller’:
    Unable to locally verify the issuer’s authority.
    HTTP request sent, awaiting response…

    Do you have any tips for me?

    • Mike Waldron says:

      Can you verify that you have the parameter “–no-check-certificate” on your WGET command line? It’s built into the batch file, so it’s strange that you are still getting a cert error.

  4. Christian says:

    Hi,

    yes the parameter is set. Here is the command:

    :GETLOG
    echo off
    echo Running WGET.EXE to retrieve %logvmwpath% from %logvmwdstore% on %vmwserver%
    “%progpath%\wget.exe” –no-check-certificate –user %vmwroot% –password %vmwrootpw% “https://%vmwserver%/folder%logvmwpath%?dcPath=ha-datacenter&dsName=%logvmwdstore%” –output-document %logpath%\%logfile%

  5. Mike Waldron says:

    I also see in your log:

    HTTP request sent, awaiting response… 401 Unauthorized

    The certificate error may not be your problem.. it may be the username you are using (unauthorized). If not using “root”, temporarily try the root username and password and see if it works for you.. then you can troubleshoot your security.

  6. Christian says:

    Hi Mike,

    i use my root user. Are there any additional settings i need to activate? I use VMWare ESXi 4.1 for my Host and try to start the script on a sencondary W2k8R2 DC.

  7. Mike Waldron says:

    Ok, the only other thing I see that could be a problem is that you are not storing your logs on a datastore. I don’t believe you can retrieve any files using WGET from anything BUT a datastore (you are using /sbin). Try moving your logs to
    /vmfs/volumes/datastore1/logs or something on one of your datastores and try that. As a rule of thumb never store anything on the vmware system volume, only use datastores for both the script and the logs.

  8. Christian says:

    Ok, i think my Problem was, that i set the absolute path in the batchfile. I changed that and now im getting a 404 File not found.

    Now my Batchfile look like that:

    set logvmwdstore=vmware
    set logvmwpath=LOG\ghettoVCB.log

    I followed your advice and I have moved the ghettovcb.sh and the logfile on a separate data store!

  9. Christian says:

    Hey!

    Now its working. I changed a setting again 😉

    set logvmwpath=/LOG/ghettoVCB.log

  10. Mike Waldron says:

    You need to format like:

    let say your log path is /vmfs/volumes/datastore1/LOGS/backup.log

    The params should be:

    set logvmwdstore=datastore1
    set logvmwpath=/LOGS/backup.log

  11. Christian says:

    Hey,

    thanks for your help! 🙂 🙂 🙂 🙂 🙂

  12. Lovro says:

    Hi,

    I hope you are still into this 🙂
    I get output :

    gvlog2em by Waldron Digital / http://www.waldrondigital.com
    ———————————————————
    Starting up .. version is 0.99
    Performing environment check..
    . was unexpected at this time.

    Did everything like you instructed. My environment :
    – ESXi 5
    – W2k8R2
    – Logging to local datastore of esxi 5.

    Regards,
    Lovro

    • Mike Waldron says:

      Lovro had inserted a tab character in the emailsmtp variable which was causing his error. If you receive a “. was unexpected at this time” look for errant tabs in your variables.

  13. Davet says:

    Just thought i would leave a note thanking you for a great contribution so that you are aware it is still being used and valued.

  14. Hemang Pokal says:

    Hi there,

    I been trying the script. So far, it is successful to retrieve the backup log and put it under the folder specified. The only thing it fails is to send email. It shows following error:

    Sending c:\putty\gvlog2em\logs\backup.log to hemangpokal@gmail.com
    Subject: Success: VMware Backup Completed for ESXi5.VMWare.Cone.com on 20
    14-02-12
    Login name is hemangpokal@gmail.com
    The SMTP server does not require AUTH LOGIN.
    Are you sure server supports AUTH?
    The SMTP server does not like the sender name.
    Have you set your mail address correctly?

    Could you please help me out how I can sort this out or what I am missing?

    I am using gmail smtp server : smtp.gmail.com and 587 as port number. It is a TLS type but there is no such place within your code to mention it or even I am not sure if its needed.

    Your response is heartly awaited and many thanks for sharing such a beautiful code. Thank you very much.

  15. Hemang Pokal says:

    Thank you very much for the reply. Sure would give it a try.

  16. This is actually needed for windows based mail servers, else they run into issues. As mentioned this feature is experimental and since there is no real mail client, the format may need to be tweaked for different mail servers.

Leave a Reply

Your email address will not be published. Required fields are marked *

Web Hosting