Question

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

Was it helpful?

Solution

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

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

OTHER TIPS

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top