{"id":2615,"date":"2015-11-23T04:04:20","date_gmt":"2015-11-23T09:04:20","guid":{"rendered":"https:\/\/academy.sqlbak.com\/?p=2615"},"modified":"2023-10-17T05:33:25","modified_gmt":"2023-10-17T09:33:25","slug":"transaction-log-backup","status":"publish","type":"post","link":"https:\/\/academy.sqlbak.com\/transaction-log-backup\/","title":{"rendered":"Transaction Log Backup"},"content":{"rendered":"

A transaction log backup contains all transaction log records that have been made between the last transaction log backup or the first full backup and the last log record that is created upon completion of the backup process. The transaction log backup allows to restore a database to a particular point-in-time before the failure has occurred. It is incremental, meaning that in order to restore a database to a certain point-in-time, all transaction log records are required\u00a0to replay\u00a0database changes up to that particular point-in-time. Please note that transaction log backup is available\u00a0only for\u00a0full or bulk-logged recovery models. The picture below shows how transaction\u00a0log backup works.<\/p>\n

\"Transaction<\/p>\n

Due to the fact that in full or bulk-logged recovery models transaction log is truncated when the transaction log backup is made, it is necessary to backup the log regularly in order to manage the size of the transaction log. Otherwise, the transaction log file will grow until there’s no more space left.<\/p>\n

If there is no need in the point-in-time recovery and database is growing slowly it is better to use a simple recovery model (without transaction logs). In this case the transaction log is automatically truncated to remove any inactive virtual log files (every log record is stored in virtual log files and can have any number of them. The size of each virtual log file is not fixed). As far as the simple recovery model is concerned, the transaction log truncation takes place after each checkpoint.<\/p>\n

Transaction Log Backup Chain<\/h2>\n

A transaction log backup chain is a continuous sequence of transaction log backups starting\u00a0with first full database backup. Each backup from the chain has its own FirstLSN (oldest log record in the backup set) and LastLSN (the number of the next log record after the backup set), that help to restore transaction log backup files in the right sequence.<\/p>\n

\"Transaction<\/p>\n

To get backup’s FirstLSN and LastLSN values you can use the following command:<\/p>\n

RESTORE HEADERONLY FROM DISK<\/span> = 'log.bak'<\/span><\/pre>\n

\"LSN\"<\/span><\/p>\n

Though it’s a great opportunity to restore a database to the point-in-time with the help of a log backup chain there are some instances when the log backup chain is broken. Here are the two of such:<\/p>\n