APP下载

SQL Server事务日志备份内容研究

2021-10-19李爱武

现代信息科技 2021年6期

摘  要:研究了在将数据库设置为完整恢复模式后,事务日志备份操作中的内容。给出SQL Server事务日志备份的概念,解释了first_lsn和last_lsn的概念,并给出SQL Server确定这两个数值的方法,指出每次事务日志备份的内容是first_lsn和last_lsn之间的重做数据。构造简洁的实验步骤,验证了第一次事务日志备份时,first_lsn是上一次全库备份的first_lsn,从第二次事务日志备份开始,first_lsn是上一次事务日志备份的last_lsn。

关键词:SQL Server;事务日志备份;完整恢复模式

中图分类号:TP311     文献标识码:A 文章编号:2096-4706(2021)06-0158-03

Study on the SQL Server Transaction Log Backup Content

Li Aiwu

(Guangdong Vocational College of Post and Telecom,Guangzhou  510630,China)

Abstract:This paper studies the content of transaction log backup operation after the database is set to full recovery mode. Gives the concept of SQL Server transaction log backup,explains the concept of first_lsn and last_lsn,and gives the method for SQL Server to determine these two numerical values,pointing out that the content of each transaction log backup is the redo data between first_lsn and last_lsn. Constructing concise experimental steps to verify that the first_lsn is the first_lsn of the previous full database backup when the first transaction log backups,and the first_lsn is the last_lsn of the previous transaction log backup from the beginning of the second transaction log backup.

Keywords:SQL Server;transaction log backup;full recovery mode

0  引  言

數据库备份是保证数据安全的重要措施。SQLServer数据库备份分为全库备份、事务日志备份和差异备份三种类型,全库备份的内容为数据库中的全部数据以及first_lsn和last_lsn内的全部重做数据,差异备份是自从上次备份以来修改过的区内的数据。数据库管理员应熟悉各类备份的步骤,并深刻理解各类备份操作的内容。

事务日志备份是为了恢复数据库全库备份操作完成后产生的新数据,从而使数据库恢复到故障时刻,不会因为介质故障而造成数据丢失,也可以使数据库恢复到全库备份操作后的指定时间,用以撤销某些误操作。

执行事务日志备份时,先确定要备份的重做数据范围,即确定first_lsn和last_lsn,然后备份位于first_lsn和last_lsn之间的重做数据。

本文详细介绍事务日志备份的相关概念和步骤,并用实例验证相关结论。

1  全库备份的first_lsn和last_lsn

执行全库备份时,SQL Server依序完成以下步骤:

(1)SQL Server执行checkpoint,把当前内存中被修改的数据写入磁盘文件,并记下checkpoint操作的LSN(Log Sequence Number,用于标识重做记录的序号),并作为checkpoint_lsn写入备份集文件头。……

登录APP查看全文