Solved

SQL servers backup report

Posted on 2012-03-10
3
223 Views
Last Modified: 2012-03-13
Hi All,

Our Requirement is we need to send SQL Server backup status report to client on weekly basis which should include daily incremental (Mon-Fri) and Full backup (Sat) backup report in the form of csv\excel.

can some one share the tsql script for our requirement or please guide me how to modify below script as per our requirement.

Select @@servername, M.Name, M.crdate, Current_DBSize = Str(Convert(Dec(15),Sum(Size))* 8192/ 1048576,10,2)+ ' MB',
K.Backup_Start_Date, K.Backup_Finish_Date,
CompletionTime =  Cast((Datediff(MI, K.Backup_Start_Date, K.Backup_Finish_Date)/60) As Char(2)) + ' Hr : ' +
Cast((Datediff(MI, K.Backup_Start_Date, K.Backup_Finish_Date) % 60) As Char(2)) + ' Min : ' +
Cast((Datediff(ss, K.Backup_Start_Date, K.Backup_Finish_Date) % 60) As Char(2)) + ' Sec' ,
Backup_Type = Case Upper(K.Type)
      When 'D' Then 'Full Backup'
      When 'I' Then 'Differential'
      When 'L' Then 'Log'
      When 'F' Then 'File Or Filegroup'
      When 'G' Then 'Differential File'
      When 'P' Then 'Partial'
      When 'Q' Then 'Differential Partial'
      End,
K.User_Name
From Sys.SysDatabases M (Nolock)
Inner Join Sys.SysAltFiles SF (Nolock)
      On M.DBId = SF.DBId
Left Outer Join MSDB..BackupSET K (Nolock)
      On M.Name = K.Database_Name And K.Type = 'D'
      And K.Backup_Start_Date >= '2010-01-22 00:00:00:000' --- And K.Backup_Start_Date < '2008-07-15 20:00:00:000'
Where M.Dbid <> 2
Group By M.Name, M.crdate, K.Backup_Start_Date, K.Backup_Finish_Date, K.Type, K.User_Name
Order By M.Name -- K.Backup_Start_Date
0
Comment
Question by:sg05121983
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
jogos earned 250 total points
ID: 37704780
This will be very old backups
  And K.Backup_Start_Date >= '2010-01-22 00:00:00:000' --- And K.Backup_Start_Date < '2008-07-15 20:00:00:000'

so make it  
  And K.Backup_Start_Date >= getdate()-31
To have last 31 days of backup, that is time included

Alse specify an ELSE in your case-structure (Transaction log backups?)
Backup_Type = Case Upper(K.Type)
      When 'D' Then 'Full Backup'
      When 'I' Then 'Differential'
      When 'L' Then 'Log'
      When 'F' Then 'File Or Filegroup'
      When 'G' Then 'Differential File'
      When 'P' Then 'Partial'
      When 'Q' Then 'Differential Partial'
      ELSE K.Type
      End,

And for the rest you must say what's not good with this query
0
 

Author Comment

by:sg05121983
ID: 37706813
Thnaks a lot Jogos for your help :)

I will test above query as per your suggestions and will let you know the results.
0
 

Author Closing Comment

by:sg05121983
ID: 37718420
--
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now