SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Which Databases are Being Backed Up - Another Look

By Santveer Singh, 2004/06/09

Total article views: 7455 | Views in the last 30 days: 29

I was reading the article Every DBA Should Know Which Databases are be Backed Up by Leo Peysakhovich. I agree with Leo, that most of the time when we need a backup of database, we noticed that we don't have backup of that database or we have a very old set of backups. To avoid this kind of situation, I have written a view based on system tables which allows me to know when the last time a database was backed up and which database have never been backed up.

Step 1: create  a view in master or any user database using below script.

Create View Last_Backup
as
Select a.name,Backup_Date from master.dbo.sysdatabases a
	left join 
            (select database_name,cmax(backup_finish_date) backup_date
            from msdb.dbo.backupset where backup_finish_date <= getdate()
            group by database_name)  B
	on  a.name = b.database_name
go

Step 2.1: Once this view is ready, to know when databases are last time backed up

Select * from Last_Backup order by 2 desc, 1

Name                               backup_date
-------------------                ---------------------------
SBD_EMIS_VIEWS                     2004-05-25 02:03:11.000  
PILOT_VIEWS                        2004-05-25 02:02:54.000  
PILOT_USER                         2004-05-25 2:02:53.000   
PILOT_SYSTEM                       2004-05-25 02:02:50.000 
PILOT_DATA_FRAME                   2004-05-25 02:02:46.000

Above result shows when database was last backed up.

Step 2.2: To know the databases that were never backed up

Select * from Last_Backup       where backup_date is null

Name                                 backup_date
-------------------                  --------------------------
CG_EMSP                              NULL
CG_FMO_ARCHIVE                       NULL  

Above result shows that two databases were never backed up.

Step 3: Add these missing databases into appropriate backup maintenance plan.

Step 4: We can schedule a job to send email on daily basis to know the backup status of all databases. Attached is the script for the same.

Conclusion

By spending few minutes to know which database was not backed up and update backup plan on regular basis, we can save data & our life.

By Santveer Singh, 2004/06/09

Total article views: 7455 | Views in the last 30 days: 29
Your response
 
 
Related tags
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com