Solved

SQL servers backup report

Posted on 2012-03-10
3
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Index and Stats Management-Specific tables 8 50
Substring works but need to tweak it 14 35
Database Owner 3 45
Need more granular date groupings 4 45
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
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…

739 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