Created
October 17, 2014 09:21
-
-
Save zommarin/9f43d8793af7e988a019 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @dbname sysname, @days int | |
SET @dbname = NULL --substitute for whatever database name you want (or just NULL to list all databases) | |
SET @days = -30 --previous number of days, script will default to 30 | |
SELECT | |
rsh.destination_database_name AS [Database], | |
rsh.user_name AS [Restored By], | |
CASE WHEN rsh.restore_type = 'D' THEN 'Database' | |
WHEN rsh.restore_type = 'F' THEN 'File' | |
WHEN rsh.restore_type = 'G' THEN 'Filegroup' | |
WHEN rsh.restore_type = 'I' THEN 'Differential' | |
WHEN rsh.restore_type = 'L' THEN 'Log' | |
WHEN rsh.restore_type = 'V' THEN 'Verifyonly' | |
WHEN rsh.restore_type = 'R' THEN 'Revert' | |
ELSE rsh.restore_type | |
END AS [Restore Type], | |
rsh.restore_date AS [Restore Started], | |
bmf.physical_device_name AS [Restored From], | |
rf.destination_phys_name AS [Restored To] | |
FROM msdb.dbo.restorehistory rsh | |
INNER JOIN msdb.dbo.backupset bs ON rsh.backup_set_id = bs.backup_set_id | |
INNER JOIN msdb.dbo.restorefile rf ON rsh.restore_history_id = rf.restore_history_id | |
INNER JOIN msdb.dbo.backupmediafamily bmf ON bmf.media_set_id = bs.media_set_id | |
WHERE rsh.restore_date >= DATEADD(dd, ISNULL(@days, -30), GETDATE()) --want to search for previous days | |
AND destination_database_name = ISNULL(@dbname, destination_database_name) --if no dbname, then return all | |
ORDER BY rsh.destination_database_name, rsh.restore_date DESC | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment