Check Backups

  • Comments posted to this topic are about the item Check Backups

  • Hi,

    I would really appreciate if you could write a code which will get results from all the servers through linked servers, and could mail the DBA's with a really nice html formatted report.

    Regards,

    Faisal

  • A set-based, non-loopy way of doing a similar thing:

    SELECT

    DB_NAME(d.database_id)'DB',

    ISNULL

    ('Backed up '+CAST(DATEDIFF(day,b.backup_start_date,GETDATE()) as varchar(10))+' days ago.',

    'Never been backed up!'

    )'Backup Info'

    FROM sys.databases d

    LEFT JOIN

    (SELECT database_name,MAX(backup_start_date)'backup_start_date'

    FROM msdb.dbo.backupset

    GROUP BY database_name

    )b ON b.database_name=DB_NAME(d.database_id)

    WHERE DB_NAME(d.database_id)<>'tempdb'

    ORDER BY 2 DESC, 1

  • It's a good idea to check that the server_name column of msdb.dbo.backupset matches the server you are checking.

    When you do a restore, if the backup set being restored isn't already in msdb.dbo.backupset, an entry will be created for it. This will be constructed based on the backup file's header and will have the name of the server and database that was actually backed up and the backup date. There will be a restorehistory record that references this backupset record, and will reflect the database that was restored to (possibly with a different name) and the restore date.

    There are also some GUIDs and LSNs in a table called master.sys.database_recovery_status which can be compared with msdb.dbo.backupset to check if a backup set actually corresponds with the current database with the same name. Look in BOL under "Recovery Forks" for an explanation of what these mean.

    If you do a restore, you typically should do a full backup right away. However, without some of this additional checking in msdb.dbo.backupset queries, it's easy to mistake the restore for a backup.

    David Lathrop
    DBA
    WA Dept of Health

  • Thank you for your script.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply