Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 How to get last backup dates

Author  Topic 

vijays3
Constraint Violating Yak Guru

354 Posts

Posted - 2010-04-27 : 04:39:24
Hi

I need to create a which could generate the
following details
servername
dbname
recoverymode
compatibility
location of data file
location of log file
last date of full backup
last date of diff. backup
last date of tran backup

These are the columns in my table
i have have two scripts which are written seperately

1..SELECT DBname=name
,Status= convert(sysname,DatabasePropertyEx(name,'Status'))
, Updateability= convert(sysname,DatabasePropertyEx(name,'Updateability'))
, UserAccess= convert(sysname,DatabasePropertyEx(name,'UserAccess'))
, Recovery= convert(sysname,DatabasePropertyEx(name,'Recovery'))
,Version= convert(sysname,DatabasePropertyEx(name,'Version'))
from sysdatabases

This above script can get the half part of the requirement


2 .


select 'Databases and backups on server ' + @@servername
select SUBSTRING(s.name,1,40) AS 'Database',
CAST(b.backup_start_date AS char(11)) AS 'Backup Date ',
CASE WHEN b.backup_start_date > DATEADD(dd,-1,getdate())
THEN 'Backup is current within a day'
WHEN b.backup_start_date > DATEADD(dd,-7,getdate())
THEN 'Backup is current within a week'
ELSE '*****CHECK BACKUP!!!*****'
END
AS 'Comment'

from master..sysdatabases s
LEFT OUTER JOIN msdb..backupset b
ON s.name = b.database_name
AND b.backup_start_date = (SELECT MAX(backup_start_date)
FROM msdb..backupset
WHERE database_name = b.database_name
AND type = 'D') -- full database backups only, not log backups
WHERE s.name <> 'tempdb'

ORDER BY s.name


and this can get the remaining information..

I am not being able to merge this two..could any please help me on thsi

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-27 : 04:46:59
[code]
select 'Databases and backups on server ' + @@servername
select SUBSTRING(s.name,1,40) AS 'Database'
,Status= convert(sysname,DatabasePropertyEx(s.name,'Status'))
, Updateability= convert(sysname,DatabasePropertyEx(s.name,'Updateability'))
, UserAccess= convert(sysname,DatabasePropertyEx(s.name,'UserAccess'))
, Recovery= convert(sysname,DatabasePropertyEx(s.name,'Recovery'))
,Version= convert(sysname,DatabasePropertyEx(s.name,'Version'))

,CAST(b.backup_start_date AS char(11)) AS 'Backup Date ',
CASE WHEN b.backup_start_date > DATEADD(dd,-1,getdate())
THEN 'Backup is current within a day'
WHEN b.backup_start_date > DATEADD(dd,-7,getdate())
THEN 'Backup is current within a week'
ELSE '*****CHECK BACKUP!!!*****'
END
AS 'Comment'

from master..sysdatabases s
LEFT OUTER JOIN msdb..backupset b
ON s.name = b.database_name
AND b.backup_start_date = (SELECT MAX(backup_start_date)
FROM msdb..backupset
WHERE database_name = b.database_name
AND type = 'D') -- full database backups only, not log backups
WHERE s.name <> 'tempdb'

ORDER BY s.name

[/code]


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

vijays3
Constraint Violating Yak Guru

354 Posts

Posted - 2010-04-27 : 04:56:58
some more question
1.
Thanks for your quick response ...but i tried to add compatibility
column but for it all values are coming null although it should show
80,90.
2.
How can we get the last diff backup date and trans backup date as well

3.
will this query work on all the version of sql?


quote:
Originally posted by webfred


select 'Databases and backups on server ' + @@servername
select SUBSTRING(s.name,1,40) AS 'Database'
,Status= convert(sysname,DatabasePropertyEx(s.name,'Status'))
, Updateability= convert(sysname,DatabasePropertyEx(s.name,'Updateability'))
, UserAccess= convert(sysname,DatabasePropertyEx(s.name,'UserAccess'))
, Recovery= convert(sysname,DatabasePropertyEx(s.name,'Recovery'))
,Version= convert(sysname,DatabasePropertyEx(s.name,'Version'))

,CAST(b.backup_start_date AS char(11)) AS 'Backup Date ',
CASE WHEN b.backup_start_date > DATEADD(dd,-1,getdate())
THEN 'Backup is current within a day'
WHEN b.backup_start_date > DATEADD(dd,-7,getdate())
THEN 'Backup is current within a week'
ELSE '*****CHECK BACKUP!!!*****'
END
AS 'Comment'

from master..sysdatabases s
LEFT OUTER JOIN msdb..backupset b
ON s.name = b.database_name
AND b.backup_start_date = (SELECT MAX(backup_start_date)
FROM msdb..backupset
WHERE database_name = b.database_name
AND type = 'D') -- full database backups only, not log backups
WHERE s.name <> 'tempdb'

ORDER BY s.name




No, you're never too old to Yak'n'Roll if you're too young to die.

Go to Top of Page
   

- Advertisement -