One of the features that have been incorporated with MS SQL Server 2005 and its newer versions is Tail-Log Backups, which is mainly associated with backup and restore of SQL Server databases using full or bulk-logged recovery models. In the article, we will be learning about the necessity of backing up Tail log when restoring the database of SQL Server.
What is Tail-Log Backup?
The Tail-Log Backups can be defined as the process to capture all the log records that have not been backed up (as the name suggests, the tail of the log). It is a feature that was introduced in SQL Server 2005 and its later versions. This form of log backup is mainly done to avoid loss of work and to make sure that the log chain is kept intact. It is necessary to have a backup of transaction log tail in order to start restore database operation to the point of failure. The tail-log backup will be the last backup of which one can use for the recovery purpose of database.
Though Tail-Log Backup proves to be quite beneficial in the cases stated above, there are situations that does not require Tail-log backup. They are:
- There is no need of Tail-log backup if recovery point is already present in an earlier log backup
- When the user needs to replace the database, that may include operations such as overwriting or moving database to different location
- When User does not need to restore the database to a point of time after the latest backup of the database
Scenarios that Requires Tail-Log Backup During Restore
Here are some of the common scenarios where a tail-log backup is needed:
- When the database is Online
- If the user wishes to perform restore operation of the online database, the first step is to back up the tail of the log. It is recommended to use ‘WITH RECOVERY’ option of the BACKUP T-SQL statement in order to avoid risk of having errors for the online database.
- NORECOVERY can be used to back up the tail of the log and to keep the database in RESTORING state. It is useful when saving the tail log of the log before RESTORE operation or failing over to a secondary database.
- User can use both NO_TRUNCATE and NORECOVERY options together to create a log backup, which will skip the log truncation and keep the database into RESTORING state in an atomic state
If the database is in offline state and fails to start, user needs to restore the database by creating backup of the tail of log. It is optional whether to use WITH NORECOVERY or not, as no transactions can occur during this time.
In case of database that is damaged, user can take tail-log backup with the help of WITHCONTINUE_AFTER_ERROR option of the BACKUP statement. Another option is to use CHECKSUM
Note: Backing up the tail-log on a damaged database will only succeed if the log files are in healthy state, the database is in the state that supports tail-log backups and no bulk-logged changes is present in the database. If the tail-log backup cannot be created, any transactions committed after the recent log backup will be lost. In such scenario you can take the help of third party SQL database repair to recover lost SQL database.
Tail-Log Backups with missing Backup Metadata
As discussed in the above section, the tail-log backups have the capability to capture the tail of the transaction log in case of the offline database, missing data or damaged files. It might lead to incomplete metadata from the restore information commands and msdb. Even though the metadata may be incomplete, the log that has been captured is complete and usable.
- If the tail-log backup has incomplete metadata, the values of the columns of has_incomplete_metadata and HasIncompleteMetadata are set to 1.
- If metadata in tail-log backup is incomplete, the backupfilegroup table will be missing most of the information related to filegroups during the tail-log backup. The table backupfilegroup will contain several columns that are having null values.
It can be concluded that there is a high necessity of backup up tail log when restoring the database in SQL Server. If the user does not backup the tail of the log, any transactions may be lost that has occurred since the last backup of the database. The article has discussed about tail log backup and the scenarios where backup of the tail log is needed for restoring the database.