Get Backup History informations

Hi all,

Need T-SQL code that extracts the following information from the MSSQL 2000 & 2005 backup history tables within the msdb databases:
1. Backup job name: example FULL_BKUP or Shrink databases
2. Start time
3. End time
4. Results of the backup job (failed, sucess)

its urgent, can anyone help me
mahboobAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
You have a lot of information about backups in BackupSet table in MSDB database. Just check it and see what information you want to extract from there:

USE msdb
GO

SELECT * FROM backupset
0
brejkCommented:
You seem to be looking for jobs history rather than backup history, so...

SELECT j.[name], j.description, h.run_date, h.run_time, h.run_duration, h.run_status
FROM msdb.dbo.sysjobs j
INNER JOIN msdb.dbo.sysjobhistory h
ON j.job_id = h.job_id

Legend: run_date is the date of start, run_time is a time of start, run_duration is duration in HHMMSS format, run_status returns 0 if the job failed and 1 if it succeeded.
0
mahboobAuthor Commented:
i want t-sql command, with them we display the informations
0
dbaSQLCommented:
try something like this:

create procedure usp_BackupDetails
as

SET NOCOUNT ON
SELECT Database_Name,
    CONVERT( SmallDateTime , MAX(Backup_Finish_Date)) as Last_Backup,
    DATEDIFF(d, MAX(Backup_Finish_Date), Getdate()) as Days_Since_Last
FROM MSDB.dbo.BackupSet
WHERE Type = 'd'
GROUP BY Database_Name
ORDER BY 3 DESC

-- Find the backup of Transaction Log files
SELECT Database_Name,
    CONVERT( SmallDateTime , MAX(Backup_Finish_Date)) as Last_Backup,
    DATEDIFF(d, MAX(Backup_Finish_Date), Getdate()) as Days_Since_Last
FROM MSDB.dbo.BackupSet
WHERE Type = 'l'
GROUP BY Database_Name
ORDER BY 3 DESC



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.