Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL servers backup report

Posted on 2012-03-10
3
Medium Priority
?
266 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 750 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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