Solved

SQL servers backup report

Posted on 2012-03-10
3
251 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
While in ##Table - Help 4 22
Script to backup a Database Dayli on SQL Server Express 3 23
Need return values from a stored procedure 8 40
denied execute as 13 26
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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