SQL Server在msdb數據中維護了一系列表,用來存儲執行所有備份和還原的細節信息。即使你正在使用第三方的備份應用程序,只要這個應用程序使用SQL Server的虛擬設備接口(Virtual Device Interface---VDI)來執行備份和還原執行,那麼執行細節依然被存儲在這一系列表中。
存儲細節的表包括:
backupset
backupfile
backupfilegroup (SQL Server 2005 upwards)
backupmediaset
backupmediafamily
restorehistory
restorefile
restorefilegroup
logmarkhistory
suspect_pages (SQL Server 2005 upwards)
你可以在Books Online裡面找到上面這些表的具體說明。
下面這個腳本可以幫你找出每個數據庫近期的備份信息:
SELECT b.name, a.type, MAX(a.backup_finish_date) lastbackup
FROM msdb..backupset a
INNER JOIN master..sysdatabases b ON a.database_name COLLATE DATABASE_DEFAULT = b.name COLLATE DATABASE_DEFAULT
GROUP BY b.name, a.type
ORDER BY b.name, a.type
指定數據庫最後20條事務日志備份信息:
SELECT TOP 20 b.physical_device_name, a.backup_start_date, a.first_lsn, a.user_name FROM msdb..backupset a
INNER JOIN msdb..backupmediafamily b ON a.media_set_id = b.media_set_id
WHERE a.type = 'L'
ORDER BY a.backup_finish_date DESC
指定時間段的事務日志備份信息:
SELECT b.physical_device_name, a.backup_set_id, b.family_sequence_number, a.position, a.backup_start_date, a.backup_finish_date
FROM msdb..backupset a
INNER JOIN msdb..backupmediafamily b ON a.media_set_id = b.media_set_id
WHERE a.database_name = 'AdventureWorks'
AND a.type = 'L'
AND a.backup_start_date > '10-Jan-2007'
AND a.backup_finish_date < '16-Jan-2009 3:30'
ORDER BY a.backup_start_date, b.family_sequence_number
刪除備份日志的兩個存儲過程:
EXEC msdb..sp_delete_backuphistory '1-Jan-2005'
EXEC msdb..sp_delete_database_backuphistory 'AdventureWorks'