DBA Scripts: Get Recovery Model Audit

🔧Part of the DBA-Tools Project, copy/paste SQL Server scripts and health checks.In: Backup & Recovery

The Mismatch That Fills a Disk

A database’s recovery model is a promise about what kind of restore is possible, FULL and BULK_LOGGED promise point-in-time recovery, backed by log backups; SIMPLE promises none, and truncates the log on its own. The incident happens when reality doesn’t match the promise: a FULL-recovery database with no log backup job behind it runs fine for months, quietly growing its log, until the drive fills and the database goes down.

This script checks every online database’s recovery model against its actual backup history and flags exactly that mismatch, along with the other common gaps, no full backup to anchor a chain, stale backups, before they become an incident.


Why Recovery Model Audit Matters

  • The “accidental FULL” database is one of the most common silent failures in SQL Server, someone switches recovery model for a one-off requirement, or it was set that way at creation, and no one ever adds a matching log backup job
  • FULL and BULK_LOGGED recovery only truncate the log on a log backup, not a full backup, so a database can be “backed up every night” and still have an ever-growing log
  • A database with no full backup at all can’t have a log backup chain either, log backups are worthless without a full backup to restore from first
  • This is a 5-minute check that catches a problem which otherwise surfaces as a 2am page when a drive fills

When to Run This Script

  • Routine SQL Server health checks
  • Any time a database’s recovery model is changed
  • After provisioning a new database or restoring one from another environment
  • Alongside Log Reuse Waits when a log is already growing, to see the backup-posture reason behind it

The Script

Run the following script against your SQL Server instance.

✓ Verified
  • Tested on: SQL Server 2025 (RTM CU8), Windows lab instance
  • Last verified: 2026-08-30 (the script on this page runs, saved output from a real run)
  • Permissions: VIEW ANY DATABASE, db_datareader on msdb
  • Safety: read-only, impact low
/*
Script Name : Get-RecoveryModelAudit
Category    : backups-and-recovery
Purpose     : Audits each database's recovery model against its actual backup posture and
              flags the mismatches that cause real incidents: FULL/BULK_LOGGED databases
              with no log backups (the log grows until the disk fills), databases with no
              full backup to anchor a log chain, and SIMPLE databases where someone may be
              expecting point-in-time recovery they do not have.
Author      : Peter Whyte (https://sqldba.blog/dba-scripts-get-recovery-model-audit/)
Requires    : VIEW ANY DATABASE, db_datareader on msdb
Notes       : "Accidental FULL" is the classic finding — a database left in FULL recovery
              with no log backup job. It runs fine for months, then the log fills the drive.
              Run Get-LogReuseWaits and Get-TransactionLogSizeAndUsage alongside this to see
              the live effect. Thresholds below are defaults; adjust to your backup SLA.

              WHERE THIS GOES BLIND. Every date here comes from msdb.dbo.backupset on THIS
              instance, so a CRITICAL is evidence of missing local history, which is usually
              but not always a missing backup job. Confirm against one of these before
              raising it:
                - Availability Groups: backup history is instance-local. Backups taken on
                  another replica leave no row here.
                - Purged history: sp_delete_backuphistory or a maintenance-plan cleanup task
                  trims backupset, so a young instance-restart or an aggressive retention
                  setting can empty this out.
                - Snapshot backups that bypass the SQL backup path: VM or storage-array
                  snapshots taken without VSS/VDI integration never write a backupset row.
                  (Most third-party tools — Veeam application-aware, Commvault, LiteSpeed,
                  Redgate — go through VDI and DO appear here.)
                - Renamed databases: backupset records the name at backup time, so history
                  stays behind under the old name and the database reads as never backed up.
*/
-- SAFE:ReadOnly
-- IMPACT:Low
SET NOCOUNT ON;

DECLARE @LogBackupStaleHours INT = 24;
DECLARE @FullBackupStaleDays INT = 7;

;WITH FullBackup AS
(
    /* Copy-only fulls are deliberately COUNTED here. A copy-only full backup is a valid
       restore base and log backups can be applied on top of it, so it genuinely does let
       a log chain start. (What it does not do is reset the differential base, which is a
       different question this script does not ask.) Filtering it out here would raise a
       false CRITICAL against a database that is in fact restorable. */
    SELECT database_name, MAX(backup_finish_date) AS last_full_backup
    FROM msdb.dbo.backupset
    WHERE type = 'D'
    GROUP BY database_name
),
LogBackup AS
(
    /* Copy-only log backups are EXCLUDED, and this one matters. A copy-only log backup
       preserves the log archive point and does not truncate the log, so counting it as
       evidence the log is being managed inverts the finding this script exists to make:
       one copy-only log backup would downgrade a genuine "log will grow until the disk
       fills" CRITICAL to a mild staleness warning while the log kept growing. */
    SELECT database_name, MAX(backup_finish_date) AS last_log_backup
    FROM msdb.dbo.backupset
    WHERE type = 'L'
      AND is_copy_only = 0
    GROUP BY database_name
)

SELECT
    d.name AS database_name,
    d.recovery_model_desc AS recovery_model,
    fb.last_full_backup,
    lb.last_log_backup,
    CAST(SUM(CAST(mf.size AS BIGINT)) * 8.0 / 1024
        AS DECIMAL(18,1)) AS log_size_mb,
    CASE
        -- FULL / BULK_LOGGED: the log only truncates when a log backup runs.
        WHEN d.recovery_model_desc IN ('FULL', 'BULK_LOGGED') AND fb.last_full_backup IS NULL
            THEN 'CRITICAL: no full backup, log backup chain cannot start'
        WHEN d.recovery_model_desc IN ('FULL', 'BULK_LOGGED') AND lb.last_log_backup IS NULL
            THEN 'CRITICAL: ' + d.recovery_model_desc + ' recovery with no log backups, log will grow until the disk fills'
        WHEN d.recovery_model_desc IN ('FULL', 'BULK_LOGGED')
             AND DATEDIFF(HOUR, lb.last_log_backup, GETDATE()) > @LogBackupStaleHours
            THEN 'WARNING: log backups are stale (>' + CAST(@LogBackupStaleHours AS VARCHAR(10)) + 'h)'
        WHEN fb.last_full_backup IS NULL
            THEN 'WARNING: no full backup on record'
        WHEN DATEDIFF(DAY, fb.last_full_backup, GETDATE()) > @FullBackupStaleDays
            THEN 'WARNING: full backup is stale (>' + CAST(@FullBackupStaleDays AS VARCHAR(10)) + 'd)'
        WHEN d.recovery_model_desc = 'SIMPLE'
            THEN 'INFO: SIMPLE - no point-in-time recovery between full/diff backups'
        ELSE 'OK'
    END AS finding
FROM sys.databases AS d
JOIN sys.master_files AS mf
    ON mf.database_id = d.database_id
    AND mf.type_desc = 'LOG'
LEFT JOIN FullBackup AS fb
    ON fb.database_name = d.name
LEFT JOIN LogBackup AS lb
    ON lb.database_name = d.name
WHERE d.state_desc = 'ONLINE'
  AND d.database_id > 4
GROUP BY
    d.name,
    d.recovery_model_desc,
    fb.last_full_backup,
    lb.last_log_backup
ORDER BY
    CASE
        WHEN d.recovery_model_desc IN ('FULL', 'BULK_LOGGED') AND lb.last_log_backup IS NULL THEN 0
        WHEN fb.last_full_backup IS NULL THEN 1
        ELSE 2
    END,
    d.name;

The finding column ranks CRITICAL mismatches first, so the databases that need attention today sort straight to the top.


How To Run From The Repo

Clone DBA Tools, initialize and run the script:

# Clone dba-tools repo:
git clone https://github.com/peterwhyte-lgtm/dba-tools

# Initialize environment:
cd dba-tools
.\Initialize-Environment.ps1

# Audit every database's recovery model against its actual backup posture:
.\run.ps1 Get-RecoveryModelAudit

# To run against a remote sql server:
.\run.ps1 Get-RecoveryModelAudit -ServerInstance SQLSERVER01

This script lives in the repo at:


Example Output

Run against a lab instance.

SSMS showing the Get-RecoveryModelAudit script and its results grid. Seven databases are listed. The top row, in FULL recovery, has a full backup taken that day, NULL for its last log backup and a 520 MB log, and reads CRITICAL: FULL recovery with no log backups, log will grow until the disk fills. The six rows below it read WARNING: log backups are stale, over 24 hours.

The top row is the one that matters. It is in FULL recovery, it has a full backup from that morning, and it has never had a log backup, so its log grows until the disk fills. It is also the row that looks fine on a backup report. The other 6 have a log backup chain that stopped running, which is why they read as stale rather than critical.


Understanding the Results

CRITICAL: no full backup,
log backup chain cannot start
The database has no full backup on record at all. Log backups cannot help until a full backup exists to anchor them, so there is nothing to restore from and nothing to chain to. Act when always. Take a full backup before anything else on this list.
CRITICAL: FULL recovery with no
log backups, log will grow
until the disk fills
The classic accidental FULL. A recent full backup, a healthy-looking database, and zero log backups ever taken. Full backups do not truncate the log under FULL or BULK_LOGGED recovery, so the log grows without bound. Act when always, and today. This is the finding that takes an instance down when the drive fills, and it gives no warning until it does.
WARNING: log backups are stale
Log backups exist, so the chain started, but nothing has run inside the threshold. The job is disabled, failing, or was never rescheduled after a change. Act when the gap is longer than your recovery point objective. A chain that stopped last week means a week of transactions you cannot restore to.
WARNING: full backup is stale
The full backup side is ageing out rather than the log side. Check the backup job before reading anything else on the row.
INFO: SIMPLE
Not a failure by itself. It is only a problem when someone on the team believes that database has point-in-time recovery, which happens more often than it should. Act when the database holds anything you would be asked to restore to a moment in time.
last_log_backup
last_full_backup
The newest backup of each type from msdb.dbo.backupset. A SIMPLE database can still show an old last_log_backup date, left behind from when it was FULL. That date is history, not an active log chain, and it is a common misread.
log_size_mb
The allocated size of the log files, not how much of that is in use. It is the right number for judging what the accidental-FULL case has already cost on disk, and the wrong one for judging how full the log is right now. Use Transaction Log Size and Usage for the live figure.

Where This Check Goes Blind

Every date here comes from msdb.dbo.backupset on the instance you ran it against. A CRITICAL is therefore evidence of missing local history, which is usually a missing backup job but is not always. Rule these out before raising it:

  • Availability Groups. Backup history is instance-local. Backups taken on another replica leave no row on this one.
  • Purged history. sp_delete_backuphistory, or the cleanup task in a maintenance plan, trims backupset on a retention schedule.
  • Snapshot backups that bypass SQL Server. VM or storage-array snapshots taken without VSS or VDI integration never write a row. Most third-party tools do go through VDI and do appear here, so this is narrower than it is usually assumed to be.
  • Renamed databases. backupset records the name as it was at backup time, so the history stays behind under the old name and the database reads as never backed up.
TipCopy-only backups are filtered out of the log side of this check on purpose. A copy-only log backup preserves the log archive point and does not truncate the log, so counting one would quietly downgrade a genuine “log will grow until the disk fills” finding to a mild staleness warning while the log carried on growing. Copy-only full backups are deliberately still counted, because a copy-only full is a valid restore base that a log chain can start from.

How to Fix Recovery Model Mismatches

For a FULL/BULK_LOGGED database with no log backups, the fix is either operational or a deliberate recovery model change, not both left unresolved:

-- Option 1: add a proper log backup job (the usual fix if point-in-time recovery is needed)
BACKUP LOG [YourDatabase] TO DISK = 'D:\Backups\YourDatabase_log.trn';
-- then schedule this on the interval your recovery-point objective requires

-- Option 2: if point-in-time recovery was never actually needed, switch to SIMPLE
ALTER DATABASE [YourDatabase] SET RECOVERY SIMPLE;
-- take a full backup immediately after, the old log backup chain is now broken

For a database with no full backup at all, take one before anything else, log backups can’t help until a full backup exists to anchor them.


Best Practices

  • Treat any CRITICAL finding as something to fix today, not a backlog item, an unbounded growing log eventually takes the whole instance down when the drive fills
  • Every FULL or BULK_LOGGED database needs a log backup job as a matter of course when it’s created, not added later once someone notices the log is huge
  • Re-run this audit after any recovery model change or new database provisioning, not just on a schedule

Microsoft’s reference covers sys.databases and sys.master_files in full.


Frequently Asked Questions

Why does a database with recent full backups still show a CRITICAL finding?

Because full backups don’t truncate the transaction log for FULL or BULK_LOGGED recovery, only a log backup does. A database can look well-backed-up on the full backup side and still have an unbounded growing log with zero log backups behind it.

Should every database just use SIMPLE recovery to avoid this?

No, SIMPLE means no point-in-time recovery between full/diff backups, only restore to the last backup taken. That’s a real tradeoff for production databases where losing hours of transactions is unacceptable. The right fix for a FULL-recovery database missing log backups is almost always to add the missing log backup job, not to downgrade the recovery model.


Summary

Recovery model and backup posture have to agree with each other, and the gap between them is exactly what causes the “the log filled the drive” incident that always seems to come out of nowhere. It doesn’t come out of nowhere, it’s been growing since the day the mismatch started.

Run this audit as part of routine health checks, and immediately after any recovery model change or new database provisioning, so a CRITICAL finding gets caught the same week it starts, not the week the disk runs out.


Related Scripts

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *