Link to home
Start Free TrialLog in
Avatar of Randy_R
Randy_R

asked on

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.
Avatar of Randy_R
Randy_R

ASKER

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?
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
Avatar of Randy_R

ASKER

Thank you.  And how do I check if the backup and verificaiton both completed successfullly?
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
Avatar of Randy_R

ASKER

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?
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.
Avatar of Randy_R

ASKER

Ok, I see the code.

But I still need a way to check if the backup completed successfully.
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!
Avatar of Randy_R

ASKER

Maybe someone else can help me???
Avatar of Lionel MM
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
Avatar of Randy_R

ASKER

So, "ErrorLevel 1" is dispositive of NTBackup not completing successfully?  If so, is this also true of Normal and Differential backups lionelmm?
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.
Avatar of Randy_R

ASKER

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?
Backup completed on date at time

Example
(9/2/2010 at 11:18 PM.)
Avatar of Randy_R

ASKER

So if there is any error at all, that text won't be in the log file, correct?
ASKER CERTIFIED SOLUTION
Avatar of Lionel MM
Lionel MM
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Randy_R

ASKER

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?
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?
Avatar of Randy_R

ASKER

No problem.  So, I'll leave the question open?
You can close it
 just email it to me if you remember. lionelmm@msn.com
Avatar of Randy_R

ASKER

Ok.  Thanks!