Dela via


How to: Restore a Transaction Log Backup (SQL Server Management Studio)

Note

The normal process of a restore is to select the log backups in the Restore Database dialog box along with the data and differential backups.

Backups must be restored in the order in which they were created. Before you can restore a particular transaction log backup, you must first restore the following previous backups without rolling back uncommitted transactions, that is WITH NORECOVERY:

  • The full database backup and the last differential backup, if any, taken before the particular transaction log backup.

  • All transaction log backups taken after the full database backup or the differential backup (if you restore one) and before the particular transaction log backup.

    Note

    Restore the previous backups using the following Recovery state option: Leave the database non-operational, and do not roll back the uncommitted transactions. Additional transaction logs can be restored. (RESTORE WITH NORECOVERY)

    For information about using transaction log backups, see Working with Transaction Log Backups.

To restore a transaction log backup

  1. After connecting to the appropriate instance of the Microsoft SQL Server Database Engine, in Object Explorer, click the server name to expand the server tree.

  2. Expand Databases, and, depending on the database, either select a user database or expand System Databases and select a system database.

  3. Right-click the database, point to Tasks, and then click Restore.

  4. Click Transaction Log, which opens the Restore Transaction Log dialog box.

  5. On the General page, in the Database list box, select or type the name of a database. Only databases in the restoring state are listed.

  6. To specify the source and location of the backup sets to restore, click one of the following options:

    • From previous backups of database

      Select the name of the database whose log backups you want to restore.

    • From file or tape

      Click the browse button to select one or more files or tapes as the source for the transaction log backups.

      Selecting a file or tape opens the Specify Backup dialog box. In the Backup media list box, select one of the listed device types. To select one or more devices for the Backup location list box, click Add. After adding the devices you want to the list box, click OK to return to the General page.

  7. In the Select the backup sets to restore grid, select the backups to restore. This grid lists the transaction log backups available for the selected database. A log backup is available only if its First LSN is greater than the Last LSN of the database. Log backups are listed in the order of the log sequence numbers (LSN) they contain, and they must be restored in this order.

    The following table lists the column headers of the grid and describes their values.

    Header

    Value

    Restore

    Selected check boxes indicate the backup sets to be restored.

    Backup Set Name

    Name of the backup set.

    Backup Component

    Backed-up component: Database, File, or <blank> (for transaction logs).

    Backup Type

    Type of backup performed: Full, Differential, or Transaction Log.

    Server Name

    Name of the Database Engine instance that performed the backup operation.

    Database

    Name of the database involved in the backup operation.

    Position

    Position of the backup set in the volume.

    First LSN

    Log sequence number of the first transaction in the backup set. Blank for file backups.

    Last LSN

    Log sequence number of the last transaction in the backup set. Blank for file backups.

    Checkpoint LSN

    Log sequence number of the most recent checkpoint at the time the backup was created.

    Full LSN

    Log sequence number of the most recent full database backup.

    Start Date

    Date and time when the backup operation began, presented in the regional setting of the client.

    Finish Date

    Date and time when the backup operation finished, presented in the regional setting of the client.

    Size

    Size of the backup set in bytes.

    User Name

    Name of the user who performed the backup operation.

    Expiration

    Date and time the backup set expires.

  8. Select one of the following:

    • Point in time

      Either retain the default (Most recent possible) or select a specific date and time by clicking the browse button, which opens the Point in Time Restore dialog box.

    • Marked transaction

      Restore the database to a previously marked transaction. Selecting this option launches the Select Marked Transaction dialog box, which displays a grid listing the marked transactions available in the selected transaction log backups.

      By default, the restore is up to, but excluding, the marked transaction. To restore the marked transaction also, select Include marked transaction.

      The following table lists the column headers of the grid and describes their values.

      Header

      Value

      <blank>

      Displays a checkbox for selecting the mark.

      Transaction Mark

      Name of the marked transaction specified by the user when the transaction was committed.

      Date

      Date and time of the transaction when it was committed. Transaction date and time are displayed as recorded in the msdb gmarkhistory table, not in the client computer's date and time.

      Description

      Description of marked transaction specified by the user when the transaction was committed (if any).

      LSN

      Log sequence number of the marked transaction.

      Database

      Name of the database where the marked transaction was committed.

      User Name

      Name of the database user who committed the marked transaction.

  9. To view or select the advanced options, click Options in the Select a page pane.

  10. For the Restore to options, the choices are:

    • Preserve the replication settings

      Preserves the replication settings when restoring a published database to a server other than the server where the database was created.

      This option is available only with the Leave the database ready for use by rolling back the uncommitted transactions... option (described later), which is equivalent to restoring a backup with the RECOVERY option.

      Checking this option is equivalent to using the KEEP_REPLICATION option in a Transact-SQL RESTORE statement.

    • Prompt before restoring each backup

      Before restoring each backup set (after the first), this option brings up the Continue with Restore dialog box, which asks you to indicate whether you want to continue the restore sequence. This dialog displays the name of the next media set (if available), the backup set name, and backup set description.

      This option is particularly useful when you must swap tapes for different media sets. For example, you can use it when the server has only one tape device. Wait until you are ready to proceed before clicking OK.

      Clicking No leaves the database in the restoring state. At your convenience, you can continue the restore sequence after the last restore that completed. If the next backup is a data or differential backup, use the Restore Database task again. If the next backup is a log backup, use the Restore Transaction Log task.

    • Restrict access to the restored database

      Makes the restored database available only to the members of db_owner, dbcreator, or sysadmin.

      Checking this option is synonymous to using the RESTRICTED_USER option in a Transact-SQL RESTORE statement.

  11. For the Recovery state options, specify the state of the database after the restore operation.

    • Leave the database ready for use by rolling back the uncommitted transactions. Additional transaction logs cannot be restored. (RESTORE WITH RECOVERY)

      Recovers the database. This option is equivalent to the RECOVERY option in a Transact-SQL RESTORE statement.

      Choose this option only if you have no log files you want to restore.

    • Leave the database non-operational, and do not roll back the uncommitted transactions. Additional transaction logs can be restored. (RESTORE WITH NORECOVERY)

      Leaves the database in an unrecovered state. This option is equivalent to using the NORECOVERY option in a Transact-SQL RESTORE statement.

      When you choose this option, the Preserve replication settings option is unavailable.

    • Leave the database in read-only mode. Undo uncommitted transactions, but save the undo actions in a file so that recovery effects can be reverted. (RESTORE WITH STANDBY)

      Leaves the database in a standby state. This option is equivalent to using the STANDBY option in a Transact-SQL RESTORE statement.

      Choosing this option requires that you specify a standby file.

  12. Optionally, specify a standby filename in the Standby file text box. This option is required if you leave the database in read-only mode. You can browse for the standby file or type its pathname in the text box.