Has Your Database Been Backed up in the Last 24 Hours? | Database Journal

Has Your Database Been Backed up in the Last 24 Hours?

Written By
Gregory Larsen
Gregory Larsen
Jan 2, 2018
1 minute read

As a DBA your #1 responsibility is to make sure that each of your SQL Server databases are backed up.  Without recent backups you will not be able to recover your database without potentially losing many days of database updates.  Therefore, you need to make sure on a daily basis that your backups are running and running successfully.  In this tip, I provide a couple of TSQL scripts that will identify the last backup of each database.  By reviewing the output from these scripts, you will be able to identify the last backup for the databases on your instance.

Script #1:  Return the LastBackupDateTime for each database on your Instance

SELECT db.Name AS DatabaseName,
COALESCE(CONVERT(VARCHAR(19), MAX(bs.backup_finish_date), 120),'None') AS LastBackUpDateTime
FROM sys.sysdatabases db
        LEFT OUTER JOIN msdb.dbo.backupset bs 
     ON bs.database_name = db.name
GROUP BY db.Name; 

Script #2: Show the databases that have never had a backup, or the current backup is over 24 hours old

SELECT db.Name AS DatabaseName,
COALESCE(CONVERT(VARCHAR(19), MAX(bs.backup_finish_date), 120),'None') AS LastBackUpTime
FROM sys.sysdatabases db
        LEFT OUTER JOIN msdb.dbo.backupset bs 
     ON bs.database_name = db.name
GROUP BY db.Name
HAVING max(bs.backup_finish_date) < dateadd(dd,-1,getdate())
    or max(bs.backup_finish_date) is NULL;

See all articles by Greg Larsen

Gregory Larsen

Gregory A. Larsen is a DBA at Washington State Department of Health (DOH). Greg is responsible for maintaining SQL Server and other database management software. Greg works with customers and developers to design and implement database changes, and solve database/application related problems. Greg builds homegrown solutions to simplify and streamline common database management tasks, such as capacity management.

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.