I want to run a normal ntbackup (with verify) in a batch file and check if it completed successfully...

I want to create a batch file that will run ntbackup (which I know how to do) and if it completes successfuly will delete certain outdated files, but if the backup does not complete successfuly I do not want to delete the files.

So I think I need a line in the file after the ntbackup command like:

If {error} then go skipit
  delete a
  delete b
  ...
:skipit

How do I test if the ntbackup job of my exchange data store (with verify on) completed  successfully (what expression goes in {error}?

Thank you experts.
Randy_RAsked:
Who is Participating?
 
Lionel MMConnect With a Mentor Small Business IT ConsultantCommented:
If you are only backing up one drive or one folder then yes. There is a Backup successful for each backup job and a verify successful for each job as well, if you choose to verify.
0
 
Randy_RAuthor Commented:
Actually I spoke too soon!  If I have .bks file with my backup job in it, how do I trigger that to run as a line in my .bat file on Windows 2000 SBS?
0
 
Dave StringfellowIT managerCommented:
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Backup.bks" /n "Media created 28/01/2010 at 12:59" /d "Set created 28/01/2010 at 12:59" /n "Media created 28/01/2010 at 12:59" /v:no /r:no /rs:no /hc:on /m normal /j "Backup" /l:s /p "4mm DDS" /um


Best way, create a backup job with windows backup, then go in to the scheduled job and copy the command line out (same as I have posted) just remember to put /UM at the end to use new media.

Hope this helps
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
Randy_RAuthor Commented:
Thank you.  And how do I check if the backup and verificaiton both completed successfullly?
0
 
Dave StringfellowIT managerCommented:
Windows Backup has a logfile located in %user%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data

Not sure you you will be able to check it, but it should be easy as its just a txt file
0
 
Randy_RAuthor Commented:
Is it true that if there is a problem with the backup, then the .bkf file will not exist?  If so, maybe I can just test for its existence?

Also, I am trying to find the file that the task scheduler creates so I can cut and paste the code from it into my batch file, but I can't fine it.  Do you know where it is and how to open it?
0
 
Dave StringfellowIT managerCommented:
Nope, it will create one and say what is wrong, or be blank.. sadly its not that easy :P

Make sure you have setup a backup job in NTBackup 1st, then Open control panel, scheduled tasks edit the backup task and the line you need will be there.
0
 
Randy_RAuthor Commented:
Ok, I see the code.

But I still need a way to check if the backup completed successfully.
0
 
Dave StringfellowIT managerCommented:
Run a backup, and look at the log file, this will show you what a good backup should look like, that way at least you know what to look for. I cant help on parsing log files and reading them im afraid... sorry!
0
 
Randy_RAuthor Commented:
Maybe someone else can help me???
0
 
Lionel MMSmall Business IT ConsultantCommented:
I run all my backups with scripts and then have the log files emailed to me. Here is a copy of one. If my backup does not complete I also get an email with an error log.

:FileBackup
Rem      Added for File backup 2007-09-25
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do Set dt=%%i%%l%%j%%k
for /f "Tokens=1-4" %%i in ('time /t') do Set tm=%%i%%j%%k
Set tm=%tm::=%
Set dtt1=%dt%%tm%
Rem      Set TapeName=%dt%
Set FileName=%dt%
Set >C:\Backup\Logs\Set1.Txt
Echo Backup into File started at %Time% >C:\Backup\Logs\FileStartTime.Txt
GoTo File

:File
ntbackup backup systemstate C:\ /n "%FileName%" /d "Drive-C to Drive-D for %dtt1%" /m normal /v:yes /r:no /rs:no /hc:on /j "Nightly Backup of Server1-C" /l:s /f "D:\Backup\%dt%.Bkf"
If ErrorLevel 1 GoTo File_ERR
Echo Backup File ended at %Time% >C:\Backup\Logs\FileEndTime.Txt
GoTo FileLog

:File_ERR
Echo There was an ERROR with Nightly Backup on %dtt1%>C:\Backup\Logs\NightlyERR-%dt%.Txt
C:\Utils\eMail\blat.exe "C:\Backup\Logs\NightlyERR-%dt%.Txt" -t sci@lionbusiness.com -s "Nightly Backup Error-%dtt1%" -uuencode -server mail.xyz.com -u abc@123.com -pw 345 -log "C:\Backup\Logs\Blat.Csv"
Net Send dlopez Error Nightly Backup DID NOT Complete Successfully!
GoTo FileLog

:FileLog
Set fld=C:\Documents and Settings\%USERNAME%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\
Set fcmd=dir "%fld%*.log" /OD /A-D /B
for /F "tokens=* delims= " %%i in ('%fcmd%') do Set lastf=%fld%%%i
Copy "%lastf%" C:\Backup\Logs\%FileName%.log /y >C:\Backup\Logs\Log1.Txt
GoTo Logs

:Logs
Copy C:\Backup\Logs\%FileName%.Log \\server1\downloads\Nightly.Log /y

:EmailLogFiles
C:\Utils\eMail\blat.exe "C:\Backup\Logs\%FileName%.log" -t backup@southeastcompanies.com -s "Nightly Backup on %FileName%" -uuencode -server mail.abc.com -u abc@123.com -pw 345 -log "C:\Backup\Logs\Blat.Csv"
If ErrorLevel 1 GoTo eMail_Err
GoTo End

:eMail_Err
Net Send * Error SENDING eMail BUT Nightly Backup Completed Successfully!
GoTo Eject

:Eject
Rem      rsm.exe eject /PF"%TapeName% - 1" /astart >C:\Backup\Logs\Eject.Txt

:End
0
 
Randy_RAuthor Commented:
So, "ErrorLevel 1" is dispositive of NTBackup not completing successfully?  If so, is this also true of Normal and Differential backups lionelmm?
0
 
Lionel MMSmall Business IT ConsultantCommented:
This is not always true unfortunately. If backup does not start at all this errorlevel check works, like when a tape is missing or a drive is full. If back starts and then encounters and error my batch file does not always get the proper errorlevel but the log file I get by email, set to send me the summary, does. So in combination either bu errorlevel or by the email I always catch backup errors.
0
 
Randy_RAuthor Commented:
Is there a text phrase that reliably appears in the log file if everything, including verification, completes successfuly that I could check for in a batch file?
0
 
Lionel MMSmall Business IT ConsultantCommented:
Backup completed on date at time

Example
(9/2/2010 at 11:18 PM.)
0
 
Randy_RAuthor Commented:
So if there is any error at all, that text won't be in the log file, correct?
0
 
Randy_RAuthor Commented:
Thank you very much.

One more question if you don't mind.  When sending mail from the batch file, why would I use blat over sendmail, or vice versa?
0
 
Lionel MMSmall Business IT ConsultantCommented:
Its just one I know--if you prefer sendmail use it. Its just a question of habit--sendmail is probably better and safer I don't know.

Also I checked some of my logs that have errors and this may help you to look for as well
"The operation did not successfully complete" is what I get when backup did NOT complete successfully.

If you automate your logs with send mail mind sending me the script for that so I can try it--thanks?
0
 
Randy_RAuthor Commented:
No problem.  So, I'll leave the question open?
0
 
Lionel MMSmall Business IT ConsultantCommented:
You can close it
 just email it to me if you remember. lionelmm@msn.com
0
 
Randy_RAuthor Commented:
Ok.  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.