views:

21

answers:

1

Through SINGLE T-sql query can we find : 1. Database Backup mode - [full,simple,bulk] 2. IS database is scheduled for backup [yes, no] 3. If backup is enabled the size of the DB backup

and Daily transaction log backup size ? any help

+2  A: 

You can query the msdb backupset table for this kind of information:

SELECT 
    database_name,
    recovery_model, 
    CASE bs.type 
        WHEN 'D' THEN 'FULL'
        WHEN 'I' THEN 'DIFFERENTIAL'
        WHEN 'L' THEN 'TRANSACTION LOG'
        ELSE 'UNKNOWN'
    END AS backup_type, 
    backup_finish_date,
    backup_size,
    compressed_backup_size
FROM msdb.dbo.backupset bs

EDIT:

This query will return the database name, recovery model, and the last datetime for full, differential, and log backups. If a database returns NULL for the last FULL it is not being backed up at all. If it returns NULL for the last transaction log and the database uses FULL recovery it is not being backed up correctly.

SELECT  
    d.name, 
    d.recovery_model_desc,
    MAX(CASE bs.type WHEN 'D' THEN backup_finish_date ELSE NULL END) AS [last_full_backup_date],
    MAX(CASE bs.type WHEN 'I' THEN backup_finish_date ELSE NULL END) AS [last_diff_backup_date],
    MAX(CASE bs.type WHEN 'L' THEN backup_finish_date ELSE NULL END) AS [last_tlog_backup_date]
FROM sys.databases d
LEFT JOIN msdb.dbo.backupset bs ON bs.database_name = d.name
GROUP BY d.name, d.recovery_model_desc
Jonathan Kehayias
Thank you Jonathan, but how can i get IS my Backup mode database is in Scheduled or not bcoz i have 20 serves with 130 databases. need to find backupmode database which is in scheduled mode.
Dhiva
It all depends on how you do backups. Do you use Maintenance Plans, custom TSQL scripts, third party tools? You could change the query to work off sys.databases and find the last backup dates for the databases as shown above in the Edit I provided. This at least gives you information about whether they are being backed up. Whether they are scheduled at all or not depends on how you actually are performing backups, but if it wasn't scheduled, it wouldn't have a recent backup date in the query results.
Jonathan Kehayias