{"id":3229,"date":"2015-12-08T02:59:16","date_gmt":"2015-12-08T07:59:16","guid":{"rendered":"https:\/\/academy.sqlbak.com\/?p=3229"},"modified":"2023-10-17T05:20:50","modified_gmt":"2023-10-17T09:20:50","slug":"backup-chain","status":"publish","type":"post","link":"https:\/\/academy.sqlbak.com\/backup-chain\/","title":{"rendered":"Backup chain"},"content":{"rendered":"
<\/p>\n
RESTORE DATABASE<\/span>\u00a0your_database\u00a0<\/em>FROM DISK<\/span> = 'full_00_00.bak'<\/span> WITH NORECOVERY<\/span>, REPLACE<\/span><\/pre>\n\nDifferential Backup<\/h3>\n<\/div>\nAfter the full backup was restored the next necessary step would be restoring the last differential backup. If you are not sure which differential database backups belong to the restored full backup, you can first restore the headers of backups. Please use the following\u00a0syntax to do it:<\/div>\nRESTORE HEADERONLY FROM DISK<\/span> = 'full_00_00.bak'<\/span>\r\nRESTORE HEADERONLY FROM DISK<\/span> = 'diff_06_00.bak'<\/span> \r\nRESTORE HEADERONLY FROM DISK<\/span> = 'diff_12_00.bak' \u00a0<\/span><\/pre>\nThe following result will be received:<\/div>\n<\/div>\n<\/div>\n<\/div>\nIn this scenario you need to pay attention to the full backup CheckpointLSN value and compare it with Differential backups DatabaseBackupLSN value – they should be identical (marked as blue square). It means\u00a0that these two differential backups belong to this full backup and can be restored after it. To find out what differential backup was made earlier, compare\u00a0their FirstLSN numbers (marked as orange square). The last differential backup will have bigger value.<\/div>\n<\/div>\nIf you try to restore a differential backup before restoring its full\u00a0backup, you will get the following error message:<\/div>\nMsg 3136, Level 16, State 3, Line 1<\/span>\r\nThis differential backup cannot be restored because the database has not been restored to the correct earlier state.<\/span>\r\nMsg 3013, Level 16, State 1, Line 1<\/span>\r\nRESTORE DATABASE is terminating abnormally.<\/span><\/pre>\n\nThat means that the backup chain\u00a0was broken and any further recovery process is not possible. Therefore, pay attention to what differential backup should be restored after the full backup. In our example it is necessary to restore a differential database backup from 12:00 using the following command:<\/p>\n
RESTORE DATABASE<\/span>\u00a0your_database\u00a0<\/em>FROM DISK<\/span> = 'diff_12_00.bak'<\/span> WITH NORECOVERY<\/span><\/pre>\n<\/div>\n\nTransaction Log Backups<\/h3>\n<\/div>\nNow that we’ve restored the full and differential backups, let’s\u00a0restore the database to its state as of 14:29. This is where we will require the transaction log backups. In this case it is also necessary to follow a certain sequence to avoid breaking transaction log backup chain.<\/div>\nIf you need to determine what transaction log backup follows after another, you need to get backup’s headers\u00a0(same as we did with differential backups):<\/div>\n<\/div>\n<\/div>\nThis picture shows a transaction log backup chain, each backup from the chain has its own FirstLSN\u00a0and LastLSN. Every LastLSN value of the transaction log must be the same as FirstLSN values of the next transaction log backup. These values help to restore transaction log backup files in the right sequence. To find out what transaction log backup should\u00a0be restored after the differential backup, compare their DatabaseBackupLSN values – they should be identical:<\/div>\n<\/div>\n<\/div>\n<\/div>\nTo understand which transaction log backup should be restored first after differential backup, please check LastLSN value of the differential backup. This value should be somewhere between the FirstLSN and the LastLSN values of the transaction log backup. Otherwise, if the wrong transaction log backup is\u00a0applied to the differential backup, you’ll get\u00a0the following error:<\/div>\nMsg 4305, Level 16, State 1, Line 17<\/span>\r\nThe log in this backup set begins at LSN 74000000071200001, which is too recent to apply to the database. An earlier log backup that includes LSN 74000000065600001 can be restored.<\/span>\r\nMsg 3013, Level 16, State 1, Line 17<\/span>\r\nRESTORE LOG is terminating abnormally.<\/span><\/pre>\nTo restore transaction log use the following syntax:<\/div>\nRESTORE <\/span>LOG<\/span> your_database<\/em> FROM DISK<\/span> = 'log_13_00.bak'<\/span> WITH NORECOVERY\u00a0<\/span><\/pre>\nThen to restore the database up to the state at 13:29:59 run the foloowing command for transaction log from 14:00 using “WITH STOPAT” option:<\/div>\n\nRESTORE<\/span> LOG<\/span> your_database<\/em> FROM DISK<\/span> = 'log_14_00.bak' <\/span>WITH STOPAT<\/span> = '2015-11-19 13:29:59.000'<\/span>, RECOVERY<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"A backup chain is a specific sequence in which all database backups should be restored. If a backup chain is broken, the restore process will be not possible, and some data will be lost. Let us consider the following example with all three backup types to understand the backup chain better.<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[157],"tags":[],"yoast_head":"\n
Backup chain - Sql Server Backup Academy<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n