How to generate the script to restore transaction log backup?

  • Suppose I need to restore 20 transaction log backup file. I copied 20 files in D: \BackupFiles\. How to generate below script?

    RESTORE LOG NewDatabase

    FROM DISK = ''D: \BackupFiles\TestDatabase_TransactionLogBackup1.trn'

    WITH NORECOVERY

    .

    .

    .

    .

    RESTORE LOG NewDatabase

    FROM DISK = ''D: \BackupFiles\TestDatabase_TransactionLogBackup20.trn'

    WITH RECOVERY

    Thanks

  • You will have to add the scripting piece inline with the physical_device_name but shouldn't be too much work to get the syntax selected out;

    selectbmf.physical_device_name

    frombackupset bs join backupmediafamily bmf

    on bs.media_set_id = bmf.media_set_id

    wherebs.backup_start_date > getdate()-30

    and physical_device_name like '%TestDatabase%'

    and bs.type = 'L'

    order by bs.backup_finish_date

    ...and you will need to change the date parameter to just get the ones you are looking for.

    David

    @SQLTentmaker

    “He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot

  • There are lots of scripts on the site here. You might try searching for "restore log"

    Here's one: http://qa.sqlservercentral.com/scripts/T-Log/69750/

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply