Tuesday, March 27, 2012

Error processing BACKUP DATABASE statement

Hello all!
I do database backup using SQL-script (BACKUP DATABASE to ...). This scripts
runs by osql utility.
How i can know - was backup successful or not.
I'm trying to use @.@.error variable, but it doesn't return error if device is
full or doesn't exists.
How can i do such error processing is SQL-script ?
Thanks, SlavaIf works, you get errors - example
-- I don't have disk n:
backup database northwind to disk='n:\notexisting.bak'
select @.@.error As 'Error No.'
-- Output in QA
Server: Msg 3201, Level 16, State 1, Line 1
Cannot open backup device 'n:\notexisting.bak'. Device error or device
off-line. See the SQL Server error log for more details.
Server: Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
Error No.
--
3013
Check your script. Also, if you are using a scheduled job, you can define
workflow - what to do is a task fails, for example send a mail to a
operator.
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Slava" <Slava@.discussions.microsoft.com> wrote in message
news:22375259-06DC-4C80-A66C-4136A1A897FB@.microsoft.com...
> Hello all!
> I do database backup using SQL-script (BACKUP DATABASE to ...). This
scripts
> runs by osql utility.
> How i can know - was backup successful or not.
> I'm trying to use @.@.error variable, but it doesn't return error if device
is
> full or doesn't exists.
> How can i do such error processing is SQL-script ?
> Thanks, Slava

No comments:

Post a Comment