Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Last Backup Taken, or Not


Last Backup Taken, or Not

Author
Message
DBA Pete
DBA Pete
Valued Member
Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)

Group: General Forum Members
Points: 63 Visits: 2286
Hi Jon,

This is what I mean:

Create a new database called TEST in full recovery mode. It has never been backed up and shows as:

DatabaseName recovery_model BackupType LastBackUpTaken
TEST No Backup Taken No Backup

Backup the database and this now shows as:

DatabaseName recovery_model BackupType LastBackUpTaken
TEST FULL Full Dec 11 2012 10:53AM

But what I would find useful is to show that while the database had a full backup, it has never had a transaction log backup.
This is important as I have seen many cases of a database set up by vendors where the database is in full recovery mode.
It has regular full backups but never a transaction log backup.
This often results in the transaction log being larger than the main data file.

I think it would be useful to show something like the second row below:

DatabaseName recovery_model BackupType LastBackUpTaken
TEST FULL Full Dec 11 2012 10:53AM
TEST FULL Log Never

Regards,

DBA Pete.



Jon.Morisi
Jon.Morisi
Mr or Mrs. 500
Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)

Group: General Forum Members
Points: 539 Visits: 1142
I hear what you're saying, but I use this script on a regular basis to identify the issue. I do this by reviewing the output and if I see database name, full recovery, only a full backup and not another line indicating a transaction log backup, I know there's an issue. If you'd like to make an update to the script that inserts a line stating no t-log backup when the above is true, please feel free to contribute.

Thanks,
Jon
Karl Klingler
Karl Klingler
SSC-Addicted
SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)

Group: General Forum Members
Points: 492 Visits: 2074
Hi,

this is not so short anymore, but should do the trick...

;WITH a AS (SELECT 'Full' AS type UNION ALL SELECT 'Log' UNION ALL SELECT 'Differential'), b AS
( SELECT Name, DATABASEPROPERTYEX(Name, 'recovery') AS rm
FROM sys.sysdatabases
), c AS
( SELECT * FROM a , b WHERE rm = 'FULL' OR (rm = 'SIMPLE' AND type IN ( 'FULL', 'Differential') )
), d AS
( SELECT database_name,
Isnull(Max(recovery_model),'No Backup Taken') AS backup_recovery_model,
CASE type
WHEN 'D' THEN 'Full'
WHEN 'I' THEN 'Differential'
WHEN 'L' THEN 'Log'
ELSE COALESCE(type,'No Backup')
END AS BackupType,
CONVERT(VARCHAR(17), CONVERT(DATETIME, Max(backup_finish_date), 113)) AS LastBackUpTaken
FROM msdb.dbo.backupset
GROUP BY database_name, type
)
SELECT c.Name AS DatabaseName,
c.rm AS database_recovery_model,
c.type AS BackupType,
Isnull(d.LastBackUpTaken, 'Never') AS LastBackUpTaken
FROM c LEFT OUTER JOIN d
ON d.database_name = c.name AND c.type = d.BackupType
WHERE NOT ( c.type = 'Differential' AND d.LastBackUpTaken IS NULL) AND c.name <> 'tempdb'
GROUP BY c.Name, d.BackupType, d.LastBackUpTaken, c.rm, c.type
ORDER BY 1, 3



All corrections are welcome... :-)

Best regards
karl
DBA Pete
DBA Pete
Valued Member
Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)

Group: General Forum Members
Points: 63 Visits: 2286
Hi Karl,

That works.
I also could not find a better way than to use an additional union to get this information.

If anyone does come up with a better way then let us know.

Thanks,

DBA Pete



Karl Klingler
Karl Klingler
SSC-Addicted
SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)

Group: General Forum Members
Points: 492 Visits: 2074
Hi,

i had neglected bulk_logged databases... Here a better script

;WITH a AS
( SELECT type='D' UNION ALL SELECT 'L' UNION ALL SELECT 'I'
), c AS
( SELECT b.Name, DATABASEPROPERTYEX(b.Name, 'recovery') as rm, a.type
FROM a, sys.sysdatabases b
WHERE DATABASEPROPERTYEX(b.Name, 'recovery') IN ( 'FULL', 'BULK_LOGGED') OR a.type IN ( 'D', 'I')
), d AS
( SELECT database_name,
Isnull(Max(recovery_model),'No Backup Taken') AS backup_recovery_model,
type,
CONVERT(VARCHAR(17), CONVERT(DATETIME, Max(backup_finish_date), 113)) AS LastBackUpTaken
FROM msdb.dbo.backupset
GROUP BY database_name, type
)
SELECT c.Name AS DatabaseName,
c.rm AS database_recovery_model,
CASE c.type
WHEN 'D' THEN 'Full'
WHEN 'I' THEN 'Differential'
WHEN 'L' THEN 'Log'
ELSE COALESCE(d.type,'No Backup')
END AS BackupType,
Isnull(d.LastBackUpTaken, 'Never') AS LastBackUpTaken
FROM c LEFT OUTER JOIN d
ON d.database_name = c.name AND c.type = d.type
WHERE NOT ( c.type = 'I' AND d.LastBackUpTaken IS NULL) AND c.name <> 'tempdb'
GROUP BY c.Name, c.type, d.LastBackUpTaken, c.rm, d.type
ORDER BY c.Name, c.type



Best regards
karl
Karl Klingler
Karl Klingler
SSC-Addicted
SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)SSC-Addicted (492 reputation)

Group: General Forum Members
Points: 492 Visits: 2074
... and one more version.
This one works on SQL Server versions 2000-2012...

SELECT c.Name AS DatabaseName, c.rm AS database_recovery_model, 
CASE c.type
WHEN 'D' THEN 'Full'
WHEN 'I' THEN 'Differential'
WHEN 'L' THEN 'Log'
ELSE COALESCE(d.type,'No Backup')
END AS BackupType,
Isnull(d.LastBackUpTaken, 'Never') AS LastBackUpTaken
FROM ( SELECT b.Name, DATABASEPROPERTYEX(b.Name, 'recovery') as rm, a.*
FROM (SELECT type='D' UNION ALL SELECT 'L' UNION ALL SELECT 'I') a, master.dbo.sysdatabases b
WHERE DATABASEPROPERTYEX(b.Name, 'recovery') IN ( 'FULL', 'BULK_LOGGED') OR a.type IN ( 'D', 'I')
) c LEFT OUTER JOIN ( SELECT database_name,
--Isnull(Max(recovery_model),'No Backup Taken') AS backup_recovery_model,
type,
CONVERT(VARCHAR(17), CONVERT(DATETIME, Max(backup_finish_date), 113)) AS LastBackUpTaken
FROM msdb.dbo.backupset
GROUP BY database_name, type
) d
ON d.database_name = c.name AND c.type = d.type
WHERE NOT ( c.type = 'I' AND d.LastBackUpTaken IS NULL) AND c.name <> 'tempdb'
GROUP BY c.Name, c.type, d.LastBackUpTaken, c.rm, d.type
ORDER BY 1, c.type



Best regards
karl
Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)

Group: General Forum Members
Points: 8702 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search