Skip to content

Instantly share code, notes, and snippets.

@yngwie74
Created August 17, 2012 17:40
Show Gist options
  • Save yngwie74/3380899 to your computer and use it in GitHub Desktop.
Save yngwie74/3380899 to your computer and use it in GitHub Desktop.
Determinar cuando se hizo un "RESTORE" a un BD por última vez en SQL Server
SELECT rsh.destination_database_name AS [Database]
,rsh.user_name AS [Restaurado por]
,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 [Tipo]
,rsh.restore_date AS [Fecha]
,bmf.physical_device_name AS [Origen]
,rf.destination_phys_name AS [Destino]
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(month, -6, GETDATE())
-- agregar si solo se quiere una base, quitar para todas
-- AND destination_database_name = 'OKW'
ORDER BY rsh.destination_database_name DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment