Restore from the lastest transactional log file lsn

Hi All,

I'm trying to create a restore job which gets the latest transactional log file and it will run daily. I wanted to know if there is any way of writing a script so it captures the lsn number of the transactional log file please?

Thank you in advance!

August 28th, 2015 7:44am

Select redo_start_lsn from sys.master_files where

database_id = db_id('SecondaryDatabaseName') and type = 0

This will give you the LSN of last restored log based on which you could identify the next one. You could also use powershell for this. Please check the link.

http://www.sqlservercentral.com/Forums/Topic1167312-391-1.aspx

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 8:13am

You can query the lsn Information from msdb.dbo.backupset:

select top 10 first_lsn, last_lsn, checkpoint_lsn, database_backup_lsn, *
from msdb.dbo.backupset
where [type] = 'L'
order by backup_set_id desc

August 28th, 2015 8:16am

Thank you for your reply!

I used the sql script but I'm having an issue with the following line:


SELECT

LTRIM(SUBSTRING(Col1,1,20))AS'DateTimeStamp',

LTRIM(SUBSTRING(Col1,71,6))AS'LSN',

LTRIM(SUBSTRING(Col1,21,18))AS'FileSize',

LTRIM(SUBSTRING(Col1,40,1000))AS'FileName1'

FROM

#OriginalFileList


ORDER

BYLSN

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

The statement has been terminated.

Processing File 1/0

Would you please advice?

Thank you!



Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 12:44pm

What is the outputs of LTRIM(SUBSTRING(Col1,1,20))?
August 28th, 2015 2:22pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics