[go: up one dir, main page]

CN100449548C - Database synchronization method and system - Google Patents

Database synchronization method and system Download PDF

Info

Publication number
CN100449548C
CN100449548C CNB2007100738877A CN200710073887A CN100449548C CN 100449548 C CN100449548 C CN 100449548C CN B2007100738877 A CNB2007100738877 A CN B2007100738877A CN 200710073887 A CN200710073887 A CN 200710073887A CN 100449548 C CN100449548 C CN 100449548C
Authority
CN
China
Prior art keywords
server
database
synchronization
backup
main
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CNB2007100738877A
Other languages
Chinese (zh)
Other versions
CN101038591A (en
Inventor
朱湘毅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CNB2007100738877A priority Critical patent/CN100449548C/en
Publication of CN101038591A publication Critical patent/CN101038591A/en
Application granted granted Critical
Publication of CN100449548C publication Critical patent/CN100449548C/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种数据库同步的方法,该方法中在主用服务器数据库中设置包括同步标识号和SQL语句的同步表,利用同步表实现数据库的数据同步。本发明还公开了一种数据库同步系统,包括主用服务器和备用服务器,主用服务器包括备份单元、同步表单元,备用服务器包括请求单元、获取单元和同步单元。本发明公开的方法和系统,利用同步表,在实现数据库同步,简化对服务器配置的修改,使得数据库同步可以不受操作系统和数据库系统的限制,提高数据同步的效率。

Figure 200710073887

The invention discloses a database synchronization method. In the method, a synchronization table including a synchronization identification number and an SQL statement is set in a main server database, and the data synchronization of the database is realized by using the synchronization table. The invention also discloses a database synchronization system, which includes a main server and a backup server. The main server includes a backup unit and a synchronization table unit, and the backup server includes a request unit, an acquisition unit and a synchronization unit. The method and system disclosed in the present invention use the synchronization table to realize database synchronization, simplify the modification of server configuration, make the database synchronization not limited by the operating system and the database system, and improve the efficiency of data synchronization.

Figure 200710073887

Description

数据库同步方法及系统 Database synchronization method and system

技术领域 technical field

本发明涉及数据库技术,尤其涉及数据库同步的方法及系统。The invention relates to database technology, in particular to a database synchronization method and system.

背景技术 Background technique

在电信管理网络中,每个网络单元都有一个操作维护单元(OMU,Operation & Maintenance Unit),具体可以是安装OMU软件的服务器,负责提供该网络单元的操作维护功能。为维护网络单元的正常工作,电信运营商对网络单元的操作维护功能可靠性要求很高,一般都在99.999%以上。因此,为了保证OMU操作维护功能的可靠性,电信设备供应商一般采用对OMU的双机(Dual System)备份机制。所谓双机,是由两台计算机组成的系统,其中,与主用OMU对应的服务器是主用服务器(Active Server,以下简称AS),对外提供服务功能;与备用OMU对应的服务器是备用服务器(StandbyServer,以下简称SS),为主用服务器提供备份功能、不对外提供服务功能。主用服务器和备用服务器在一定条件下可以发生倒换,即主用变备用、备用变主用。两者结合,能够连续地对外提供服务功能。In the telecommunications management network, each network unit has an operation and maintenance unit (OMU, Operation & Maintenance Unit), which can be specifically a server with OMU software installed, which is responsible for providing the operation and maintenance function of the network unit. In order to maintain the normal operation of the network unit, telecom operators have very high requirements on the reliability of the operation and maintenance function of the network unit, generally more than 99.999%. Therefore, in order to ensure the reliability of OMU operation and maintenance functions, telecom equipment suppliers generally adopt a dual system (Dual System) backup mechanism for OMU. The so-called dual-computer system is a system composed of two computers. Among them, the server corresponding to the active OMU is the active server (Active Server, hereinafter referred to as AS), which provides external service functions; the server corresponding to the standby OMU is the standby server ( StandbyServer, hereinafter referred to as SS), provides backup functions for the main server and does not provide external service functions. The active server and the standby server can be switched under certain conditions, that is, the active server becomes the standby server, and the standby server becomes the active server. The combination of the two can continuously provide external service functions.

采用双机备份机制可以保证系统运作的可靠性,在主用服务器因故死机或人为疏忽等影响,而无法对OMU进行操作维护时,备用服务器会立即取代主用服务器的地位,继续对OMU进行操作维护。采用这种机制,大大减少系统运作停顿的概率,无论对个人用户还是企业用户,都提供了可靠的保障。另外,采用双机备份机制,用户数据可以传递给两部主机,获得妥善的备份,提高了信息处理的安全性。The dual-server backup mechanism can ensure the reliability of the system operation. When the main server fails to operate and maintain the OMU due to some reasons such as crash or human negligence, the backup server will immediately replace the main server and continue to maintain the OMU. Operation and maintenance. Adopting this mechanism greatly reduces the probability of system operation halting, and provides reliable protection for both individual users and enterprise users. In addition, by adopting the dual-computer backup mechanism, user data can be transmitted to two hosts to obtain proper backup and improve the security of information processing.

要实现对网络单元的操作维护,服务器要处理大量的数据,例如配置数据、告警数据、性能统计数据等,这些数据都存储于服务器的数据库系统中,OMU服务器上会安装数据库系统软件,提供统一的数据库访问接口。这些存储于数据库系统中的数据随着系统的运行,是实时修改的。因此要实现双机备份功能,必须保证主用服务器数据库系统中的数据和备用服务器数据库系统中的数据之间的实时同步。这样才能确保主用服务器发生故障时,备用服务器升级为主用服务器后能提供正确的操作维护功能。To implement the operation and maintenance of network units, the server has to process a large amount of data, such as configuration data, alarm data, and performance statistics. These data are stored in the database system of the server. database access interface. These data stored in the database system are modified in real time as the system runs. Therefore, to realize the dual-machine backup function, it is necessary to ensure real-time synchronization between the data in the database system of the active server and the data in the database system of the standby server. Only in this way can it be ensured that when the active server fails, the standby server can provide correct operation and maintenance functions after being upgraded to the active server.

现有技术中,实现双机数据库同步有如下技术方案:In the prior art, there are the following technical solutions to realize the synchronization of dual-machine databases:

方案一:Option One:

利用数据库复制机制,比如SQL复制。所谓复制,是将一组数据从一个数据源拷贝到多个数据源的技术。SQL(Structured Query Language,结构化查询语言)复制的基本元素包括出版服务器、订阅服务器、分发服务器、出版物、文章。源数据所在的服务器是出版服务器,负责发表数据。出版服务器把要发表的数据的所有改变情况拷贝复制到分发服务器,分发服务器包含有一个分发数据库,可从出版服务器接收数据的所有改变,并保存这些改变,再把这些改变分发给订阅服务器。Utilize database replication mechanisms, such as SQL replication. The so-called replication is a technique for copying a set of data from one data source to multiple data sources. The basic elements of SQL (Structured Query Language, Structured Query Language) replication include publishers, subscribers, distributors, publications, and articles. The server where the source data resides is the publishing server, which is responsible for publishing the data. The publishing server copies all the changes of the data to be published to the distribution server. The distribution server contains a distribution database, which can receive all the changes of the data from the publishing server, save these changes, and then distribute these changes to the subscription server.

以Microsoft公司的SQL Server数据库系统为例,该系统提供了三种复制技术,分别是快照复制、事务复制和合并复制。主备服务器之间的数据库实时同步一般采用事务复制技术。采用事务复制需要进行如下配置步骤:Taking Microsoft's SQL Server database system as an example, the system provides three replication technologies, namely snapshot replication, transactional replication, and merge replication. Real-time database synchronization between primary and secondary servers generally uses transactional replication technology. Using transactional replication requires the following configuration steps:

1.配置一个数据库作为分发数据库(分发数据库可以配置在主用服务器,也可以配置在备用服务器上),指定哪些服务器可以使用该数据库;1. Configure a database as the distribution database (the distribution database can be configured on the main server or on the standby server), and specify which servers can use the database;

2.在主用服务器上,配置主用服务器使用的分发数据库;配置主用服务器上允许的订阅服务器;配置主用服务器上需要发布的数据库和数据库中需要发布的数据表和字段等;2. On the active server, configure the distribution database used by the active server; configure the subscribers allowed on the active server; configure the database that needs to be published on the active server and the data tables and fields that need to be published in the database;

3.在备用服务器上,配置对发布数据库的订阅;3. On the standby server, configure the subscription to the publishing database;

4.配置各代理进程的调度和属性,有快照代理进程、分发代理进程和日志读取代理进程等;4. Configure the scheduling and attributes of each agent process, including snapshot agent process, distribution agent process and log reading agent process, etc.;

上述配置过程非常复杂,容易出错且配置时间较长,如果有多个数据库,每个数据库有多张数据表进行同步,则配置过程一般需要几分钟。同时该配置过程对数据库的属性进行了修改,对数据库的操作将受到限制,比如配置某数据库为发布数据库后,就不能删除该数据库了。The above configuration process is very complicated, error-prone and takes a long time to configure. If there are multiple databases and each database has multiple data tables for synchronization, the configuration process generally takes several minutes. At the same time, the configuration process modifies the attributes of the database, and the operations on the database will be restricted. For example, after configuring a database as a publishing database, the database cannot be deleted.

上述配置成功后,主用服务器上的SQL SERVER会把各数据库中需要同步的数据表的数据自动生成一个快照(类似于数据表的数据导出文件),该快照信息传送到分发数据库中,分发数据库再分发到备用服务器,备用服务器将快照中的数据导入到订阅数据库中,这样主备服务器完成了初始数据同步。事务复制配置好之后,先完成初始同步,自动进行实时同步。主用服务器发生数据修改时,发布数据库会把数据修改的日志信息传送到分发数据库,分发数据库再将其分发给订阅数据库,订阅数据库根据日志信息修改数据,保证与发布数据库同步。After the above configuration is successful, the SQL SERVER on the primary server will automatically generate a snapshot of the data in the data table that needs to be synchronized in each database (similar to the data export file of the data table), and the snapshot information will be sent to the distribution database, and the distribution database Then distribute to the standby server, and the standby server imports the data in the snapshot into the subscription database, so that the primary and secondary servers complete the initial data synchronization. After transactional replication is configured, the initial synchronization is completed first, and real-time synchronization is performed automatically. When data modification occurs on the primary server, the publishing database will transmit the log information of the data modification to the distribution database, and the distribution database will distribute it to the subscription database, and the subscription database will modify the data according to the log information to ensure synchronization with the distribution database.

该方案的缺陷是:The disadvantages of this scheme are:

1.必须基于SQL Server数据库系统,相应的,该系统必须安装在WINDOWS操作系统上;1. Must be based on the SQL Server database system, correspondingly, the system must be installed on the WINDOWS operating system;

2.必须在主备服务器间配置事务复制关系,主备服务器发生倒换需要重新配置事务复制关系。由于事务复制关系非常复杂,对数据库系统的配置过程很复杂。2. The transaction replication relationship must be configured between the active and standby servers, and the transaction replication relationship needs to be reconfigured when the active and standby servers are switched. Since the transaction replication relationship is very complicated, the configuration process of the database system is very complicated.

3.发布服务器和订阅服务器完成初始数据库同步时间长。事务复制生成和应用快照的时间与数据表的数量成正比,以数据库中需要同步的数据表为500张计算,一般需要30分钟以上的时间才能完成初始同步。而且订阅服务器上应用快照是一张表接一张表依次应用的,不是一个事务里完成的。完成初始同步过程前一般不能发生主备服务器的倒换,否则备用服务器上的数据是混乱的。这个时间对于电信运营商难以接收;3. The publisher and subscriber take a long time to complete the initial database synchronization. The time for transactional replication to generate and apply snapshots is proportional to the number of data tables. If there are 500 data tables in the database that need to be synchronized, it usually takes more than 30 minutes to complete the initial synchronization. Moreover, the application of snapshots on the subscriber server is applied one by one table by table, not in one transaction. Generally, the switchover of the active and standby servers cannot occur before the initial synchronization process is completed, otherwise the data on the standby server will be confused. This time is difficult for telecom operators to accept;

4.该方案对于服务器有很多限制和影响。事务复制依赖于数据库的日志,对日志做标记,以标识已经传送到分发数据库以及未传送的日志,以此保证数据库更改一致。如果备用服务器故障,则主用服务器的数据库日志会不断增长,导致数据库无法运行;如果主用服务器还原数据库,则会导致日志混乱,事务复制会出现故障。4. This solution has many restrictions and impacts on the server. Transactional replication relies on the database's log, and marks the log to identify the log that has been delivered to the distribution database and the log that has not been delivered, so as to ensure that the database changes are consistent. If the standby server fails, the database log of the active server will continue to grow, causing the database to fail to run; if the active server restores the database, the log will be confused, and transaction replication will fail.

方案二:Option II:

以Microsoft公司的SQL Server 2000企业版为例,该系统提供了日志传送的功能,即不间断地从源数据库中备份事务日志,然后将它们复制并还原到目的数据库,使目的数据库与源数据库保持同步。与事务复制相比,日志传送稍为简单一些。日志传送保证两个数据库同步,而事务复制可以使需要同步的数据表保持同步,不需要同步的数据表可以不进行同步。初始同步方面,SQL SERVER提供了日志传送操作的向导,在目的服务器上创建源数据库,保证初始数据一致。Take Microsoft's SQL Server 2000 Enterprise Edition as an example. This system provides the function of log transfer, that is, it continuously backs up transaction logs from the source database, then copies and restores them to the destination database, so that the destination database and the source database remain the same. Synchronize. Log shipping is slightly simpler than transactional replication. Log transfer ensures that the two databases are synchronized, and transactional replication can keep the data tables that need to be synchronized in sync, and the data tables that do not need to be synchronized can not be synchronized. In terms of initial synchronization, SQL SERVER provides a wizard for log transfer operations to create a source database on the destination server to ensure that the initial data is consistent.

该方案的缺陷是:The disadvantages of this scheme are:

1.必须基于Sql Server数据库系统,相应的,该系统必须安装在WINDOWS操作系统上;1. It must be based on the Sql Server database system. Correspondingly, the system must be installed on the WINDOWS operating system;

2.日志传送的实时性较差,实时同步周期一般配置在15分钟,对于实时性要求较高的服务器不合适;2. The real-time performance of log transmission is poor, and the real-time synchronization cycle is generally configured at 15 minutes, which is not suitable for servers with high real-time requirements;

3.日志传送可靠性不如事务复制,对可靠性要求较高的服务器不合适。3. The reliability of log transfer is not as good as transactional replication, and it is not suitable for servers with high reliability requirements.

发明内容 Contents of the invention

有鉴于此,本发明实施例要解决的主要问题在于,提供数据库同步的方法和系统,可以简化对服务器配置的修改,数据库同步不受操作系统和数据库系统的限制,提高了数据同步的效率。In view of this, the main problem to be solved by the embodiment of the present invention is to provide a method and system for database synchronization, which can simplify the modification of server configuration, database synchronization is not limited by the operating system and database system, and the efficiency of data synchronization is improved.

本发明的一个实施例所提供的数据库同步的方法,用于主用服务器数据库和备用服务器数据库的初始同步,主用服务器数据库中设置有包括同步标识号的同步表,该方法包括以下步骤:备用服务器向主用服务器发送初始同步请求;主用服务器根据接收到的初始同步请求,在同步表中更新同步标识号,并备份主用服务器数据库,生成备份文件;备用服务器获取更新后的同步标识号和备份文件,用备份文件恢复备用服务器数据库。The method for database synchronization provided by an embodiment of the present invention is used for the initial synchronization of the active server database and the standby server database. The active server database is provided with a synchronization table comprising a synchronization identification number. The method includes the following steps: standby The server sends an initial synchronization request to the active server; the active server updates the synchronization identification number in the synchronization table according to the received initial synchronization request, and backs up the database of the active server to generate a backup file; the standby server obtains the updated synchronization identification number and backup files, use the backup files to restore the standby server database.

本发明的另一个实施例所提供的数据库同步的方法,用于主用服务器数据库和备用服务器数据库的实时同步,主用服务器数据库中设置有包括同步标识号和SQL语句的同步表,同步标识号根据数据库操作实时更新,该方法包括以下步骤:主用服务器复制需要同步的数据库操作的SQL语句到同步表中;备用服务器直接连接到主用服务器数据库上,从同步表中获取SQL语句,并用该SQL语句访问备用服务器数据库。The method for database synchronization provided by another embodiment of the present invention is used for the real-time synchronization of the active server database and the standby server database. The active server database is provided with a synchronization table comprising a synchronization identification number and an SQL statement, the synchronization identification number Real-time update according to the database operation, the method comprises the following steps: the primary server replicates the SQL statement of the database operation that needs to be synchronized to the synchronization table; the standby server is directly connected to the primary server database, obtains the SQL statement from the synchronization table, and uses the SQL statements access the standby server database.

本发明的再一个实施例所提供的数据库同步的方法,用于主用服务器数据库和备用服务器数据库的同步,主用服务器数据库中设置有包括同步标识号和SQL语句的同步表,该方法包括:The method for database synchronization provided by another embodiment of the present invention is used for the synchronization of the active server database and the standby server database. The active server database is provided with a synchronization table comprising a synchronization identification number and an SQL statement. The method includes:

A、备用服务器检查其保存的标识号是否存在于同步表中,如果不存在,则执行步骤B、C、D,如果存在,则执行步骤E、F;A, standby server checks whether the identification number it saves exists in the synchronization table, if it does not exist, then execute steps B, C, D, if it exists, then execute steps E, F;

B、备用服务器向主用服务器发送初始同步请求;B. The standby server sends an initial synchronization request to the active server;

C、主用服务器根据接收到的所述初始同步请求,在同步表中更新同步标识号,备份主用服务器数据库数据库,生成备份文件;C. The active server updates the synchronization identification number in the synchronization table according to the received initial synchronization request, backs up the database database of the active server, and generates a backup file;

D、备用服务器获取更新后的同步标识号和备份文件,用备份文件恢复备用服务器数据库;D, the backup server obtains the updated synchronization identification number and the backup file, and restores the backup server database with the backup file;

E、主用服务器复制需要同步的数据库操作的SQL语句到同步表中;E. The primary server copies the SQL statement of the database operation that needs to be synchronized to the synchronization table;

F、备用服务器从同步表中获取该SQL语句,并用该SQL语句访问备用服务器数据库。F. The standby server obtains the SQL statement from the synchronization table, and uses the SQL statement to access the database of the standby server.

本发明的再一个实施例所提供的数据库同步的系统,包括配置有主用服务器数据库的主用服务器,以及配置有备用服务器数据库的备用服务器,主用服务器数据库中设置有包括同步标识号和SQL语句的同步表。The database synchronization system provided by another embodiment of the present invention includes a primary server configured with a primary server database, and a standby server configured with a standby server database. The synchronization table for the statement.

该系统的主用服务器包括:备份单元,用于在初始同步阶段,在收到备用服务器发送的初始同步请求后,备份主用服务器数据库生成备份文件;同步表单元,用于在初始同步阶段,在同步表中更新同步标识号,还用于在实时同步阶段,更新同步表中的同步标识号,复制需要同步的数据库操作的SQL语句到同步表中;The active server of the system includes: a backup unit, used for generating a backup file from the database of the active server after receiving the initial synchronization request sent by the standby server in the initial synchronization phase; a synchronization table unit, used in the initial synchronization phase, Update the synchronization identification number in the synchronization table, and also used to update the synchronization identification number in the synchronization table during the real-time synchronization stage, and copy the SQL statement of the database operation that needs to be synchronized to the synchronization table;

备用服务器包括:请求单元,用于向主用服务器发送初始同步请求;获取单元,用于在初始同步阶段,获取备份单元生成的备份文件,以及同步表单元在同步表中更新后的同步标识号;同步单元,用于在初始同步阶段,从获取单元获取备份文件,并用该备份文件恢复备用服务器数据库,还用于在实时同步阶段,从同步表中获取SQL语句,并用该SQL语句访问备用服务器数据库。The backup server includes: a request unit, used to send an initial synchronization request to the active server; an acquisition unit, used to obtain the backup file generated by the backup unit during the initial synchronization phase, and the synchronization identification number updated by the synchronization table unit in the synchronization table ; The synchronization unit is used to obtain the backup file from the acquisition unit in the initial synchronization phase, and use the backup file to restore the standby server database, and is also used to obtain the SQL statement from the synchronization table in the real-time synchronization phase, and use the SQL statement to access the standby server database.

本发明的实施例所提供的方法及系统,利用同步表中的标识号,来判断是否需要初始同步和保证初始同步后主备服务器保持数据一致,采用备用服务器读取主用服务器上的同步表中的SQL语句的方式,直接获取主用服务器的数据修改。从而简化对服务器配置的修改,数据库同步不受操作系统和数据库系统的限制,提高了数据同步的效率。The method and system provided by the embodiments of the present invention use the identification number in the synchronization table to judge whether initial synchronization is required and ensure that the primary and secondary servers maintain data consistency after initial synchronization, and use the secondary server to read the synchronization table on the primary server Directly obtain the data modification of the primary server by means of the SQL statement in the This simplifies the modification of the server configuration, the database synchronization is not restricted by the operating system and the database system, and the efficiency of data synchronization is improved.

附图说明 Description of drawings

图1为本发明实施例中,同步表结构示意图;FIG. 1 is a schematic structural diagram of a synchronization table in an embodiment of the present invention;

图2为本发明第一个实施例数据库同步的方法流程图;Fig. 2 is the flow chart of the method for database synchronization in the first embodiment of the present invention;

图3为本发明第二个实施例数据库同步的方法流程图;Fig. 3 is the flow chart of the method for database synchronization in the second embodiment of the present invention;

图4为本发明第三个实施例数据库同步的方法流程图;Fig. 4 is the flow chart of the method for database synchronization of the third embodiment of the present invention;

图5为本发明第四个实施例数据库同步的系统图。Fig. 5 is a system diagram of database synchronization in the fourth embodiment of the present invention.

具体实施方式 Detailed ways

为使本发明的目的、技术方案和优点更加清楚明白,下面结合实施例和附图,对本发明的技术方案进一步详细说明。In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be further described in detail below in conjunction with the embodiments and accompanying drawings.

本发明实施例提供的技术方案,利用同步表,在应用层实现数据库同步,简化对服务器配置的修改,数据库同步可以不受操作系统和数据库系统的限制,提高数据同步的效率。The technical solution provided by the embodiment of the present invention utilizes the synchronization table to implement database synchronization at the application layer, simplifies the modification of the server configuration, and the database synchronization is not restricted by the operating system and the database system, thereby improving the efficiency of data synchronization.

图1为本发明实施例中,同步表结构示意图。FIG. 1 is a schematic structural diagram of a synchronization table in an embodiment of the present invention.

如图1所示,设置于主用服务器数据库中的同步表,包括两个字段:同步标识字段(identity)和SQL语句字段。As shown in FIG. 1 , the synchronization table set in the primary server database includes two fields: a synchronization identification field (identity) and a SQL statement field.

同步标识字段一般采用数据库提供的种子属性,自动递增。这个字段不需要维护,如果种子属性设置是从1开始递增,插入第一条记录时,不需要制定该字段的值,数据库系统就自动置为1,插入第二条,自动置为2,如果删除了数据库的所有记录,下次再插入时,该字段的值是删除之前的值加1。同步标识字段用来表示同步标识号。The synchronization identification field generally adopts the seed attribute provided by the database and is automatically incremented. This field does not need to be maintained. If the seed attribute is set to increase from 1, when inserting the first record, there is no need to specify the value of this field, and the database system will automatically set it to 1, insert the second record, and automatically set it to 2. If All records in the database are deleted. When inserting next time, the value of this field is the value before deletion plus 1. The synchronization identification field is used to indicate the synchronization identification number.

SQL语句字段存放修改数据库的SQL语句。SQL几乎是所有大型数据服务器都支持的数据操作语言,它提供一些可以快速执行数据查询、更新、删除等数据操作的叙述。就标识和SQL的关系而言,标识是插入每条SQL记录时给的一个编号,即每插入一条SQL记录,标识字段的值加1。The SQL statement field stores the SQL statement for modifying the database. SQL is a data manipulation language supported by almost all large-scale data servers, and it provides some narratives that can quickly perform data operations such as data query, update, and deletion. As far as the relationship between the identifier and SQL is concerned, the identifier is a number given when inserting each SQL record, that is, the value of the identifier field is increased by 1 for each SQL record inserted.

本发明实施例中,通过在主用服务器上设置同步表,同步表的同步标识号和备用服务器的标识号配合比较,检查是否需要初始同步。通过SQL语句,实现实时同步,同时在实时同步的过程中,实时检查是否需要初始同步。以此,通过同步表中标识和SQL语句,实现数据库同步。In the embodiment of the present invention, by setting a synchronization table on the active server, the synchronization identification number of the synchronization table is compared with the identification number of the standby server to check whether initial synchronization is required. Real-time synchronization is realized through SQL statements, and at the same time, during the process of real-time synchronization, it is checked in real time whether initial synchronization is required. In this way, database synchronization is realized by synchronizing the identifiers and SQL statements in the table.

备用服务器的标识号可以保存在数据库中或保存在配置文件中。该值初始化为0,所以初次启动时,肯定与主用服务器同步表中最小的标识号是不一样的,因此会进行初始同步。初始同步完成后,备用服务器保存的标识号就会存在于同步表中。接着进入实时同步,在该过程中,主用服务器每修改一次数据,在同步表中插入SQL记录,增加一次同步表记录,对应增加标识号;实时同步时,备用服务器先删除主用服务器上同步表中标识号小于自身保存的标识号的记录,然后读取主用服务器上同步表中标识号大于自身保存标识号的记录。备用服务器每执行一条读取过来的记录前,将自己保存的标识号与读取过来的记录的标识号进行检查,如果其保存的标识号与读取过来的标识号连续,则说明备用服务器与主用服务器一直保持同步,则执行该条记录,并更新保存的标识号,即,将最新同步过的标识号保存下来。如果不连续,则说明主备用服务器已经失去了数据同步,备用服务器需要重新开始数据同步。判断备用服务器保存的标识号与读取过来的标识号是否连续,也即判断备用服务器保存的标识号是否存在于同步表中。The identification number of the standby server can be saved in the database or in the configuration file. The value is initialized to 0, so when it is started for the first time, it must be different from the smallest identification number in the synchronization table of the active server, so the initial synchronization will be performed. After the initial synchronization is complete, the identification numbers held by the standby server are present in the synchronization table. Then enter real-time synchronization. In this process, every time the primary server modifies data, it inserts a SQL record into the synchronization table, adds a synchronization table record, and correspondingly increases the identification number; The record in the table whose identification number is smaller than the identification number saved by itself, and then read the record in the synchronization table on the primary server whose identification number is greater than the identification number saved by itself. Before the backup server executes a read record, it checks the ID number saved by itself and the ID number of the read record. If the primary server keeps in sync all the time, execute this record and update the saved identification number, that is, save the latest synchronized identification number. If not, it means that the primary and standby servers have lost data synchronization, and the standby server needs to restart data synchronization. It is judged whether the identification number stored by the standby server is continuous with the read identification number, that is, it is judged whether the identification number stored by the standby server exists in the synchronization table.

如果备用服务器发生重启,则重启后检查其保存的同步标识号在主用服务器同步表中是否仍然存在,如果是,则只需要继续实时同步即可。如果备用服务器停止了很长时间,导致主用服务器把同步表清除过,则备用服务器保存的同步标识号在同步表中不存在了,则重新开始初始同步。If the standby server restarts, check whether the synchronization identification number saved by it still exists in the synchronization table of the active server after restarting, and if so, only need to continue the real-time synchronization. If the standby server has stopped for a long time, causing the active server to clear the synchronization table, the synchronization identification number saved by the standby server does not exist in the synchronization table, and the initial synchronization is restarted.

本发明的第一个实施例涉及数据库初始同步的方法,用于主用服务器数据库和备用服务器数据库的初始同步,其中,主用服务器数据库中设置有包括同步标识号的同步表,该方法具体流程如图2所示。The first embodiment of the present invention relates to a method for initial synchronization of databases, which is used for the initial synchronization of the primary server database and the standby server database, wherein the primary server database is provided with a synchronization table including a synchronization identification number, and the specific flow of the method as shown in picture 2.

步骤201:由备用服务器检查其保存的标识号是否存在于同步表中,据此判断是否需要开始初始同步;Step 201: check whether the identification number saved by the standby server exists in the synchronization table, and judge whether to start the initial synchronization accordingly;

比如,在以下三种场景下,都需要进行步骤201的判断:For example, in the following three scenarios, the judgment of step 201 is required:

(1)如前所述,标识字段采用数据库提供的种子属性,自动递增,可以设置从1开始。备用服务器的标识号可以保存在数据库中或保存在配置文件中。该值初始化为0。所以初次启动时,肯定与主用服务器同步表中最小的标识号是不一样的,即备用服务器保存的标识号不存在于同步表中,因此会进行初始同步,则执行后续步骤;(1) As mentioned above, the identification field adopts the seed attribute provided by the database, which is automatically incremented and can be set to start from 1. The identification number of the standby server can be saved in the database or in the configuration file. The value is initialized to 0. Therefore, when starting for the first time, it must be different from the smallest identification number in the synchronization table of the active server, that is, the identification number saved by the standby server does not exist in the synchronization table, so the initial synchronization will be performed, and then follow-up steps will be performed;

(2)在实时同步过程中,备用服务器执行一条记录,则更新一下自己保存的标识号,执行前将自己保存的标识号与读取过来的记录的标识号进行检查,如果其保存的标识号与读取过来的记录的标识号连续,则只需要继续实时同步即可;如果否,说明主用服务器清除过同步表记录,则重新开始初始同步,执行后续步骤;(2) In the process of real-time synchronization, when the standby server executes a record, it updates the identification number saved by itself, and checks the identification number saved by itself and the identification number of the read record before execution. If it is continuous with the identification number of the read record, you only need to continue the real-time synchronization; if not, it means that the primary server has cleared the synchronization table record, then restart the initial synchronization and perform the next steps;

(3)如果备用服务器发生重启,则重启后检查保存的同步标识号在主用同步表中是否仍然存在,如果是,则只需要继续实时同步即可。如果备用服务器停止了很长时间,导致主用服务器把同步表清除过,则备用服务器保存的同步标识号在同步表中不存在了,则重新开始初始同步,执行后续步骤。(3) If the standby server restarts, check whether the saved synchronization identification number still exists in the active synchronization table after the restart, and if so, only need to continue the real-time synchronization. If the standby server has stopped for a long time, causing the active server to clear the synchronization table, the synchronization identification number saved by the standby server does not exist in the synchronization table, then restart the initial synchronization and perform subsequent steps.

步骤202:备用服务器向主用服务器发送请求初始同步的请求消息;Step 202: the standby server sends a request message requesting initial synchronization to the active server;

步骤203:主用服务器收到备用服务器发送的请求消息后,在同步表中更新同步标识号,备份主用服务器数据库,生成备份文件;Step 203: After the active server receives the request message sent by the standby server, it updates the synchronization identification number in the synchronization table, backs up the database of the active server, and generates a backup file;

该步骤中,主用服务器收到备用服务器发送的请求消息后,在备份数据库前,会清空同步表中的数据记录。另外,在备份数据库之前,为防止备份过程中,有模块修改数据库数据,要对数据库加锁。加锁成功后清空同步表中的数据记录,主用服务器清空数据记录后再插入一条空记录,同步标识字段的值在删除之前的值的基础上加1,形成更新后的同步标识号。接着,主用服务器备份数据库,生成备份文件。完成备份后,解除对数据库的锁定,并发送携带该新的同步标识号的备份成功消息给备用服务器。In this step, after receiving the request message sent by the standby server, the active server will clear the data records in the synchronization table before backing up the database. In addition, before backing up the database, in order to prevent any module from modifying the database data during the backup process, the database must be locked. After the locking is successful, the data records in the synchronization table are cleared, the primary server clears the data records and then inserts an empty record, and the value of the synchronization identification field is added to the value before deletion to form an updated synchronization identification number. Next, the primary server backs up the database and generates a backup file. After the backup is completed, the database is unlocked, and a backup success message carrying the new synchronization identification number is sent to the standby server.

步骤204:备用服务器获取备份文件和更新后的同步标识号;Step 204: the standby server obtains the backup file and the updated synchronization identification number;

备用服务器收到主用服务器发送的备份成功消息后,会获取并保存该同步标识号,即第一条同步记录对应的标识,以此来保证备用服务器保存的标识号存在于在主用服务器的同步表中。另外,可以通过FTP或操作系统提供的文件传输功能,把备份文件从主用服务器传输到备用服务器。具体传输的方式,既可以采用备用服务器主动获取备份文件的方式,也可以是主用服务器主动传输的方式。而采用备用服务器主动获取备份文件的方式,可以减少主用服务器处理的复杂度。After receiving the backup success message sent by the active server, the standby server will obtain and save the synchronization identification number, that is, the identification corresponding to the first synchronization record, so as to ensure that the identification number saved by the standby server exists in the active server's in the synchronization table. In addition, the backup file can be transferred from the active server to the standby server through FTP or the file transfer function provided by the operating system. The specific way of transmission can be either a way that the standby server actively obtains the backup file, or a way that the active server actively transmits. And adopting the mode that the standby server actively obtains the backup file can reduce the processing complexity of the active server.

步骤205:备用服务器用接收到的备份文件恢复备用服务器数据库。Step 205: the standby server restores the database of the standby server by using the received backup file.

至此,完成了数据库初始同步过程。At this point, the initial database synchronization process is completed.

从数据库加锁到解锁的时间内,主用服务器的各模块访问数据库会阻塞住。一般网元数据库中的配置、告警、性能等数据总量在50M~500M之间,OMU服务器的硬盘都采用高性能的SCSI硬盘或SAS硬盘,吞吐量在每秒30M以上,SATA硬盘在每秒150M以上。数据库从加锁到锁住的时间0~3秒左右,数据库被锁住的总时间在3~20秒左右。数据初始同步时间还包括备用服务器获取备份文件以及恢复数据库的时间,主备服务器间一般是1000MBits/S的高速带宽,备份文件可以在10秒内传送到备用服务器。数据库恢复时间小于数据库备份时间,加上之前所用的时间,整个初始同步可以在1分钟之内完成,提高了初始同步的效率。From the time when the database is locked to unlocked, each module of the primary server will be blocked from accessing the database. Generally, the total amount of configuration, alarm, and performance data in the network element database is between 50M and 500M. The hard disk of the OMU server uses high-performance SCSI hard disk or SAS hard disk, with a throughput of more than 30M per second. More than 150M. The time from locking to locking the database is about 0 to 3 seconds, and the total time for the database to be locked is about 3 to 20 seconds. The initial data synchronization time also includes the time for the standby server to obtain backup files and restore the database. The high-speed bandwidth between the active and standby servers is generally 1000MBits/S, and the backup files can be transferred to the standby server within 10 seconds. The database recovery time is shorter than the database backup time, plus the previous time, the entire initial synchronization can be completed within 1 minute, which improves the efficiency of the initial synchronization.

在整个初始同步过程中,如果出现没有成功完成某个步骤的情况,如主用服务器返回消息失败或等待超时,数据库加锁失败,数据库备份失败,备份文件传输失败,或备用数据库恢复失败等,都会返回步骤201。During the entire initial synchronization process, if a certain step is not successfully completed, such as the failure of the active server to return a message or wait for timeout, database locking failure, database backup failure, backup file transfer failure, or standby database recovery failure, etc., All will return to step 201.

由于本发明实施例数据库初始同步的方法,利用同步表中的标识号,来判断是否需要初始同步和保证初始同步后主备服务器保持数据一致,具体采用数据库备份还原的方法,简化对服务器配置的修改,数据库同步不受操作系统和数据库系统的限制,提高了数据初始同步的效率。Because the method for the initial synchronization of the database in the embodiment of the present invention uses the identification number in the synchronization table to judge whether the initial synchronization is needed and to ensure that the primary and backup servers maintain data consistency after the initial synchronization, specifically adopt the method of database backup and restoration to simplify the server configuration. Modification, database synchronization is not limited by the operating system and database system, which improves the efficiency of initial data synchronization.

从整个数据库同步过程来看,备用服务器首先同步主用服务器的初始数据库;备用服务器在完成初始同步的基础上,实时同步主用服务器上数据库中的数据修改。初始同步完成后,备用服务器保存的标识号就会存在于同步表中。以下结合附图对本发明第二个实施例进行描述。From the point of view of the entire database synchronization process, the standby server first synchronizes the initial database of the active server; after completing the initial synchronization, the standby server synchronizes the data modification in the database on the active server in real time. After the initial synchronization is complete, the identification numbers held by the standby server are present in the synchronization table. The second embodiment of the present invention will be described below with reference to the accompanying drawings.

本发明的第二个实施例涉及数据库实时同步的方法,用于主用服务器数据库和备用服务器数据库的实时同步,其中,主用服务器数据库中设置有包括同步标识号和SQL语句的同步表,同步标识号根据数据库操作实时更新,该方法具体流程如图3所示。The second embodiment of the present invention relates to a method for real-time database synchronization, which is used for the real-time synchronization of the active server database and the standby server database, wherein the active server database is provided with a synchronization table comprising a synchronization identification number and an SQL statement, and the synchronization The identification number is updated in real time according to the database operation, and the specific flow of the method is shown in FIG. 3 .

步骤301:主用服务器判断是否有需要实时同步的数据库操作,如果需要,则执行步骤302和303,如果不需要,则继续进行本步骤的判断;Step 301: The primary server judges whether there is a database operation that requires real-time synchronization, and if so, executes steps 302 and 303, and if not, proceeds to the judgment of this step;

OMU软件提供统一的数据库访问接口,一般OMU提供的配置、性能统计、告警等操作维护功能由不同的软件模块来实现。各软件模块调用该数据库访问接口操作数据库。数据库访问接口提供可选参数,指明该操作是否需要同步。例如,可以用TRUE表示需要同步,FALSE表示不需要同步,缺省是TRUE。The OMU software provides a unified database access interface. Generally, the OMU functions such as configuration, performance statistics, and alarms are implemented by different software modules. Each software module calls the database access interface to operate the database. The database provider provides an optional parameter indicating whether the operation requires synchronization. For example, you can use TRUE to indicate that synchronization is required, FALSE to indicate that synchronization is not required, and the default is TRUE.

步骤302:主用服务器复制需要实时同步的数据库操作的SQL语句到同步表中;Step 302: the primary server copies the SQL statement of the database operation requiring real-time synchronization to the synchronization table;

该语句是某模块访问数据库并对数据库数据进行修改的语句。这样,备用服务器就可以从同步表中获取该SQL语句。This statement is a statement for a certain module to access the database and modify the database data. In this way, the standby server can obtain the SQL statement from the synchronization table.

步骤303:备用服务器从所述同步表中获取该SQL语句;Step 303: the standby server acquires the SQL statement from the synchronization table;

具体获取SQL语句的方法,可以是备用服务器获取主用服务器数据库的用户名和密码,根据获取的用户名和密码,直接连接到主用数据库上,获取同步表的SQL语句。备用服务器通过这样的方式,从主用服务器的数据同步表中读取一批记录。A specific method for obtaining the SQL statement may be that the standby server obtains the user name and password of the database of the primary server, and directly connects to the primary database according to the obtained user name and password to obtain the SQL statement of the synchronization table. In this way, the standby server reads a batch of records from the data synchronization table of the active server.

步骤304:备用服务器用同样的SQL访问备用服务器数据库。Step 304: the standby server uses the same SQL to access the database of the standby server.

获取SQL语句后,备用服务器通过数据库访问接口,用同样的SQL访问其数据库,即逐个执行这些记录。由于备用服务器与主用服务器的基础数据一致,因此两者的数据修改同步,从而使备用服务器与主用服务器的数据库保持了同步。After obtaining the SQL statement, the standby server accesses its database with the same SQL through the database access interface, that is, executes these records one by one. Since the basic data of the standby server is consistent with that of the active server, the data modification of the two is synchronized, so that the databases of the standby server and the active server are kept in sync.

实时同步过程中,主用服务器每修改一次数据,就增加一次同步表记录。备用服务器实时同步时,同步更新备用服务器的标识号,把最新同步过的标识号保存下来,执行修改记录完成后,删除主用服务器同步表中已同步的记录。因为备用服务器同步主用服务器的第N条记录时,只会删除主用同步表中前面的N-1条记录,第N条记录保留在同步表中,这样,备用服务器每次都可以检查自己同步过的最后一条记录是否在同步表中,判断是否需要初始同步。During real-time synchronization, every time the primary server modifies data, a synchronization table record is added. When the standby server is synchronized in real time, the identification number of the standby server is updated synchronously, and the latest synchronized identification number is saved. After the modification record is completed, the synchronized record in the synchronization table of the active server is deleted. Because when the standby server synchronizes the Nth record of the active server, it only deletes the first N-1 records in the active synchronization table, and the Nth record is kept in the synchronization table, so that the standby server can check itself every time Whether the last record that has been synchronized is in the synchronization table determines whether initial synchronization is required.

备用服务器可以设置同步周期,在完成一个周期的同步后,下一个周期继续实时同步。同步周期一般设置在秒级,因此主用服务器上的数据修改在秒级内就可以同步到备用服务器,做到了实时同步。The standby server can set a synchronization period, and after completing a period of synchronization, the next period will continue to synchronize in real time. The synchronization period is generally set at the second level, so the data modification on the primary server can be synchronized to the standby server within seconds, achieving real-time synchronization.

由于本发明实施例提供的数据库实时同步的方法,采用备用服务器读取主用服务器上的同步表记录中的SQL语句的方式,直接获取主用服务器的数据修改,简化对服务器配置的修改,数据库同步不受操作系统和数据库系统的限制,提高了数据同步的效率。Because the database real-time synchronization method provided by the embodiment of the present invention adopts the mode of the standby server to read the SQL statement in the synchronization table record on the active server, directly obtains the data modification of the active server, simplifies the modification to the server configuration, and the database Synchronization is not limited by the operating system and database system, which improves the efficiency of data synchronization.

本发明的第三个实施例涉及数据库同步的方法,用于主用服务器数据库和备用服务器数据库的同步,其中,主用服务器数据库中设置有包括同步标识号和SQL语句的同步表。本实施例中,以先初始同步,完成后进行实时同步为例,该方法具体流程如图4所示。The third embodiment of the present invention relates to a method for synchronizing databases, which is used for synchronizing the primary server database and the standby server database, wherein the primary server database is provided with a synchronization table including a synchronization identification number and an SQL statement. In this embodiment, the initial synchronization is performed first, and the real-time synchronization is performed after completion as an example. The specific flow of the method is shown in FIG. 4 .

步骤401:由备用服务器检查其保存的标识号是否存在于同步表中,据此判断是否需要开始初始同步;Step 401: check whether the identification number saved by the standby server exists in the synchronization table, and judge whether to start the initial synchronization accordingly;

如果不需要初始同步,则直接进入步骤406;如果需要初始同步,进行以下步骤:If initial synchronization is not required, proceed directly to step 406; if initial synchronization is required, proceed to the following steps:

步骤402:备用服务器向主用服务器发送请求初始同步的请求消息;Step 402: the standby server sends a request message requesting initial synchronization to the active server;

步骤403:主用服务器根据接收到的所述请求消息,在同步表中更新同步标识号,备份主用服务器数据库,生成备份文件;Step 403: The active server updates the synchronization identification number in the synchronization table according to the received request message, backs up the database of the active server, and generates a backup file;

步骤404:备用服务器获取备份文件和更新后的同步标识号;Step 404: the backup server obtains the backup file and the updated synchronization identification number;

步骤405:备用服务器用接收到的备份文件恢复备用服务器数据库。Step 405: the standby server restores the database of the standby server by using the received backup file.

以上初始同步各步骤中的具体流程,与第一个实施例中的相应步骤相同,此处不再赘述。至此,完成了数据库初始同步过程,因为此时备用服务器保存的标识号存在于同步表中,所以初始同步完成后进行实时同步。The specific processes in the steps of initial synchronization above are the same as the corresponding steps in the first embodiment, and will not be repeated here. At this point, the initial synchronization process of the database is completed, because the identification number saved by the standby server exists in the synchronization table at this time, so real-time synchronization is performed after the initial synchronization is completed.

步骤406:主用服务器判断是否有需要实时同步的数据库操作;Step 406: The primary server judges whether there is any database operation requiring real-time synchronization;

如果有需要同步的数据库操作,进行下面步骤。If there are database operations that need to be synchronized, perform the following steps.

步骤407:主用服务器复制需要同步的数据库操作的SQL语句到同步表中;Step 407: the primary server copies the SQL statement of the database operation that needs to be synchronized to the synchronization table;

步骤408:备用服务器从所述同步表中获取该SQL语句;Step 408: The standby server acquires the SQL statement from the synchronization table;

步骤409:备用服务器用同样的SQL访问备用服务器数据库。Step 409: The standby server uses the same SQL to access the database of the standby server.

以上实时同步各步骤中的具体流程,与第二个实施例中的相应步骤相同,此处不再赘述。在实时同步的过程中,备用服务器同步更新备用服务器的标识号,执行完成后删除主用服务器同步表中已同步的记录。并且备用服务器每执行一条记录,都会检查标识号是否存在于同步表中,判断是否需要初始同步。因为数据是从同步表中读出来的,只要判断一下备用服务器保存的标识是否和读出来的记录的标识是否连续即可。The specific processes in the steps of the above real-time synchronization are the same as the corresponding steps in the second embodiment, and will not be repeated here. In the process of real-time synchronization, the standby server synchronously updates the identification number of the standby server, and deletes the synchronized records in the synchronization table of the active server after the execution is completed. And every time the standby server executes a record, it will check whether the identification number exists in the synchronization table, and judge whether initial synchronization is required. Because the data is read from the synchronization table, it is only necessary to judge whether the identifier saved by the standby server is continuous with the identifier of the read record.

由于本发明该实施例数据库同步的方法,利用同步表,实现数据库的初始同步和实时同步,简化对服务器配置的修改,数据库同步不受操作系统和数据库系统的限制,提高了数据同步的效率。Because the database synchronization method in this embodiment of the present invention utilizes the synchronization table to realize the initial synchronization and real-time synchronization of the database, simplify the modification of the server configuration, the database synchronization is not restricted by the operating system and the database system, and the efficiency of data synchronization is improved.

本发明的第四个实施例涉及数据库同步的系统,图5为该数据库同步的系统图,如图5所示:The fourth embodiment of the present invention relates to a database synchronization system, and Fig. 5 is a system diagram of the database synchronization, as shown in Fig. 5:

该数据库同步系统,包括配置有主用服务器数据库的主用服务器,以及配置有备用服务器数据库的备用服务器,主用服务器数据库中设置有包括同步标识号和SQL语句的同步表。The database synchronization system includes an active server configured with an active server database, and an alternate server configured with an alternate server database. The active server database is provided with a synchronization table including a synchronization identification number and an SQL statement.

其中,主用服务器包括:Among them, the main server includes:

备份单元501,用于在初始同步阶段,在收到备用服务器发送的初始同步请求后,备份数据库生成备份文件;同步表单元502,用于在初始同步阶段,在同步表更新同步标识号,还用于在实时同步阶段,更新同步表中的同步标识号,复制需要同步的数据库操作的SQL语句到同步表中;同步表可以设置于同步表单元中。The backup unit 501 is used to generate a backup file for the backup database after receiving the initial synchronization request sent by the standby server in the initial synchronization phase; the synchronization table unit 502 is used to update the synchronization identification number in the synchronization table in the initial synchronization phase, and also It is used to update the synchronization identification number in the synchronization table in the real-time synchronization stage, and copy the SQL statement of the database operation that needs to be synchronized to the synchronization table; the synchronization table can be set in the synchronization table unit.

备用服务器包括:Alternate servers include:

请求单元503,用于向主用服务器发送请求初始同步的请求消息;获取单元504,用于在初始同步阶段,获取主用服务器中备份单元生成的备份文件,以及同步表单元502在同步表中更新后的同步表标识并保存;同步单元505,用于在初始同步阶段,从获取单元504获取备份文件,并用该备份文件恢复备用服务器数据库,还用于在实时同步阶段,从同步表中获取SQL语句,并用同样的SQL语句访问备用服务器数据库。The request unit 503 is configured to send a request message requesting initial synchronization to the primary server; the obtaining unit 504 is used to obtain the backup file generated by the backup unit in the primary server during the initial synchronization phase, and the synchronization table unit 502 is in the synchronization table The updated synchronization table is marked and saved; the synchronization unit 505 is used to obtain the backup file from the acquisition unit 504 during the initial synchronization phase, and restores the backup server database with the backup file, and is also used to obtain the backup file from the synchronization table during the real-time synchronization phase. SQL statement, and use the same SQL statement to access the standby server database.

主用服务器的备份单元可以进一步包括:The backup unit of the primary server may further include:

备份子单元,用于在收到备用服务器发送的初始同步请求后,备份数据库生成备份文件;响应子单元,用于在备份子单元备份数据库成功后,向备用服务器发送备份成功消息;其中,备份成功消息携带初始同步阶段同步表单元在同步表中更新后的同步标识号。相应的,获取单元从备份成功消息中获取该同步标识号,从备份子单元中获取备份文件。The backup subunit is used to back up the database to generate a backup file after receiving the initial synchronization request sent by the backup server; the response subunit is used to send a backup success message to the backup server after the backup subunit successfully backs up the database; wherein, the backup The success message carries the synchronization identification number after the synchronization table unit is updated in the synchronization table in the initial synchronization phase. Correspondingly, the acquiring unit acquires the synchronization identification number from the backup success message, and acquires the backup file from the backup subunit.

主用服务器还可以进一步包括:加锁子单元,用于在主用服务器备份数据库前,对主用服务器数据库加锁。The active server may further include: a locking subunit, configured to lock the database of the active server before the active server backs up the database.

该系统还可以包括实时同步判断单元,用于根据数据库访问接口提供的参数,判断有需要实时同步的数据库操作时,向同步单元发送同步命令;同步单元根据所述同步命令,从同步表中获取SQL语句,并用同样的SQL语句访问备用服务器数据库,完成数据的实时同步。The system can also include a real-time synchronization judging unit, which is used to send a synchronization command to the synchronization unit when judging that there is a database operation that requires real-time synchronization according to the parameters provided by the database access interface; the synchronization unit obtains from the synchronization table according to the synchronization command. SQL statement, and use the same SQL statement to access the standby server database to complete real-time data synchronization.

数据同步过程中,请求单元503根据获取单元504保存的同步标识号是否存在于同步表单元502的同步表中,作出是否需要初始同步的判断;如果需要初始同步,则发送请求初始同步的请求消息给主用服务器的备份单元501。备份单元501收到备用服务器发送的请求消息后,备份数据库,生成备份文件。同步表单元502,在同步表中形成更新后的同步标识号。备份成功后,获取单元504获取该备份文件,并获取该同步表标识并保存之。而同步单元505,利用获取单元504获取的备份文件,用该文件恢复备用服务器数据库,实现了数据库初始同步。In the data synchronization process, the request unit 503 determines whether initial synchronization is needed according to whether the synchronization identification number preserved by the acquisition unit 504 exists in the synchronization table of the synchronization table unit 502; if initial synchronization is required, then send a request message requesting initial synchronization Backup unit 501 for the active server. After receiving the request message sent by the standby server, the backup unit 501 backs up the database and generates a backup file. The synchronization table unit 502 forms an updated synchronization identification number in the synchronization table. After the backup is successful, the obtaining unit 504 obtains the backup file, and obtains the synchronization table identifier and saves it. The synchronization unit 505 uses the backup file acquired by the acquisition unit 504 to restore the database of the backup server, thereby realizing the initial synchronization of the database.

主用服务器判断有需要实时同步的数据库操作时,同步表单元502复制需要同步的数据库操作的SQL语句到同步表中,更新同步表单元中的同步标识。在该过程中,主用服务器每修改一次数据,就增加一次同步表记录。同步单元505从同步表中获取该SQL语句,并用同样的SQL访问备用服务器数据库,实现数据实时的修改同步。备用服务器同步主用服务器的第N条记录时,只会删除主用同表中前面的N-1条记录,第N条记录保留在同步表中,这样,备用每次都可以检查自己同步过的最后一条记录是否在同步表中,判断是否需要初始同步。When the primary server judges that there is a database operation that needs to be synchronized in real time, the synchronization table unit 502 copies the SQL statement of the database operation that needs to be synchronized to the synchronization table, and updates the synchronization identifier in the synchronization table unit. During this process, every time the primary server modifies data, a synchronization table record is added. The synchronization unit 505 obtains the SQL statement from the synchronization table, and uses the same SQL to access the standby server database, so as to realize real-time data modification synchronization. When the standby server synchronizes the Nth record of the active server, it will only delete the first N-1 records in the same table of the active server, and the Nth record will be kept in the synchronization table, so that the standby server can check whether it has synchronized each time. Whether the last record of is in the synchronization table determines whether initial synchronization is required.

而本实施例中,判断是否有需要实时同步的数据库操作,可以由实时同步判断单元来实现,该单元根据数据库访问接口提供的参数,判断是否有需要实时同步的数据库操作。若判断结果为是,则向同步单元505发送同步命令,同步单元505根据该命令,从所述同步表中获取SQL语句,并用同样的SQL语句访问备用服务器数据库。However, in this embodiment, judging whether there is a database operation requiring real-time synchronization can be realized by a real-time synchronization judging unit, which judges whether there is a database operation requiring real-time synchronization according to the parameters provided by the database access interface. If the judgment result is yes, a synchronization command is sent to the synchronization unit 505, and the synchronization unit 505 obtains the SQL statement from the synchronization table according to the command, and uses the same SQL statement to access the standby server database.

由于本发明该实施例数据库同步系统,利用同步表,实现数据库的初始同步和实时同步,简化对服务器配置的修改,数据库同步不受操作系统和数据库系统的限制,提高了数据同步的效率。Because the database synchronization system of this embodiment of the present invention utilizes the synchronization table to realize the initial synchronization and real-time synchronization of the database, simplify the modification of the server configuration, the database synchronization is not restricted by the operating system and the database system, and the efficiency of data synchronization is improved.

以上所述的具体实施例,对本发明的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上所述仅为本发明思想的一种展示,而非用于限定本发明的保护范围。凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The specific embodiments described above have further described the purpose, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a demonstration of the idea of the present invention, and is not used to limit the present invention scope of protection. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.

Claims (16)

1, a kind of database synchronization method is used for main initial synchronisation with server database and standby server database, it is characterized in that, described main with being provided with the synchronous meter that comprises sync id number in the server database, this method may further comprise the steps:
Standby server sends the initial synchronisation request to main with server;
Main with server according to the described initial synchronisation request that receives, in described synchronous meter, upgrade sync id number, and back up the described main server database of using, generation backup file;
Standby server obtains sync id number and the described backup file after the described renewal, with described backup file recovery standby server database.
2, method according to claim 1 is characterized in that, described main with server according to the described initial synchronisation request that receives, the step of renewal sync id number comprises in described synchronous meter:
Main receive described initial synchronisation request with server after, empty the data recording in the synchronous meter and insert null record, form the sync id number after upgrading.
3, method according to claim 2 is characterized in that, described master with after the server database success, sends the backup success message of the sync id number after carrying described renewal with the server backup master to standby server;
The step that described standby server obtains the sync id number after the described renewal is:
Standby server obtains and preserves the sync id number after the described renewal from described backup success message.
4, according to each described method of claim 1 to 3, it is characterized in that, further be included in and lead with the server backup master with before the server database, to the main step that locks with server database.
5, the main seed attribute that increases progressively automatically that provides with server database of sync id in the described synchronous meter number employing according to each described method of claim 1 to 3, is provided.
6, a kind of database synchronization method, be used for main the synchronous in real time of server database and standby server database of using, described main with being provided with the synchronous meter that comprises sync id number and SQL statement in the server database, described sync id is number according to the database manipulation real-time update, it is characterized in that this method may further comprise the steps:
The master needs the SQL statement of data in synchronization storehouse operation in described synchronous meter with server replicates;
Standby server is directly connected to the master with on the server database, obtains described SQL statement from described synchronous meter, and visits the standby server database with described SQL statement.
7, method according to claim 6 is characterized in that, before described master needs data in synchronization storehouse operation with server replicates SQL statement was in the described synchronous meter, described method also comprised the steps:
The master according to the parameter that database access interface provides, need to have judged whether the operation of real-time data in synchronization storehouse with server.
8, method according to claim 7 is characterized in that, described standby server obtains described SQL statement from described synchronous meter step comprises:
Described standby server obtains main username and password with server database;
Be connected to the master according to the described username and password that obtains and use server, obtain the described SQL statement of synchronous meter.
9, a kind of database synchronization method, be used for main with server database and standby server database synchronously, described main with being provided with the synchronous meter that comprises sync id number and SQL statement in the server database, it is characterized in that this method comprises:
A, standby server check whether the identification number of its preservation is present in the described synchronous meter, if there is no, then execution in step B, C, D, if exist, then execution in step E, F;
B, standby server send the initial synchronisation request to main with server;
C, main with server according to the described initial synchronisation request that receives, in described synchronous meter, upgrade sync id number, back up described master and uses server database, the generation backup file;
D, standby server obtain sync id number and the described backup file after the described renewal, recover the standby server database with described backup file;
E, master need the SQL statement of data in synchronization storehouse operation in described synchronous meter with server replicates;
F, standby server obtain described SQL statement from described synchronous meter, and visit the standby server database with described SQL statement.
10, method according to claim 9 is characterized in that, described main with server according to the described initial synchronisation request that receives, the step of renewal sync id number comprises in described synchronous meter:
Main receive described initial synchronisation request with server after, empty the data recording in the synchronous meter and insert null record, form the sync id number after upgrading;
Main with the server backup master with the server database success after, send the backup success message of the sync id number after carrying described renewal to standby server.
11, method according to claim 9 is characterized in that, also comprises before step e:
The main parameter that provides according to database access interface with server, judging has the operation of the real-time data in synchronization of needs storehouse.
12, method according to claim 9 is characterized in that, described standby server obtains described SQL statement from described synchronous meter step comprises:
Standby server obtains main username and password with server database, is connected to the master with on the server according to described username and password, obtains the described SQL statement of synchronous meter.
13, a kind of database synchronous system comprises that disposing main master with server database uses server, and the standby server that disposes the standby server database, it is characterized in that,
Described main with being provided with the synchronous meter that comprises sync id number and SQL statement in the server database;
Described master comprises with server:
Backup units was used in the initial synchronisation stage, and after receiving the initial synchronisation request that standby server sends, backup is main to generate backup file with server database;
The synchronous meter unit was used in the initial synchronisation stage, upgraded sync id number in described synchronous meter, also was used at real-time synchronous phase, upgraded the sync id number in the described synchronous meter, duplicate need the operation of data in synchronization storehouse SQL statement in synchronous meter;
Described standby server comprises:
Request unit is used for sending the initial synchronisation request to main with server;
Acquiring unit was used in the initial synchronisation stage, obtained the backup file that described backup units generates, and the sync id of synchronous meter unit after upgrading in described synchronous meter number;
Lock unit, be used in the initial synchronisation stage, obtain described backup file from described acquiring unit, and recover the standby server database with this backup file, also be used at real-time synchronous phase, from described synchronous meter, obtain described SQL statement, and visit the standby server database with described SQL statement.
14, system according to claim 13 is characterized in that, described main backup units with server further comprises:
The backup subelement is used for after receiving the initial synchronisation request that standby server sends, and backup is main to generate backup file with server database;
The response subelement is used for sending the backup success message to standby server after described backup subelement backup master is with the server database success;
Described backup success message carries the sync id number after initial synchronisation stage described synchronous meter unit upgrades in described synchronous meter;
Described acquiring unit obtains the sync id number after the described renewal from described backup success message, obtain described backup file from described backup subelement.
15, system according to claim 13 is characterized in that, described master further comprises with server:
The subelement that locks, be used for main with the server backup master with before the server database, lock with server database to main.
16, system according to claim 13, it is characterized in that this system also comprises main with the in real time synchronous judging unit in the server, and the parameter that provides according to database access interface is provided, judge when the operation of the real-time data in synchronization of needs storehouse is arranged, send synch command to described lock unit;
Described lock unit obtains described SQL statement according to described synch command from described synchronous meter, and visits the standby server database with described SQL statement.
CNB2007100738877A 2007-04-11 2007-04-11 Database synchronization method and system Expired - Fee Related CN100449548C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2007100738877A CN100449548C (en) 2007-04-11 2007-04-11 Database synchronization method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2007100738877A CN100449548C (en) 2007-04-11 2007-04-11 Database synchronization method and system

Publications (2)

Publication Number Publication Date
CN101038591A CN101038591A (en) 2007-09-19
CN100449548C true CN100449548C (en) 2009-01-07

Family

ID=38889494

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2007100738877A Expired - Fee Related CN100449548C (en) 2007-04-11 2007-04-11 Database synchronization method and system

Country Status (1)

Country Link
CN (1) CN100449548C (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110096389A (en) * 2019-04-30 2019-08-06 上海达梦数据库有限公司 A kind of starting method, apparatus, equipment and the storage medium of database

Families Citing this family (53)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101933014B (en) * 2007-09-28 2013-11-20 阿珀蒂奥有限公司 System and method for replication and synchronisation
CN100574220C (en) * 2007-12-11 2009-12-23 华为技术有限公司 Data back up method and application processing system
CN101489074B (en) * 2009-01-14 2013-11-27 深圳市龙视传媒有限公司 Collaborative recording system and method
CN101826073B (en) * 2009-03-06 2013-08-28 华为技术有限公司 Synchronous method, apparatus and system for distributed database
CN102006611B (en) * 2009-09-03 2014-03-19 中兴通讯股份有限公司 Method for realizing data uniqueness conversion and mobile switching center servers
CN101706795B (en) * 2009-11-30 2012-05-09 上海世范软件技术有限公司 Method for synchronizing database data on main server and standby server
CN102193841B (en) 2010-03-04 2013-07-31 阿里巴巴集团控股有限公司 Backup method and device of Subversion configuration database
CN101854400B (en) * 2010-06-09 2015-04-01 中兴通讯股份有限公司 Database synchronization deployment and monitoring method and device
CN102299904B (en) * 2010-06-23 2014-03-19 阿里巴巴集团控股有限公司 System and method for realizing service data backup
CN102118247A (en) * 2011-01-04 2011-07-06 中兴通讯股份有限公司 System and method for password management
CN102843395B (en) * 2011-06-22 2015-08-19 阿里巴巴集团控股有限公司 A kind of method of data synchronization and device
CN102662793A (en) * 2012-03-07 2012-09-12 江苏引跑网络科技有限公司 Hot backup and recovery method of distributed database with guarantee of data consistency
CN102801789B (en) * 2012-07-17 2015-09-02 浙江中烟工业有限责任公司 A kind of number of cigarette combined test stand adopts networked system
CN103580906B (en) * 2012-08-09 2018-02-27 腾讯科技(深圳)有限公司 A kind of method of data backup, system and server
WO2014127300A1 (en) * 2013-02-15 2014-08-21 Intuitive Surgical Operations, Inc. Systems and methods for synchronizing nodes of a robotic system
CN104066107A (en) * 2013-03-22 2014-09-24 中兴通讯股份有限公司 Method and system for business disaster tolerance
CN103365979A (en) * 2013-07-03 2013-10-23 交通银行股份有限公司 Long-distance double-center online processing method and system based on open database
CN103605740B (en) * 2013-11-19 2016-10-05 北京国双科技有限公司 Data import treating method and apparatus
CN103886091B (en) * 2014-04-01 2017-08-01 无锡科技职业学院 A kind of database synchronization method based on recording mark
CN104503868B (en) * 2014-12-29 2017-10-27 成都致云科技有限公司 Method of data synchronization, device and system
CN105988893A (en) * 2015-02-10 2016-10-05 北京中科同向信息技术有限公司 Technique based on data replication
CN104809199B (en) * 2015-04-24 2018-11-16 联动优势科技有限公司 A kind of method and apparatus of database synchronization
CN104834694A (en) * 2015-04-24 2015-08-12 同程网络科技股份有限公司 OTA-based quick and intelligent report form processing method
CN105045678B (en) * 2015-07-09 2018-10-26 小米科技有限责任公司 Database restoring method and device
CN105069059A (en) * 2015-07-28 2015-11-18 小米科技有限责任公司 Database synchronization method and apparatus
CN104965935B (en) * 2015-08-06 2018-10-12 上海携程商务有限公司 The update method of network monitoring daily record
CN105117441A (en) * 2015-08-11 2015-12-02 北京思特奇信息技术股份有限公司 Data work order processing method and system
CN106802895B (en) * 2015-11-26 2020-06-02 阿里巴巴集团控股有限公司 Method and device for repairing database backup data
CN106855860A (en) * 2015-12-08 2017-06-16 阿里巴巴集团控股有限公司 Method and apparatus for creating master/slave data storehouse
CN106919496B (en) * 2015-12-28 2020-09-08 华为技术有限公司 Method, device and system for testing service continuity of database
US10545990B2 (en) * 2016-03-31 2020-01-28 Veritas Technologies Llc Replication between heterogeneous storage systems
CN110703985B (en) 2016-10-25 2021-05-18 华为技术有限公司 Data synchronization method and out-of-band management equipment
CN106779993A (en) * 2016-11-29 2017-05-31 南京信息工程大学 A kind of stateless Financial information processing and standby system and method
CN107066480B (en) * 2016-12-20 2020-08-11 创新先进技术有限公司 Method, system and equipment for managing main and standby databases
CN108733699A (en) * 2017-04-19 2018-11-02 北京京东尚科信息技术有限公司 Database leader follower replication system, method and apparatus
CN107229541B (en) * 2017-06-20 2019-11-26 携程旅游信息技术(上海)有限公司 Backup method, standby system and the server of Transaction Information
CN107741950A (en) * 2017-09-05 2018-02-27 北京趣拿软件科技有限公司 Processing method, device, processor and the service end of data syn-chronization task
CN108038028B (en) * 2017-12-13 2021-03-23 北信源系统集成有限公司 File backup method and device and file restoration method and device
CN108200220B (en) * 2018-04-08 2021-07-23 武汉斗鱼网络科技有限公司 Data synchronization method, server and storage medium
CN108573060A (en) * 2018-04-26 2018-09-25 北京恒华伟业科技股份有限公司 A kind of method of data synchronization and system based on spring boot plug-in units
CN108900497B (en) * 2018-06-25 2021-11-02 江苏欧软信息科技有限公司 Method and system for data synchronization between heterogeneous systems
CN110766371A (en) * 2018-07-27 2020-02-07 视联动力信息技术股份有限公司 Office automation data synchronization method and system
CN109885622B (en) * 2019-01-18 2021-07-16 广州虎牙信息科技有限公司 Data processing equipment, system and multi-node data processing method
CN109933630B (en) * 2019-03-19 2021-11-23 武汉达梦数据库股份有限公司 Real-time database data synchronization method and device
CN110442643A (en) * 2019-07-05 2019-11-12 苏州浪潮智能科技有限公司 A kind of file synchronisation method and device for two-node cluster hot backup
CN110851527B (en) * 2019-09-24 2022-12-06 福建星网智慧科技有限公司 Data synchronization method for main and standby servers
CN110727733B (en) * 2019-09-25 2023-07-14 许昌许继软件技术有限公司 A kind of primary and secondary server system and data synchronization method
CN111241198B (en) * 2020-01-02 2024-02-27 广州虎牙科技有限公司 Data synchronization method and device and data processing equipment
CN111831661A (en) * 2020-07-20 2020-10-27 江苏云柜网络技术有限公司 Database filing method based on express business logic
CN112307054B (en) * 2020-11-18 2023-02-28 太原理工大学 A method for reading and writing active-active database active and standby servers
CN114531394B (en) 2020-11-20 2023-11-17 华为技术有限公司 Data synchronization method and device
CN113609232B (en) * 2021-10-08 2021-12-03 武汉四通信息服务有限公司 Data management method, data management system, and computer-readable storage medium
CN114187073A (en) * 2021-12-13 2022-03-15 平安证券股份有限公司 Order information processing method and device, computer equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1437348A (en) * 2002-02-04 2003-08-20 深圳市中兴通讯股份有限公司 Real-time synchronizing method for data in both main and spare board in communication system
US20040153624A1 (en) * 2002-10-29 2004-08-05 Brocade Communications Systems, Inc. High availability synchronization architecture
CN1561022A (en) * 2004-03-04 2005-01-05 中兴通讯股份有限公司 Method of internal data base main-spare synchronous
CN1851657A (en) * 2005-07-21 2006-10-25 上海华为技术有限公司 Dual-machine back-up realizing method and system
US20060271813A1 (en) * 2005-05-26 2006-11-30 David Horton Systems and methods for message handling among redunant application servers

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1437348A (en) * 2002-02-04 2003-08-20 深圳市中兴通讯股份有限公司 Real-time synchronizing method for data in both main and spare board in communication system
US20040153624A1 (en) * 2002-10-29 2004-08-05 Brocade Communications Systems, Inc. High availability synchronization architecture
CN1561022A (en) * 2004-03-04 2005-01-05 中兴通讯股份有限公司 Method of internal data base main-spare synchronous
US20060271813A1 (en) * 2005-05-26 2006-11-30 David Horton Systems and methods for message handling among redunant application servers
CN1851657A (en) * 2005-07-21 2006-10-25 上海华为技术有限公司 Dual-machine back-up realizing method and system

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110096389A (en) * 2019-04-30 2019-08-06 上海达梦数据库有限公司 A kind of starting method, apparatus, equipment and the storage medium of database

Also Published As

Publication number Publication date
CN101038591A (en) 2007-09-19

Similar Documents

Publication Publication Date Title
CN100449548C (en) Database synchronization method and system
US11907254B2 (en) Provisioning and managing replicated data instances
CN113396407A (en) System and method for augmenting database applications using blockchain techniques
US11010267B2 (en) Method and system for automatic maintenance of standby databases for non-logged workloads
TW497071B (en) Method and apparatus for managing clustered computer systems
US10503699B2 (en) Metadata synchronization in a distrubuted database
US9286368B2 (en) Linking framework for information technology management
JP2025522399A (en) End-to-end resumability of cross-region replication with new replication
US10565071B2 (en) Smart data replication recoverer
US20060123057A1 (en) Internally consistent file system image in distributed object-based data storage
WO2019184775A1 (en) Management data storage method and device, and storage medium
US12124474B2 (en) Real-time masking in a standby database
US20200301787A1 (en) Systems and methods for non-blocking backups
JP7644205B2 (en) Switching to eventually consistent database replication
CN111125001A (en) Snap copy method, electronic device, and computer program product
CN118796932A (en) Data synchronization method, device, equipment and storage medium
CN100362760C (en) A Backup Method for Distributed Configuration Database System
US20200401567A1 (en) Object Storage System with Versioned Meta Objects
US20230126173A1 (en) Methods, devices and systems for writer pre-selection in distributed data systems
CN113297134A (en) Data processing system, data processing method and device, and electronic device
CN115297129B (en) Method and device for establishing data communication network
CN116319832A (en) Method, terminal and control system for AD domain account asset disaster recovery
CN116501544A (en) Database backup method and system, electronic equipment and storage medium
HK40059162A (en) Data processing system, data processing method, data processing device and electronic equipment
HK40059162B (en) Data processing system, data processing method, data processing device and electronic equipment

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20090107