Solved

Change bat file to email failures

Posted on 2012-04-03
7
562 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:CCG3
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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. …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now