Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Change bat file to email failures

Posted on 2012-04-03
7
Medium Priority
?
604 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 800 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

916 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