SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


check full recovery dbs have tran log backups


check full recovery dbs have tran log backups

Author
Message
paul_richardson
paul_richardson
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1586 Visits: 215
Comments posted to this topic are about the item check full recovery dbs have tran log backups
stephen.griffiths
stephen.griffiths
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 80
a nifty little script, I installed the SP on a couple of boxes and straightaway found some little databases no-one cared about enough to monitor that were on 'full recovery' but had no tran-log backups setup.
paul_richardson
paul_richardson
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1586 Visits: 215
Hi,
that's exactly why i wrote it, people often forget to remove full recovery mode when they copy from a production environment, so it has caused me issues in the past.

Thanks

Paul
stuart.adair
stuart.adair
SSC Veteran
SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)

Group: General Forum Members
Points: 289 Visits: 206
/*
Why are you using temp table and using subquery? A subquery is not as efficient as a join or a derived table or an exists. The latter being the most optimal. This would have been far more efficient in typing and execution.

You have allocated a data type varchar(50) for the database name when this should have been syname or nvarchar(128) as per the system tables that you are refering to. This would fail for database with a name > 50 characters

I would like to have had the date of the last backup if I'm checking.
*/

DECLARE
@num_of_days int

SELECT @num_of_days = 7

SELECT
a.[name]
,b.DateLogLastBackedUp
,CASE
WHEN b.DateLogLastBackedUp IS NULL THEN 1
ELSE 0
END AS TransactionLogNeverBackedUpIndicator
FROM
master.dbo.sysdatabases a
LEFT JOIN
( -- gets the latest available transaction log backup if exists
SELECT
database_name
,MAX(backup_start_date) AS DateLogLastBackedUp
FROM
msdb.dbo.backupset
WHERE
type = 'L' -- Log backups only
AND
DATEDIFF(dd,backup_start_date,GETDATE()) > @num_of_days
GROUP BY
database_name
) b ON a.[name] = b.DateLogLastBackedUp
WHERE
DATABASEPROPERTYEX(a.[name],'Recovery') = 'FULL'
DavePeck
DavePeck
SSC Rookie
SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)

Group: General Forum Members
Points: 33 Visits: 1070
The LEFT JOIN for the derived table in the example from stuart.adair should be on b.database_name (not b.DateLogLastBackedUp):

) b ON a.[name] = b.database_name



Iwas Bornready
Iwas Bornready
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21762 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