Solved

Change bat file to email failures

Posted on 2012-04-03
7
571 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 12

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 12

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now