Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change bat file to email failures

Posted on 2012-04-03
7
Medium Priority
?
603 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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