The following scenario (on SQL Server 2008 R2 and 2012 servers)
A co-worker of mine restored another DB into the one our process was trying to create a differential backup for. As I am currently only checking for the existence of any row for that respective DB in the msdb.dbo.backupset
, a differential backup has been initiated - a row has been found. It failed, because the DB was not the one matching the full backup.
Now, to decide whether a full backup needs to be taken or a differential backup can be initiated, I would like to know exactly if the db uid and the backup's uid match - only then I want to create a differential backup, otherwise first create a full backup.
Can anybody tell me if the following is a sensible thing to do:
SELECT
sysdb.name
FROM
sys.databases sysdb
INNER JOIN
sys.master_files sysmf ON sysmf.database_id = sysdb.database_id
INNER JOIN
msdb.dbo.backupset bck ON bck.backup_set_uuid = sysmf.differential_base_guid
WHERE
sysdb.name = @dbname
AND bck.database_name = sysdb.name
AND bck.type = 'D'
Thank you very much in advance for a feedback,
Cheers