Solved

Change bat file to email failures

Posted on 2012-04-03
7
580 Views
Last Modified: 2012-04-05
Hello Everyone, I run a batch file that backs up a local copy of my SharePoint Server and then copies that backup file to a NAS server where I later back it up to tape or disk. I was wondering if based on the following lines that I have in my script if there was some way to determane if it failed and if so can I send myself an email that if failed.

Here is what I run each evening to get my backup....

cd %programfiles%\Common Files\Microsoft Shared\web server extensions\12\BIN


stsadm.exe -o backup -url https://SHAREPOINTSITE -filename C:\SharePointBak\SPSiteBak.dat -overwrite


xcopy "C:\SharePointBak" "\\NAS DATA SERVER\SharePoint Backup" /e /y
0
Comment
Question by:CCG3
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Assisted Solution

by:Grasty86
Grasty86 earned 200 total points
ID: 37803535
If your looking for the simplest answer you could check to see if it completed by simply checking to see if the file exists on the NAS Data Server ...

IF EXIST "\\NAS DATA SERVER\SharePoint Backup" GOTO YES

Send Email

:YES
exit


Basically, if the file is there, it skips the email command and exits, if the file isnt there, it would send the email.

You could also have it send the email regardless so if the file is there then send an email saying it succeeded otherwise send an email saying it failed.

As for sending the email. Here is a good article about it, they use a third party app to send the email, that would probably be the simplest.
http://stackoverflow.com/questions/709635/sending-mail-from-batch-file
0
 
LVL 13

Expert Comment

by:Daz_1234
ID: 37805996
Apparently stsadm.exe returns 0 when successful and -1 (or non-zero) when it fails [1].

I would do something like this:
cd %programfiles%\Common Files\Microsoft Shared\web server extensions\12\BIN


stsadm.exe -o backup -url https://SHAREPOINTSITE -filename C:\SharePointBak\SPSiteBak.dat -overwrite
If %ERRORLEVEL% NEQ 0 Goto EmailFail

xcopy "C:\SharePointBak" "\\NAS DATA SERVER\SharePoint Backup" /e /y

Goto End

:EmailFail
REM Do the emaily-bit here

:End
REM End Of Script

Open in new window


Hope this helps,
Daz.

[1] http://blogs.msdn.com/b/markarend/archive/2007/11/08/scripting-stsadm-commands.aspx
0
 
LVL 4

Expert Comment

by:Grasty86
ID: 37806082
That would only notify you if the backup failed, not if the backup succeeded and the copy failed.

Maybe you could modify that so that there is 2 spots to send an email? One to send an email saying the Backup Failed, and another that said the copy failed but the backup succeeded.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:CCG3
ID: 37806212
That is a great suggestion Grasty! How would i do that?

I created a vbs to send an email and I am calling that vbs to send an email if it fails to backup. How would I determine if the copy fails and then send an email if it does?
0
 
LVL 13

Accepted Solution

by:
Daz_1234 earned 300 total points
ID: 37806370
You can do that the same way: xcopy returns non-zero if it fails [1].
cd %programfiles%\Common Files\Microsoft Shared\web server extensions\12\BIN


stsadm.exe -o backup -url https://SHAREPOINTSITE -filename C:\SharePointBak\SPSiteBak.dat -overwrite
If %ERRORLEVEL% NEQ 0 Goto STSADMFail

xcopy "C:\SharePointBak" "\\NAS DATA SERVER\SharePoint Backup" /e /y
If %ERRORLEVEL% NEQ 0 Goto CopyFail

Goto End

:STSADMFail
REM Do the emaily-bit here
Goto End

:CopyFail
REM EmaIL COPY fail
Goto End

:End
REM End Of Script

Open in new window


Regards,
Daz

[1] XCOPY: 0 success, 1 no files found to copy, 2 aborted by ctrl+c, 4 initialization error (not enough memory or disk space, invalid drive, or syntax error), 5 disk write error.
0
 
LVL 4

Expert Comment

by:Grasty86
ID: 37808464
I agree, Daz's should work great for you (once you put in your calls for the vbs script you have of course.
0
 

Author Comment

by:CCG3
ID: 37812191
Thanks guys! I was able to set this up and test it yesterday and I ran it live last night. Everything seems to be fine. Thanks for your help!!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question