Wbadmin email alert on failure

5,050

Solution 1

If you've already had a failed backup it should be easy enough to accomplish by finding the failed backup in the Backup|Operational event log, right-clicking the failed event, selecting "Attach Task to this Event", and filling out the task settings appropriately.

Then whenever a backup fails and logs the event to the log, an email will be sent based on your task configuration.

Solution 2

On Server 2012, The backup tool writes two log files after each backup task: enter image description here

  • When successfull,Backup_Error-<date>.log is created but empty.
  • When unsuccessful, I assume that a Backup_Error-<date>.log would be populated with data.

    Using task scheduler, I run a batch file to achieve the following:

    1. Delete empty .log files in C:\Windows\Logs\WindowsServerBackup directory
    2. Search for (remaining) Backup_Error*.log (because non-empty)
    3. Mail its content to me using Blat
@echo off
:: This script has been written to monitor WBAdmin backups on Server 2012
::
:: Tested on: Microsoft Windows Server 2012 Standard (6.2.9200 N/A Build 9200) 
:: Date:      September 4, 2015
:: Author Florian Bidabe @Enelass (https://au.linkedin.com/in/bidabe)

::Variables
set MailServer=
set Sender=
set Recipient=


:: Delete Empty files
cd C:\Windows\Logs\WindowsServerBackup
for %%F in (*) do if %%~zF equ 2 del "%%F"

:: Look for Backup_Error file(s)
dir C:\Windows\Logs\WindowsServerBackup\Backup_Error*.log  > nul 2> nul
if %ERRORLEVEL% EQU 0 goto :AdminAlert
echo No Error Logs available ! Backup suceeded !
ping 0.0.0.0 -n 5 > nul 2> nul
exit 0

:AdminAlert
:: Test if blat can be found (SMTP Server)
where blat > nul 2> nul
if not %ERRORLEVEL% EQU 0 (
 echo Blat cannot be found... Copy blat.exe in system32!
 ping 0.0.0.0 -n 5 > nul 2> nul
 exit 1)

:: Select most recent error log
FOR %%F IN (C:\Windows\Logs\WindowsServerBackup\Backup_Error*.log) DO (
 set filename=%%F
 goto :Send
)

:Send
blat -SaveSettings -f %Sender% -server %MailServer%
blat -body "Hello Administrator, Please consult the attached log" -attach %filename% -s "%computername% - Windows Server Backup has failed !" -to %Recipient%
exit 0
Share:
5,050

Related videos on Youtube

Greg
Author by

Greg

Updated on September 18, 2022

Comments

  • Greg
    Greg almost 2 years

    Does anyone have a script they use with WBADMIN to send email alerts? I am a scripting newbie and having trouble finding a solution to notify on failed backups. Seems like it would be a useful tool to have.

    I am running Server 2008 R2 Foundation and backing up to a NAS. I am using wbadmin with task scheduler to perform daily backups.

    UPDATE We do not have a budget for third party solutions so I am trying to effect a solution through a simple script.

    • Hecter
      Hecter almost 12 years
      I would recommend BackupAssist for this type of scenario.
    • Hecter
      Hecter over 8 years
      @FlorianBidabe Check timestamps above.
    • Admin
      Admin over 8 years
      Since email notifications through the scheduler is no longer supported (and was lacking to begin with), I've written a PowerShell script to review the logs and send a nice, easy to read, report. Check it out at: blog.jocha.se/tech/wbadmin-backup-mail-reportenter image description here
  • Don OzOn
    Don OzOn almost 9 years
    Can you please post <<your script>> ?
  • Don OzOn
    Don OzOn almost 9 years
    I followed the instructions on the site, enter all parameters in the ini and got a "ERR job not found: PRINTSRVBCK" every time I run the scheduled task. MKSBackup was last update in Januray 2013.
  • Don OzOn
    Don OzOn almost 9 years
    The question is about WBAdmin
  • Don OzOn
    Don OzOn about 7 years
    You can test this script by filling the Backup_Error*.log with random data.