Embodiment
Below by drawings and Examples, technical scheme of the present invention is described in further detail.
The schematic flow sheet of a kind of database synchronization method that Fig. 1 provides for the embodiment of the present invention.In the present embodiment, the executive agent of the method can be database synchronization device.As shown in Figure 1, the method comprises the following steps:
101, monitor the daily record of source database, catch the data variation information of described source database.
Particularly, database synchronization device is monitored the daily record of source database, and when the daily record of source database changes, database synchronization device captures the data variation information of this source database.For example, source database can be structured query sentence (Structured Query Language is called for short SQL) database, and corresponding, data variation information can be SQL data variation statement.
102, determine the type for the treatment of each synchronous target database.
In practical application, database synchronization device can be connected with a plurality of databases, and after getting data variation information, database synchronization device can be determined the type for the treatment of each synchronous target database.In the present embodiment, the type of target database comprises: the complete backup database of source database, the incremental backup database of source database, for store data variation information document data bank, with the database of source database isomery, in the present embodiment, source database is relevant database, and with the database of source database isomery be internal memory type database.For the ease of expressing and distinguishing dissimilar database, the incremental backup database that in the present embodiment, the complete backup database of source database is called to the first database, source database is called the second database, internal memory type database is called the 3rd database and will be called the 4th database for storing the document data bank of data variation information.
103, obtain the synchronization rules corresponding with the type of each target database.
In the present embodiment, synchronization rules corresponding to pre-stored all types of target database in database synchronization device.After determining the type of target database, database synchronization device, according to the type of each target database, obtains and the corresponding synchronization rules of all types of target database.Particularly, mapping relations in database synchronization device between the type identification of pre-stored target database and synchronization rules sign, after determining the type of target database, according to the type identification for the treatment of each synchronous target database, inquire about above-mentioned mapping relations, can get the synchronization rules sign corresponding with each target database, the synchronization rules sign corresponding according to each target database, obtains the synchronization rules corresponding with each target database.
104, according to described data variation information and described synchronization rules corresponding to each target database, each target database and described source database are carried out to data and synchronize.
Particularly, if treat that the type of synchronous target database is the first database, during the database of i.e. the first database backup completely that is source database, the synchronization rules corresponding with the first database getting is: according to the data variation information getting, all data variation in source database are synchronized in this first database.
If treat that the type of synchronous target database is the second database, the incremental backup that the second database is source database, the synchronization rules corresponding with the second database getting is: from data variation information, obtain the first data variation information corresponding with the second database, data variation corresponding to the first data variation information is synchronized in the second database.
If treat that the type of synchronous target database is the 3rd database, wherein, source database is relevant database, the 3rd database is internal memory type database, the synchronization rules corresponding with the 3rd database getting comprises in default source database the mapping relations between tables of data in tables of data and the 3rd database, obtain the second data variation information relevant to tables of data in source database, according to described the second data variation information and this mapping relations, data variation corresponding to the second data variation information is synchronized in the 3rd database.
If treat that the type of synchronous target database is the 4th database, the 4th database is that the synchronization rules corresponding with the 4th database getting is: data variation information is stored in the 4th database for storing the file based database application of data variation information.
Correspondingly, when target database is the first database, database synchronization device, according to this data variation information and synchronization rules corresponding to the first database, is synchronized to all data variation in source database in this first database.
Correspondingly, when target database is the second database, database synchronization device obtains the first data variation information that this second database is corresponding from data variation information, then data variation corresponding to the first data variation information is synchronized in the second database.For example, the second database is the backup database of some subsets in source database, the data variation information that database synchronization device obtains this subset from data variation information i.e. the first data variation information, then according to this first data variation information, the data variation of this subset is synchronized in the second database, so just can guarantees synchronizeing of the second database and this subset in source database.
Correspondingly, when target database is the 3rd database, mapping relations between tables of data in tables of data and the 3rd database in source database in synchronization rules corresponding to database synchronization device inquiry the 3rd database, based on tables of data in source database in mapping relations, obtain the second data variation information relevant to tables of data in source database, according to this second data variation information and above-mentioned mapping relations, data variation corresponding to the second data variation information is synchronized in the tables of data in the 3rd database.The present embodiment has been realized synchronizeing of relevant database and internal memory type database.
Correspondingly, when target database is the 4th database, database synchronization device is synchronized to data variation information in the 4th database.
Further, database synchronization device can also carry out in synchronizing process at source database and target database, and whether monitoring data sync break occurs, for example, target database, because hardware or network failure cause data synchronously cannot carry out, will cause the synchronous interruption of data.When monitoring described data sync break, record the point of interruption that described data sync break occurs, after described data sync break is recovered, the data variation after the described point of interruption is synchronized in described target database guaranteeing.
Further, database synchronization device, after getting data variation information, can also carry out pre-service to data change information, for example, when data variation information is SQL data variation statement, this SQL data variation statement is resolved, obtain data variation information.
Database synchronization device can also get the key word of each data variation information, then according to key word, data change information is filtered, and to reduce, treats synchronous data volume.In the present embodiment, a list for data change information is filtered is set in database synchronization device, in this list, store the key word for filtering, when key word that data variation information that database synchronization device listens to comprises is in this list during key word, this data variation information filtering is fallen, treat that so synchronous data variation information just can be simplified, thereby reduced the data volume for the treatment of synchronous data, reduce the wasting of resources, improve the synchronous efficiency between database.Wherein above-mentioned list can be arranged according to the actual requirements flexibly by managerial personnel.
And database synchronization device can adopt message queue mechanism, data variation information is sent in Message queue, database synchronization device is based on message queue to all data variation information, and the data between fulfillment database are synchronous.Alternatively, database synchronization device can also carry out buffer memory to data change information, to avoid the loss of data variation information.
The database synchronization method that the present embodiment provides can be applied in Railway Passenger Ticket System, and Railway Passenger Ticket System comprises Railway Passenger Ticket System and the internet Railway Passenger Ticket System based on internal memory type database based on traditional relational database at present.Database synchronization method hardware or software that execution the present embodiment is provided, be arranged between the database and the database in internet Railway Passenger Ticket System in traditional railway Ticketing and Reservation System, using the database in traditional railway Ticketing and Reservation System wherein as source database, database synchronization device is monitored the data variation information of source database, then determine the type of database in internet Railway Passenger Ticket System, and then obtain corresponding synchronization rules, based on synchronization rules and data variation information, data variation is synchronized in the database of this internet Railway Passenger Ticket System, so just realizing traditional railway Ticketing and Reservation System synchronizes with the data between internet Ticketing and Reservation System.
The database synchronization method that the present embodiment provides, monitor the daily record of source database, catch the data variation information of source database, determine the type for the treatment of each synchronous target database, according to the type of each target database, obtain the synchronization rules corresponding with the type of each target database, according to data variation information and synchronization rules corresponding to each target database, each target database and source database are carried out to data and synchronize.In the present embodiment, for dissimilar target database, set up different synchronization rules, after getting the data variation information of source database, based on synchronization rules corresponding to each target database, target database and source database are carried out to data synchronizes, overcome the data variation Information Problems that needs multi collect source database in prior art, reduce the wasting of resources, and improved the synchronous efficiency between database.
The structural representation of a kind of database synchronization device that Fig. 2 provides for the embodiment of the present invention.As shown in Figure 2, this database synchronization device comprises: trapping module 21, determination module 22, acquisition module 23 and synchronization module 24.
Particularly, the daily record of 21 pairs of source databases of trapping module is monitored, and when the daily record of source database changes, can capture the data variation information of this source database.For example, source database can be SQL database, and corresponding, data variation information can be SQL data variation statement.
In practical application, database synchronization device can be connected with a plurality of databases.Trapping module 21 is connected with determination module 22, and after getting data variation information, determination module 22 can be determined the type for the treatment of each synchronous target database.In the present embodiment, the type of target database comprises: the complete backup database of source database, the incremental backup database of source database, for store data variation information document data bank, with the database of source database isomery, in the present embodiment, source database is relevant database, and with the database of source database isomery be internal memory type database.For the ease of expressing and distinguishing dissimilar database, the incremental backup database that in the present embodiment, the complete backup database of source database is called to the first database, source database is called the second database, internal memory type database is called the 3rd database and will be called the 4th database for storing the document data bank of data variation information.
In the present embodiment, synchronization rules corresponding to pre-stored all types of target database in database synchronization device.Determination module 22 is connected with acquisition module 23, determines after the type of target database at determination module 22, and acquisition module 23, according to the type of each target database, obtains and the corresponding synchronization rules of all types of target database.Particularly, mapping relations in database synchronization device between the type identification of pre-stored target database and synchronization rules sign, after determining the type of target database, acquisition module 23 is according to treating that the type identification of each synchronous target database inquires about above-mentioned mapping relations, can get the synchronization rules sign corresponding with each target database, the synchronization rules sign corresponding according to each target database, obtains the synchronization rules corresponding with each target database.
Particularly, if treat that the type of synchronous target database is the first database, during the database of i.e. the first database backup completely that is source database, the synchronization rules corresponding with the first database getting is: according to the data variation information getting, all data variation in source database are synchronized in this first database.
If treat that the type of synchronous target database is the second database, the incremental backup that the second database is source database, the synchronization rules corresponding with the second database getting is: from data variation information, obtain the first data variation information corresponding with the second database, data variation corresponding to the first data variation information is synchronized in the second database.
If treat that the type of synchronous target database is the 3rd database, wherein, source database is relevant database, the 3rd database is internal memory type database, the synchronization rules corresponding with the 3rd database getting comprises in default source database the mapping relations between tables of data in tables of data and the 3rd database, obtain the second data variation information relevant to tables of data in source database, according to described the second data variation information and this mapping relations, data variation corresponding to the second data variation information is synchronized in the 3rd database.
If treat that the type of synchronous target database is the 4th database, the 4th database is that the synchronization rules corresponding with the 4th database getting is: data variation information is stored in the 4th database for storing the file based database application of data variation information.
In the present embodiment, acquisition module 23 is connected with synchronization module 24.At acquisition module 23, get after synchronization rules corresponding to each target database, synchronization module 24, according to the synchronization rules of data variation information and each target database, carries out data by each target database and source database and synchronizes.
Correspondingly, when target database is the first database, synchronization module 24, according to the data variation information and synchronization rules corresponding to the first database that get, is synchronized to all data variation in source database in this first database.
Correspondingly, when target database is the second database, synchronization module 24 obtains the first data variation information corresponding with this second database from data variation information, then data variation corresponding to the first data variation information is synchronized in the second database.For example, the second database is the backup database of some subsets in source database, the data variation information that database synchronization device obtains this subset from data variation information i.e. the first data variation information, then according to this first data variation information, the data variation of this subset is synchronized in the second database, so just can guarantees synchronizeing of the second database and this subset in source database.
Correspondingly, when target database is the 3rd database, mapping relations between tables of data in tables of data and the 3rd database in source database in synchronization rules corresponding to synchronization module 24 inquiry the 3rd databases, based on tables of data in source database in mapping relations, obtain the second data variation information relevant to tables of data in source database, according to this second data variation information and above-mentioned mapping relations, data variation corresponding to the second data variation information is synchronized in the tables of data in the 3rd database.The present embodiment has been realized synchronizeing of relevant database and internal memory type database.
Correspondingly, when target database is the 4th database, synchronization module 24 is synchronized to data variation information in the 4th database.
Further, database synchronization device can also carry out in synchronizing process at source database and target database, by synchronization module 24 monitorings, whether there is data sync break, for example, target database, because hardware or network failure cause data synchronously cannot carry out, will cause the synchronous interruption of data.When monitoring described data sync break, and record the point of interruption that described data sync break occurs, after described data sync break is recovered, the data variation after the described point of interruption is synchronized in described target database guaranteeing.
Further, after getting data variation information, trapping module 21 can also carry out pre-service to data change information, for example, when data variation information is SQL data variation statement, this SQL data variation statement is resolved, and obtains data variation information.
Trapping module 21 can also get the key word of each data variation information, then according to key word, data change information is filtered, and to reduce, treats synchronous data volume.In the present embodiment, a list for data change information is filtered is set in database synchronization device, in this list, store the key word for filtering, when key word that data variation information that trapping module 21 listens to comprises is in this list during key word, this data variation information filtering is fallen, treated that so synchronous data variation information just can be simplified, thereby reduced, treat synchronous data data volume, reduce the wasting of resources, improve the synchronous efficiency between database.Wherein above-mentioned list can be arranged according to the actual requirements flexibly by managerial personnel.
And synchronous device 24 can adopt message queue mechanism, data variation information is sent in Message queue, then based on message queue to all data variation information, the data between fulfillment database are synchronous.Alternatively, database synchronization device can also carry out buffer memory to data change information, to avoid the loss of data variation information.
At present Railway Passenger Ticket System comprises Railway Passenger Ticket System based on traditional relational database and the railway internet Ticketing and Reservation System based on memory database.The database synchronization device that the present embodiment provides, can be applied in Railway Passenger Ticket System.Executing data synchronous device is arranged between traditional railway Ticketing and Reservation System and internet Railway Passenger Ticket System, using the database in traditional railway Ticketing and Reservation System wherein as source database, database synchronization device is monitored the data variation information of source database, then determine the type of database in internet Railway Passenger Ticket System, obtain corresponding synchronization rules, based on synchronization rules and data variation information, data variation is synchronized in the database in this internet Railway Passenger Ticket System, so just realizing traditional railway Ticketing and Reservation System synchronizes with the data between internet Ticketing and Reservation System.
The database synchronization device that the present embodiment provides, monitor the daily record of source database, catch the data variation information of source database, determine the type for the treatment of each synchronous target database, according to the type of each target database, obtain the synchronization rules corresponding with the type of each target database, according to described data variation information and described synchronization rules corresponding to each target database, each target database and described source database are carried out to data and synchronize.In the present invention, for dissimilar target database, set up different synchronization rules in advance, after getting the data variation information of source database, based on synchronization rules corresponding to each target database and data variation information, each target database and source database are carried out to data synchronizes, overcome the data variation Information Problems that needs multi collect source database in prior art, reduce the wasting of resources, and improved the synchronous efficiency between database.
The structural representation of a kind of database synchronous system that Fig. 3 provides for the embodiment of the present invention.As shown in Figure 3, this database synchronous system comprises: database synchronization device 1, source database 2 and at least one target database 3.
Wherein, database synchronization device 1 is the database synchronization device that above-described embodiment provides, and is arranged between source database 2 and target database 3, for realizing source database 2, synchronizes with the data of target database 3.Relevant introduction about database synchronization device 1 can, referring to the record of related content in above-described embodiment, repeat no more herein.
In the present embodiment, for dissimilar target database, set up different synchronization rules in advance, after getting the data variation information of source database, based on synchronization rules corresponding to each target database, target database is carried out to data synchronous, overcome the data variation Information Problems that needs multi collect source database in prior art, reduce the wasting of resources, and improved the synchronous efficiency between database.
Finally it should be noted that: each embodiment, only in order to technical scheme of the present invention to be described, is not intended to limit above; Although the present invention is had been described in detail with reference to aforementioned each embodiment, those of ordinary skill in the art is to be understood that: its technical scheme that still can record aforementioned each embodiment is modified, or some or all of technical characterictic is wherein equal to replacement; And these modifications or replacement do not make the essence of appropriate technical solution depart from the scope of various embodiments of the present invention technical scheme.