Pages

Friday, 11 July 2014

SQL Server: STOPATMARK and STOPATBEFOREMARK clauses

The STOPATMARK and STOPATBEFOREMARK clauses of the RESTORE statement are used to restore the database to the saved point in the transaction or to a point before the transaction began, respectively. DBA/Developer could use the following statement to restore the log:

RESTORE LOG Research
FROM ResearchBackUp
WITH RECOVERY,
STOPATMARK='ToleranceUpdate';

When restoring a database, DBA/Developer must restore the latest full backup. If applicable, DBA/Developer must restore the latest differential backup since the last full backup. DBA/Developer should then restore each transaction log backup that was made since the last full backup or, if DBA/Developer made differential backups, the transaction log backup that was made since the last differential backup. DBA/Developer should also make a copy of the current transaction log. This backup will be called the tail-log backup because it contains the transactions that have not been recorded. When DBA/Developer restore the latest full database backup and the latest differential backup, specify WITH NORECOVERY in the RESTORE statement. The NORECOVERY option is required in this scenario because DBA/Developer will be applying transaction log backups after the database is restored. Then, DBA/Developer consecutively restore each of the transaction log backups that were made after the last full database backup or differential backup. Each transaction log backup must be restored by specifying the NORECOVERY option so that all subsequent transaction log backups can be restored. DBA/Developer should restore the transaction log backup that was made on the active transaction log. This is the latest log backup. When restoring the transaction log, DBA/Developer should use the STOPATMARK option along with the RECOVERY option in the RESTORE LOG statement. The STOPAT option specifies the desired point in time to which DBA/Developer want to restore the database, and the WITH RECOVERY option brings the database to a consistent state. DBA/Developer can use marked transactions across databases to recover multiple databases to the same specific point, but doing so causes any transactions committed after the mark used as the recovery point to be lost. DBA/Developer should not restore the log backup using WITH STOPBEFOREMARK = 'ToleranceUpdate'. The WITH STOPBEFOREMARK clause in the RESTORE LOG statement uses the log record before the saved point as the mark for recovery. In this scenario, DBA/Developer wanted to restore the Widget table to the ToleranceUpdate transaction, not to a point before it started. DBA/Developer should not use a ROLLBACK statement to roll back to the ToleranceUpdate transaction. DBA/Developer can use a ROLLBACK statement to roll back to a specific point in a transaction, but to do so, DBA/Developer must first use the SAVE TRANSACTION statement to create a named savepoint. In this scenario, DBA/Developer did not create a savepoint. DBA/Developer created a marked transaction. DBA/Developer should not restore the transaction log and use a ROLLBACK statement to roll back to the ToleranceUpdate transaction. DBA/Developer must create a savepoint to roll back to a specific point in a transaction.

No comments:

Post a Comment