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.
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.
C:\WINDOWS\system32\ntback up.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
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
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
Not sure you you will be able to check it, but it should be easy as its just a txt file
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?
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.
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.
ASKER
Ok, I see the code.
But I still need a way to check if the backup completed successfully.
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!
ASKER
Maybe someone else can help me???
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\FileStartT ime.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\FileEndTim e.Txt
GoTo FileLog
:File_ERR
Echo There was an ERROR with Nightly Backup on %dtt1%>C:\Backup\Logs\Nigh tlyERR-%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\Nightl y.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
: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\FileStartT
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\FileEndTim
GoTo FileLog
:File_ERR
Echo There was an ERROR with Nightly Backup on %dtt1%>C:\Backup\Logs\Nigh
C:\Utils\eMail\blat.exe "C:\Backup\Logs\NightlyERR
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%.
GoTo Logs
:Logs
Copy C:\Backup\Logs\%FileName%.
:EmailLogFiles
C:\Utils\eMail\blat.exe "C:\Backup\Logs\%FileName%
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
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.
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.)
Example
(9/2/2010 at 11:18 PM.)
ASKER
So if there is any error at all, that text won't be in the log file, correct?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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?
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?
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
just email it to me if you remember. lionelmm@msn.com
ASKER
Ok. Thanks!
ASKER