Ads

21 December 2011

Tail Log Backup

Like any log backup, a tail-log backup is taken by using the BACKUP LOG statement. We recommend that you take a tail-log backup in the following situations:


If the database is online and you plan to perform a restore operation on the database, before starting the restore operation, back up the tail of the log using WITH NORECOVERY:

BACKUP LOG database_name TO WITH NORECOVERY

Note : To avoid an error, the NORECOVERY option is necessary.

If the database is offline and does not start.

Try to take a tail-log backup. Because no transactions can occur at this time, using WITH NORECOVERY is optional. If the database is damaged, use WITH CONTINUE_AFTER_ERROR, as follows:

BACKUP LOG database_name TO WITH CONTINUE_AFTER_ERROR

If the database is damaged, for example, if the database does not start, a tail-log backup succeeds only if the log files are undamaged, the database is in a state that supports tail-log backups, and the database does not contain any bulk-logged changes.

The following table summarizes these options.


To create a transaction log backup when the database is damaged
 
To create a backup of the currently active transaction log

Execute the BACKUP LOG statement to back up the currently active transaction log, specifying:
The name of the database to which the transaction log to back up belongs.
The backup device where the transaction log backup will be written.

The NO_TRUNCATE clause.

This clause allows the active part of the transaction log to be backed up even if the database is inaccessible, provided that the transaction log file is accessible and undamaged.

Optionally, specify:
The INIT clause to overwrite the backup media, and write the backup as the first file on the backup media. If no existing media header exists, one is automatically written.

The SKIP and INIT clauses to overwrite the backup media, even if there are either backups on the backup media that have not yet expired, or the media name does not match the name on the backup media.

The FORMAT clause, when you are using media for the first time, to initialize the backup media and rewrite any existing media header.

The INIT clause is not required if the FORMAT clause is specified.

Important noteImportant


Use extreme caution when you are using the FORMAT or INIT clauses of the BACKUP statement as this will destroy any backups previously stored on the backup media.



Example

Important noteImportant



The MyAdvWorks_FullRM database is a copy of AdventureWorks2008R2, which uses the simple recovery model. To permit log backups, before taking a full database backup, the database was set to use the full recovery model, using ALTER DATABASE MyAdvWorks_FullRM SET RECOVERY FULL.



This example backs up the currently active transaction log for the MyAdvWorks_FullRM database even though MyAdvWorks_FullRM has been damaged and is inaccessible. However, the transaction log is undamaged and accessible:



BACKUP LOG MyAdvWorks_FullRM


TO MyAdvWorks_FullRM_log1


WITH NO_TRUNCATE;


GO

No comments:

Post a Comment