Find out when a database backup was made

2020-07-27 01:55发布

Folks,

Assume you receive a disconnected backup of a SQL Server database (2005 or 2008) and you restore that to your SQL Server instance.

Is there a way, is there a system catalog or something, to find out when the last write operation occured on that particular database? I'd like to be able to find out what day a particular database backup was from - unfortunately, that's not really being recorded explicitly anywhere, and checking all dozens of data table for the highest date/time stamp isn't really an option either....

Any ideas? Sure - I can look at the date/time stamp of the *.bak file - but can I find out more precisely from within SQL Server (Management Studio) ??

Thanks! Marc

4条回答
The star\"
2楼-- · 2020-07-27 02:33

If you have access to the SQL Server instance where the backup was originally run, you should be able to query msdb:

SELECT backup_set_id, backup_start_date, backup_finish_date
FROM  msdb.dbo.backupset  
WHERE database_name = 'MyDBname' AND type = 'D' 

There are several table relating to backup sets:

  • backupfile -- contains one row for each data file or log file backed up
  • backupmediafamily -- contains one row for each media family
  • backupmediaset -- contains one row for each backup media set
  • backupset -- contains one row for each backup set

By querying these tables you can determine when the last backups occurred, what type of backups occurred and where the files were written to.

查看更多
爷、活的狠高调
3楼-- · 2020-07-27 02:37

A bit late, but should be what you want.

Each write to the database is an entry in the log file. Which has an LSN. This must be stored in the backup for log restores at least.

So, how to match LSN to a datetime?

SELECT TOP 5 [End Time] AS BringFirst, *
FROM ::fn_dblog (NULL, NULL)
WHERE [End Time] IS NOT NULL
ORDER BY BringFirst DESC

I've never used this before (just had a play for this answer). Some writes are very likely part of the backup itself, but you should be able to distinguish them with some poking around.

查看更多
Juvenile、少年°
4楼-- · 2020-07-27 02:42

as far as I know in the master database there exists a Log-table where every write is stored with detailed information. BUT I'm unsure if you need to enable the Log-mechanism - so that the default is not to log and you have to enable it. In Oracle for example it is the way around there exists a system-database table Log that you can query.

If that is not the case - you could still write yourself a trigger and apply that on every table/column needed and do the logging yourself.

查看更多
家丑人穷心不美
5楼-- · 2020-07-27 02:46

You can try RESTORE HEADERONLY on your backup file, as described here

that should give you the information you're looking for.

查看更多
登录 后发表回答