++++++++++++++++++++
Select Destination_database_name,
restore_date,
database_name as Source_database,
Physical_device_name as Backup_file_used_to_restore,
bs.user_name,
bs.machine_name
from msdb.dbo.restorehistory rh
inner join msdb.dbo.backupset bs
on rh.backup_set_id=bs.backup_set_id
inner join msdb.dbo.backupmediafamily bmf
on bs.media_set_id =bmf.media_set_id
ORDER BY [rh].[restore_date] DESC
USE msdb ;
SELECT
DISTINCT
DBRestored = destination_database_name ,
RestoreDate = restore_date ,
SourceDB = b.database_name ,
BackupDate = backup_start_date
FROM RestoreHistory h
JOIN MASTER..sysdatabases sd ON sd.name = h.destination_database_name
INNER JOIN BackupSet b ON h.backup_set_id = b.backup_set_id
INNER JOIN BackupFile f ON f.backup_set_id = b.backup_set_id
GROUP BY destination_database_name ,
restore_date ,
b.database_name ,
backup_start_date
ORDER BY RestoreDate DESC
GO
_________________________________________________________________________________
WITH LastRestores AS
(
SELECT
DatabaseName = [d].[name] ,
[d].[create_date] ,
[d].[compatibility_level] ,
[d].[collation_name] ,
r.*,
RowNum = ROW_NUMBER() OVER (PARTITION BY d.Name ORDER BY r.[restore_date] DESC)
FROM master.sys.databases d
LEFT OUTER JOIN msdb.dbo.[restorehistory] r ON r.[destination_database_name] = d.Name
)
SELECT *
FROM [LastRestores]
WHERE [RowNum] = 1
No comments:
Post a Comment