Query To Find Restore Start End Time
Query To Find Restore Start End Time
Uses MSDB..RestoreHistory table for Start time and ErrorLog for Finish Time
*/
-- Results Table
CREATE TABLE #Restore
(
[database] VARCHAR(50) ,
StartTime DATETIME ,
EndTime DATETIME
)
-- Get start time by looking msdb..restorehistory and selecting the first record
with your db
UPDATE #Restore
SET StartTime = ( SELECT TOP ( 1 )
restore_date
FROM msdb.dbo.restorehistory
WHERE destination_database_name = @databaseName
)
WHERE [database] IS NOT NULL
-- Get end time by loading the errorlog into a temp table and filtering to find the
restore command @errorLog Result
UPDATE #Restore
SET EndTime = ( SELECT TOP ( 1 )
LogDate
FROM #TempLog
WHERE ProcessInfo = 'Backup'
AND [Text] LIKE @errorLogResult
)
WHERE [database] IS NOT NULL
-- Clean up
DROP TABLE #Restore
DROP TABLE #TempLog
DROP TABLE #logF