Friday, March 23, 2012

How to test if a full backup exists

I'm writing a automated backup routine for both SQL Server 2000 and 2005 that
will be a combination of full (once a week) and differential (all other days
of the week) backups.
My problem is that if someone creates a new database I need to automatically
take a full backup before the differential backup (or I'll get error 3035
"Cannot perform a differential backup"). So I would like to know if there is
a way to test if a full backup has been taken for a specific database?
Yes, I know about msdb.dbo.backupset but that's not a fullproof solution
since someone can create a new database with the same name as a previously
backed up database.
I have searched through DATABASEPROPERTY, DATABASEPROPERTYEX and all columns
in sysdatabases, sysfiles etc without any luck. Have I missed something or is
this property not available?
-AllanYou can use a combination of the name, create date, type and backup finish
date between the sysdatabases and backupset tables to determine whether a
full backup has occured for a given database. create date is found on both
backupset and sysdatabases and is the key to making sure the backup is
associated with the correct "version" of databases created over time with
the same name. NOTE: you will need to lop off the milliseconds to get the
join to work
sysdatabases.crdate
2007-05-01 09:35:14.553
backupset.database_creation_date
2007-05-01 09:35:14.000
Kevin G. Boles
TheSQLGuru
Indicium Resources, Inc.
"Allan" <allan@.newsgroups.nospam> wrote in message
news:C3484A5E-287C-4953-98DF-C34762A684CD@.microsoft.com...
> I'm writing a automated backup routine for both SQL Server 2000 and 2005
> that
> will be a combination of full (once a week) and differential (all other
> days
> of the week) backups.
> My problem is that if someone creates a new database I need to
> automatically
> take a full backup before the differential backup (or I'll get error 3035
> "Cannot perform a differential backup"). So I would like to know if there
> is
> a way to test if a full backup has been taken for a specific database?
> Yes, I know about msdb.dbo.backupset but that's not a fullproof solution
> since someone can create a new database with the same name as a previously
> backed up database.
> I have searched through DATABASEPROPERTY, DATABASEPROPERTYEX and all
> columns
> in sysdatabases, sysfiles etc without any luck. Have I missed something or
> is
> this property not available?
> -Allan

No comments:

Post a Comment