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'
文章来源:http://www.hulian.top,转载请注明!