WO2014090002A1 - 一种数据同步的方法、装置及系统 - Google Patents

一种数据同步的方法、装置及系统 Download PDF

Info

Publication number
WO2014090002A1
WO2014090002A1 PCT/CN2013/083584 CN2013083584W WO2014090002A1 WO 2014090002 A1 WO2014090002 A1 WO 2014090002A1 CN 2013083584 W CN2013083584 W CN 2013083584W WO 2014090002 A1 WO2014090002 A1 WO 2014090002A1
Authority
WO
WIPO (PCT)
Prior art keywords
file
configuration
data
verification
data file
Prior art date
Application number
PCT/CN2013/083584
Other languages
English (en)
French (fr)
Inventor
任志鸿
魏霄鹏
徐双桑
Original Assignee
中兴通讯股份有限公司
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 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2014090002A1 publication Critical patent/WO2014090002A1/zh

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes

Definitions

  • the present invention relates to the field of communications, and in particular, to a method, apparatus and system for data synchronization. Background technique
  • data synchronization technology has a wide range of applications.
  • the mainstream data synchronization methods include message synchronization and file synchronization.
  • the efficiency is low when dealing with large data volume synchronization, and the reliability is also poor.
  • the file synchronization method makes up for this defect, but its The main application method is only for the data on a specific server, and the configuration and deployment are separately implemented to complete a specific function.
  • This type of application has a relatively simple function and lacks versatility and flexibility. Specifically, when the system data needs to be cutover or expanded, the same data synchronization module must be reconfigured and deployed on the newly added server.
  • the data synchronization file is split into multiple copies, which causes problems such as inconsistent number of synchronization files and naming conflicts.
  • the subsequent related interfaces must be modified, which brings a series of thorny problems, not only complicated configuration, but also increased maintenance costs. The risk of upgrading is also increasing.
  • the embodiment of the invention provides a method, a device and a system for synchronizing data, so as to solve the problem that the file synchronization mode can only be synchronized for a specific function of a specific server in the prior art, and the versatility is poor.
  • an embodiment of the present invention provides a data synchronization method, including::, according to a configuration of a configuration file, extracting, from a database server, a current task Data file; According to the configuration of the configuration file, the data file is uploaded to the specified first target address to complete data synchronization.
  • the method further includes: generating, according to the configuration of the configuration file, a verification file corresponding to the verification data file, The verification file includes attribute information of the data file; and the data file and the verification file cooperation data file are uploaded together to the designated first target address.
  • the data file required to export the current task from the database server according to the configuration of the configuration file includes: determining, according to the database information configuration item in the configuration file, database information corresponding to the current task; Database information, determining a database server corresponding to the currently-used task, and connecting with the determined database server; executing an export script file in the configuration file, and extracting data required by the current task from the determined database server file.
  • the generating, according to the configuration of the configuration file, the verification file for verifying the data file comprises: analyzing, according to the configuration of the configuration file, an attribute of the exported data file; generating a location according to the analysis result
  • the verification file includes at least one of the following: a name of the data file, a size of the data file, a number of records of the data file, and a time parameter of the data file.
  • the method before uploading the data file and the verification file to the specified first target address, the method further includes: determining whether the current task needs to perform a merge operation; when a merge operation needs to be performed, Uploading the data file and the verification file to a specified second target address, and combining the data files in the second target address according to a configuration item of the merged node in the configuration file, and/or The verification documents are merged.
  • the configuration item of the merged node includes at least one of the following: a path of the source file before the merge, a merge file type, a file check number, a merged file split maximum record threshold, a file split sequence number length, and a merged file header.
  • the embodiment of the present invention further provides an apparatus for data synchronization, including: a data exporting unit configured to: derive, according to a configuration of a configuration file, a data file required by a current task from a database server; The configuration of the configuration file uploads the data file to a specified first target address to complete data synchronization.
  • a data exporting unit configured to: derive, according to a configuration of a configuration file, a data file required by a current task from a database server; The configuration of the configuration file uploads the data file to a specified first target address to complete data synchronization.
  • the device further includes: a verification file generating unit, configured to generate, according to the configuration of the configuration file, a verification file for verifying the data file, where the verification file includes attribute information of the data file
  • the uploading unit is configured to upload the verification file together with the data file to the designated first target address.
  • the data deriving unit includes: a first determining module, configured to determine, according to a database information configuration item in the configuration file, database information corresponding to the current task; and a second determining module configured to be determined according to the determined database Information, determining a database server corresponding to the currently-used task, and connecting with the determined database server; executing an module, configured to execute an export script file in the configuration file, and exporting the current task from the determined database server The required data file.
  • a first determining module configured to determine, according to a database information configuration item in the configuration file, database information corresponding to the current task
  • a second determining module configured to be determined according to the determined database Information, determining a database server corresponding to the currently-used task, and connecting with the determined database server
  • executing an module configured to execute an export script file in the configuration file, and exporting the current task from the determined database server The required data file.
  • the verification file generating unit includes: an analysis module, configured to analyze the attributes of the exported data file according to the configuration of the configuration file; and the generating module is configured to generate the verification file according to the analysis result, where
  • the verification file includes at least one of the following: a name of the data file, a size of the data file, a number of records of the data file, and a time parameter of the data file.
  • the device further includes: a determining unit, configured to determine whether the current task needs to perform a merge operation before uploading the data file and the verification file to the specified first target address; And configuring, when the determining unit determines that the merging operation needs to be performed, uploading the data file and the verification file to a specified second target address, according to the configuration item of the merged node in the configuration file, in the The data in the two target addresses
  • the documents are merged and/or the verification files are merged.
  • the embodiment of the present invention further provides a data synchronization system, including: a database client, a database server, and the foregoing device for synchronizing data, wherein the device for synchronizing data is connected to a database client, configured to pass the The database client accesses the database server.
  • data files required for different tasks in the data synchronization process are acquired by different configurations of the configuration files to complete data synchronization of different tasks, and the data synchronization manner effectively solves the related technologies. Synchronization can only be synchronized for specific functions of a particular server, and the problem of poor versatility increases the flexibility of data synchronization.
  • FIG. 1 is a preferred flowchart of a method for data synchronization in the first embodiment of the present invention
  • FIG. 2 is a preferred flowchart of deriving a data file in a method for data synchronization in the first embodiment of the present invention
  • FIG. 3 is a preferred flow chart of a merged file in a method for data synchronization in Embodiment 1 of the present invention
  • FIG. 5 is a block diagram of a preferred structure of the apparatus for data synchronization in the second embodiment of the present invention
  • FIG. 6 is a block diagram of another preferred structure of the apparatus for data synchronization in the second embodiment of the present invention
  • FIG. 8 is a block diagram showing another preferred structure of the apparatus for data synchronization in the second embodiment of the present invention.
  • the file synchronization mode can only be targeted to specific functions of a specific server.
  • the present invention provides a method, an apparatus, and a system for data synchronization. The present invention will be described in detail below with reference to the accompanying drawings. It should be noted that the embodiments in the present application and the features in the embodiments may be combined with each other without conflict.
  • FIG. 1 shows a preferred flow chart of the method. As shown in FIG. 1, the method includes the following steps:
  • the database client accesses the database server, and sends a related instruction to the database server according to the configuration item of the configuration file.
  • the instruction may be an executable export statement for exporting the data file, or may be a SQL script file.
  • a database client is installed in the system for data synchronization, and the client is provided with the ability to remotely access and operate the database server.
  • the database server mainly stores various original data resources, and can be exported to the external system when needed.
  • the raw data resources can be distributed and backed up on multiple database servers.
  • an executable export statement or a SQL export script file is sent to the corresponding database server, and the generated data file is returned according to the execution result.
  • the configuration file can support the multi-tasking multi-database mode, that is, the configuration file can support multiple data file export tasks at the same time, and each of the export tasks is independent of each other, and each task can access and operate multiple databases. And export the data file.
  • each task of the configuration file is configured as a structured node, and the node configuration is extensible, and the new export task configuration can be added by copying the entire node, and the configuration can be slightly modified according to the specific situation.
  • each node configuration of the configuration file generally includes the following configuration items: database information configuration, export script file configuration item (including pre-export SQL statement) Configuration, export SQL statement configuration, SQL statement configuration after export, export data file name configuration, export data file storage path configuration, etc.
  • S104 Upload the data file to the specified first target address according to the configuration of the configuration file to complete data synchronization.
  • the method further includes: generating, according to the configuration of the configuration file, a verification file for verifying the data file, where the verification file includes the data file Attribute information; upload the verification file collaborative data file to the specified first destination address.
  • the attributes of the data file exported above are analyzed, and recorded, and a verification file is generated according to the analysis result, and the result of the recording is used as a verification file, and the verification file is used to verify the generated data file.
  • the verification file includes but is not limited to the following parameters: a name of the data file, a size of the data file, a number of records of the data file, and a time parameter of the data file.
  • the recording rule of the verification file can be as follows: no file header, one line is a record, ending with " ⁇ r ⁇ n", and the separators are sequentially connected between the fields of each record.
  • the content includes the export data file name, file size, total file number, and file generation date and time.
  • the verification file can be configured to implement three generation modes: no generation, - corresponding generation mode, and one-to-many mode.
  • —— corresponding generation mode that is, one verification file records only one exported data file
  • one-to-many mode that is, one verification file records multiple exported data files.
  • the contents of the verification file support a free combination configuration, which allows you to selectively record data file attributes.
  • the supportable variable substitution includes exporting the data file name
  • FTP File Transfer Protocol
  • FTP is a protocol for transferring files between two computers on a TCP/IP network.
  • the uploading process supports the multitasking mode, and each task is independent of each other, and each task is configured as a structured node.
  • the node configuration is extensible, and the new uploading task configuration can be added by copying the entire node. It needs to be modified as needed.
  • Each node configuration usually includes an upload file type, a peer server IP address, an FTP designated port, an FTP user name, an FTP password, and an FTP remote path.
  • the failed retransmission mechanism is further supported. Specifically, before the uploading, it is determined whether the connection and the login remote server are normal, and the normal connection is started, and the synchronous upload is started. If the upload fails, the retransmission is continued.
  • the alarm module is configured to receive various alarm and error notification messages, and is saved in the library. The user can query and display the alarm information through the inspection tool.
  • the notification message generally includes the sender process ID, service type identifier, alarm level, error code, and error description information.
  • the log module can be used to record the operation steps and execution of each module, which is convenient for tracking and locating problems.
  • data files required for different tasks in the data synchronization process are acquired by different configurations of the configuration files to complete data synchronization of different tasks, and the data synchronization manner effectively solves the related technologies. Synchronization can only be synchronized for specific functions of a particular server, and the problem of poor versatility increases the flexibility of data synchronization.
  • the foregoing method is further optimized, and specifically, a solution for extracting a data file required by a current task from a database server according to a configuration of a configuration file is provided.
  • the method includes the following steps: determining, according to the database information configuration item in the configuration file, the database information corresponding to the current task; determining the database server corresponding to the current task according to the determined database information, and connecting with the determined database server; The export script file in the line configuration file, which exports the data files required for the current task from the determined database server.
  • the database information configuration item is a set of strings and is extensible, supporting multi-line configuration.
  • the configuration rules are as follows: Yes, the fields are separated by a line, and the separators are sequentially connected, which are the database type, the database service name, the login user name, the login password, and the export process file name.
  • exporting script files (such as the configuration of SQL statements before and after export) also supports multi-line configuration, where the system recognizes and assembles them into SQL script files.
  • each SQL statement configuration and file name configuration also supports date variable substitution, including YYYYY,
  • MM DD
  • DD DD
  • YYYYMMDD indicates the current year, month and day.
  • Figure 2 shows a preferred flow chart for exporting a data file, as shown in Figure 2, which mainly includes the following steps:
  • Step 202 At the beginning of the process, the system determines whether the scheduled task time has arrived. If the time arrives, step 204 is performed. Otherwise, it returns and continues to wait.
  • Step 204 Find a task from the task list. If the task does not exist or has been completed, return to the end. Otherwise, proceed to step 206.
  • Step 206 Obtain a corresponding configuration item set of the task according to the task and the configuration node mapping relationship.
  • Step 208 Parse the configuration item set, decompose the database information configuration and save, perform variable substitution processing on the export file name configuration, perform variable replacement processing on all SQL statement configurations, generate a SQL script file, and then proceed to step 210.
  • Step 210 Obtain a database information from the database information configuration, where the database information includes: a database type, a database service name, a login user name, a login password, and an export process file name. If the obtaining is successful, proceed to step 212, otherwise, enter Step 214.
  • Step 212 Remotely connect and log in to the database server according to the obtained database information.
  • the operation executes the SQL export script and generates a data file based on the returned result.
  • Step 214 ending the task, saving the data file to the specified directory. Then go to step 204 to start the next task.
  • the foregoing method is further optimized. Specifically, before uploading the data file and the verification file to the specified first target address, the method further includes: determining whether the current task needs to perform a merge operation If the judgment result is yes, the data file and the verification file are uploaded to the designated second target address, and the data files are merged and/or verified in the second target address according to the configuration item of the merged node in the configuration file. Consolidate.
  • files of the specified type in the specified server directory are checked and merged to generate a new data file.
  • This function is optional.
  • the system loads the function, and merges the data files and/or check files exported from the database on the cut-off multiple servers. The merged file name remains. Consistent with the cutover upgrade.
  • each task is independent of each other, and each task is configured by a structured node.
  • the node configuration is extensible, and a new merge task configuration can be added by copying the entire node.
  • Each node configuration usually includes at least one of the following: a local path where the source file is merged, a merge file type, a file check number, a merged file split maximum record threshold, a file split serial number length, a merged file header content configuration, and then The file name, the local save path of the merged file, the original file backup directory and save time, and whether file compression is supported.
  • the merge file type supports a wildcard pattern.
  • a wildcard is a special statement that has an asterisk (*) and a question mark (?), which are used to blur search files.
  • the number of file check refers to the source file directory before the merge, and the retrieved file type contains the minimum number of files to meet the merge requirements.
  • the merged file supports the file header configuration. If not configured, there is no file header.
  • the specific content can be directly described by configuration.
  • the replacement variables that can be included in the configuration are: Number ⁇ totalnum ⁇ and datetime ⁇ datetime ⁇ .
  • the merged file also supports maximum record threshold segmentation. Specifically, if the configuration is empty, the file record size is not limited. Otherwise, when the number of records limited by the file is exceeded, the merged file is split and split, and the split file is renamed according to the file split serial number length and location configuration. Assign a name.
  • file name configuration also supports date variable substitution, including YYYY, ⁇ , DD, and can be freely combined, such as YYYYMMDD indicates the current year, month, and day.
  • the split serial number is implemented by replacing the ⁇ SEQ ⁇ variable with the configuration variable at the file name location. Assume that the file split serial number length is 4, and the merged file name is configured as follows:
  • the merged file is compressed, the original data file is copied to a specified directory for backup, and the expired file in the backup directory is periodically cleaned.
  • FIG. 3 is a flowchart of an implementation of a merged file. As shown in FIG. 3, the method includes the following steps: Step 302: At the beginning of the process, the system determines whether the scheduled task time has arrived. If the time arrives, step 304 is performed. Otherwise, , return to continue waiting.
  • Step 304 Find a task from the task list. If the task does not exist or has been completed, the process returns to the end. Otherwise, the process proceeds to step 306.
  • Step 306 Acquire a corresponding configuration item set of the task according to the task and the configuration node mapping relationship.
  • step 308 the file in the target directory configured by the task is filtered to check whether the file type is consistent with the file type, whether the file header is consistent with the configuration, whether the file content is empty, and whether the number of files meets the minimum required to be merged. Value, etc., then proceeds to step 310.
  • Step 310 Perform content merge processing on the files that meet the requirements in the target directory, write them into a temporary file, and copy the source files to the backup directory, and then proceed to step 312.
  • step 312 the total number of records of the temporary file is checked and determined. If the threshold set by the file division rule is exceeded, the process proceeds to step 314. Otherwise, the process proceeds to step 316.
  • step 314 the temporary file is split according to the file division rule, and multiple data files are generated. These data file names are obtained by variable substitution to obtain the split serial number value, which is incremented in sequence with the number of file splits. In the merged file name configuration item, the split serial number location supports free configuration. Then, proceed to step 316.
  • Step 316 Change the temporary file or the split file to an official file, save it to the specified directory, end the task, and then go to step 304 to start the next task.
  • FIG. 4 shows a preferred flowchart of an FTP upload file, as shown in FIG. 4, including the following steps:
  • Step 402 At the beginning of the process, the system determines whether the scheduled task time has arrived. If the time arrives, step 404 is performed; otherwise, the return continues to wait.
  • Step 404 Find a task from the task list. If the task does not exist or has been completed, return to the end. Otherwise, proceed to step 406.
  • Step 406 Acquire a corresponding configuration item set of the task according to the task and the configuration node mapping relationship, and then proceed to step 408.
  • Step 408 Parsing the configuration item set under the task, obtaining the FTP server related information of the remote server, determining that the file to be uploaded exists in the target directory, and then performing an FTP connection and a login test. If the login is successful, the process proceeds to step 410. Otherwise, the alarm message is sent and the log is recorded, and the process proceeds to step 416.
  • Step 410 Start uploading a file that meets the file type requirement in the target directory of the task configuration, and then proceeds to step 412.
  • step 412 the result of the FTP upload return is determined. If it fails, the process proceeds to step 414. Otherwise, the process proceeds to step 416.
  • Step 414 Perform statistics on the number of FTP failures. If the number of failures is lower than the configured limit, Then, proceed to step 410, and upload again. Otherwise, send an alarm message and record the log, and go to step 416.
  • Step 416 Transfer the file in the target directory to the backup directory, and end the task. Then, go to step 404 to start the next task.
  • the preferred embodiment provides a device for data synchronization, and FIG. 5 shows a preferred structural block diagram of the device. As shown in FIG. 5, the device includes :
  • the data exporting unit 502 is configured to: according to the configuration of the configuration file, export the data file required by the current task from the database server; preferably, the data exporting unit 502 accesses the database server through the database client, and according to the configuration item of the configuration file, the database is The server sends the relevant instruction.
  • the instruction may be an executable export statement for exporting the data file, or may be an SQL script file.
  • a database client is installed within the system for data synchronization, and the data export unit 502 provides the ability to remotely access and operate the database server through the client.
  • the database server mainly stores various original data resources of the system, and can be exported to the external system when needed.
  • raw data resources can be distributed and backed up across multiple database servers, taking into account system load balancing and operational security factors.
  • an executable export statement or a SQL export script file is sent to the corresponding database server, and the generated data file is returned according to the execution result.
  • the configuration file can support the multi-tasking multi-database mode, that is, the configuration file can support multiple data file export tasks at the same time, and each of the export tasks is independent of each other, and each task can access and operate multiple databases. And export the data file.
  • each task of the configuration file is configured as a structured node, and the node configuration is extensible, and the new export task configuration can be added by copying the entire node, and only needs to be pressed during deployment. The details can be modified slightly.
  • the configuration of each node of the configuration file generally includes the following configuration items: database information configuration, export script file configuration items (including pre-export SQL statement configuration, export SQL statement configuration, export SQL statement configuration, export data file name configuration, Export data file storage path configuration) and so on.
  • the uploading unit 504 is connected to the data exporting unit 502 and configured to upload the data file to the designated first target address according to the configuration of the configuration file to complete data synchronization.
  • the apparatus further includes: a verification file generating unit 602, connected to the data exporting unit 502 and the uploading unit 504, configured to generate a verification file for verifying the data file according to the configuration of the configuration file,
  • the verification file includes attribute information of the data file
  • the uploading unit 504 uploads the verification file cooperation data file to the designated first target address.
  • the data file is verified according to the attribute information contained in the verification file to complete the data synchronization.
  • the verification file generating unit 602 includes: an analysis module configured to analyze an attribute of the exported data file according to the configuration of the configuration file; and a generating module configured to generate a verification file according to the analysis result, wherein the verification file includes at least the following One: the name of the data file, the size of the data file, the number of records in the data file, and the time parameter of the data file.
  • the recording rule of the verification file can be as follows: no file header, one line is a record, ending with " ⁇ r ⁇ n", and the separators are sequentially connected between the fields of each record.
  • the content includes the export data file name, file size, total file number, and file generation date and time.
  • the verification file can be configured to implement three generation modes: no generation, - corresponding generation mode, and one-to-many mode.
  • —— corresponding generation mode that is, one verification file records only one exported data file
  • one-to-many mode that is, one verification file records multiple exported data files.
  • the contents of the verification file support a free combination configuration, which can optionally record data file attributes.
  • the supported variable substitutions include export data file name ⁇ filename ⁇ , file size ⁇ filesize ⁇ , and total file records ⁇ totalline ⁇ , file generation date Period ⁇ datetime ⁇ .
  • the data file and the verification file are uploaded to the server directory specified by the external system, and the data file is verified by checking the attribute information contained in the file to ensure data synchronization.
  • the file is uploaded based on FTP synchronization.
  • FTP is a protocol for transferring files between two computers on a TCP/IP network.
  • the uploading process supports the multitasking mode, and each task is independent of each other, and each task is configured as a structured node.
  • the node configuration is extensible, and the new uploading task configuration can be added by copying the entire node. It needs to be modified as needed.
  • Each node configuration usually includes an upload file type, a peer server IP address, an FTP designated port, an FTP user name, an FTP password, and an FTP remote path.
  • the failed retransmission mechanism is further supported. Specifically, before the uploading, it is determined whether the connection and the login remote server are normal, and the normal connection is started, and the synchronous upload is started. If the upload fails, the retransmission is continued. If the number of failures exceeds the limit, the file upload failure information is sent to the alarm module, and the log is checked.
  • the alarm module is configured to receive various alarm and error notification messages and save them in the library. The user can query and display the alarm information through the inspection tool.
  • the notification message generally includes the sender process ID, service type identifier, alarm level, error code, and error description information.
  • the log module can be used to record the operation steps and execution of each module, which is convenient for tracking and locating problems.
  • data files required for different tasks in the data synchronization process are acquired by different configurations of the configuration files to complete data synchronization of different tasks, and the data synchronization manner effectively solves the related technologies. Synchronization can only be synchronized for specific functions of a particular server, and the problem of poor versatility increases the flexibility of data synchronization.
  • the foregoing apparatus is further optimized, and specifically, a scheme for extracting data files required by the current task from the database server according to the configuration of the configuration file is provided, as shown in the figure.
  • the data export unit includes: The first determining module 702 is configured to determine, according to the database information configuration item in the configuration file, the database information corresponding to the current task.
  • the second determining module 704 is connected to the first determining module 702, and configured to determine according to the determined database information.
  • the database server corresponding to the current task is connected to the determined database server; the executing module 706 is connected to the second determining module 704, configured to execute the export script file in the configuration file, and extract the current task required from the determined database server. data files.
  • the database information configuration item is a set of strings and is extensible, supporting multi-line configuration.
  • the configuration rules are as follows: Yes, the fields are separated by a line, and the separators are sequentially connected, which are the database type, the database service name, the login user name, the login password, and the export process file name.
  • exporting script files (such as the configuration of SQL statements before and after export) also supports multi-line configuration, where the system recognizes and assembles them into SQL script files.
  • each SQL statement configuration and file name configuration also supports date variable substitution, including YYYY, MM, DD, and can be freely combined, such as YYYYMMDD indicates the current year, month and day.
  • the apparatus is further optimized. Specifically, as shown in FIG. 8, the apparatus further includes: a determining unit 802 configured to upload the data file and the verification file to the designated Before the first target address, it is determined whether the current task needs to perform a merge operation; the merging unit 804 is connected to the determining unit 802, and configured to upload the data file and the verification file to the specified first when the determining unit 802 determines that the merging operation needs to be performed.
  • the second target address according to the configuration item of the merged node in the configuration file, merges the data file and/or the check file in the second target address. Specifically, according to the configuration file configuration, files of the specified type under the specified server directory are checked and merged to generate a new data file.
  • This function is optional. Generally, when the system performs data cutover or expansion, the system loads the function, and merges the data files and/or check files exported from the database on the cut-off multiple servers. The merged file name remains. Consistent with the cutover upgrade.
  • the function supports a multitasking mode, and each task is independent of each other.
  • the node configuration is extensible, and new merge task configurations can be added by copying the entire node.
  • the configuration of each node usually includes the local path where the source file is merged, the merge file type, the number of file check, the maximum record threshold of the merged file split, the file split serial number length, the merged file header content configuration, the merged file name, and the merged file name.
  • the merge file type supports a wildcard pattern.
  • a wildcard is a special statement that has an asterisk (*) and a question mark (?), which are used to blur search files.
  • the number of file check refers to the source file directory before the merge, and the retrieved file type contains the minimum number of files to meet the merge requirements.
  • the merged file supports the file header configuration. If not configured, there is no file header.
  • the specific content can be directly described by configuration.
  • the replacement variables that can be included in the configuration are: Total number of records after the merge ⁇ totalnum ⁇ and date time ⁇ datetime ⁇ .
  • the merged file also supports maximum record threshold segmentation. Specifically, if the configuration is empty, the file record size is not limited. Otherwise, when the number of records limited by the file is exceeded, the merged file is split and split, and the split file is renamed according to the file split serial number length and location configuration. Assign a name.
  • file name configuration also supports date variable substitution, including YYYY, ⁇ , DD, and can be freely combined, such as YYYYMMDD indicates the current year, month, and day.
  • the split serial number is implemented by replacing the ⁇ SEQ ⁇ variable with the configuration variable at the file name location. Assume that the file split serial number length is 4, and the merged file name is configured as follows:
  • the merged file is compressed, the original data file is copied to a specified directory for backup, and the expired file in the backup directory is periodically cleaned.
  • the data export unit, the upload unit, the check file generating unit, the judging unit, and the merging unit may be centrally processed by the device in which the data is synchronized (CPU, Central) Processing Unit), Digital Signal Processor (DSP) or Field-Programmable Gate Array (FPGA).
  • CPU Central
  • DSP Digital Signal Processor
  • FPGA Field-Programmable Gate Array
  • the preferred embodiment provides a data synchronization system, and the system includes: a database client, a database server, and the foregoing implementation.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种数据同步的方法、装置和系统,其中,该方法包括:根据配置文件的配置,从数据库服务器中导出当前任务所需的数据文件;根据配置文件的配置,将数据文件上传至指定的第一目标地址,完成数据同步。本发明有效地解决了相关技术中文件同步方式只能针对特定服务器的特定功能进行同步,通用性较差的问题,提高了数据同步的灵活性。

Description

一种数据同步的方法、 装置及系统 技术领域
本发明涉及通讯领域, 特别是涉及一种数据同步的方法、 装置和系统。 背景技术
在通信技术领域中, 数据同步技术具有广泛的应用。 目前, 主流的数 据同步方式包括消息同步和文件同步两种方式, 对于消息同步方式, 在处 理大数据量同步时效率较低, 可靠性也差; 文件同步方式虽然弥补了这种 缺陷, 但其主要应用方式还只是针对某个具体服务器上数据, 为完成某个 具体功能而单独进行实施配置部署。 这种应用方式, 功能相对单一, 通用 性和灵活性也不足, 具体来说, 当系统数据需要割接拆分或扩容时, 在新 增服务器上必须重新配置并部署相同的数据同步模块, 原始数据同步文件 被拆分成多份, 进而产生同步文件数量不一致和命名冲突等问题, 后续相 关接口都要做适应性修改, 由此带来一系列棘手问题, 不但配置复杂、 维 护成本增加, 而且升级风险也在加大。
针对现有技术中文件同步方式只能针对特定服务器的特定功能进行同 步, 通用性较差的问题, 目前尚未提出有效的解决方案。 发明内容
本发明实施例提供了一种数据同步的方法、 装置和系统, 以解决现有 技术中文件同步方式只能针对特定服务器的特定功能进行同步, 通用性较 差的问题。
为解决上述技术问题, 一方面, 本发明实施例提供一种数据同步的方 法, 包括: 根据配置文件的配置, 从数据库服务器中导出当前任务所需的 数据文件; 根据所述配置文件的配置, 将数据文件上传至指定的第一目标 地址, 完成数据同步。
优选地, 所述根据配置文件的配置, 将数据文件上传至指定的第一目 标地址时, 所述方法还包括: 根据所述配置文件的配置, 生成用于校验数 据文件对应的核查文件, 其中, 核查文件中包含数据文件的属性信息; 将 数据文件和核查文件协同数据文件一同上传至指定的所述第一目标地址。
优选地, 所述根据配置文件的配置, 从数据库服务器中导出当前任务 所需的数据文件包括: 根据所述配置文件中的数据库信息配置项, 确定当 前所述任务对应的数据库信息; 根据确定的数据库信息, 确定与当前所述 任务对应的数据库服务器, 并与确定的数据库服务器连接; 执行所述配置 文件中的导出脚本文件, 从所述确定的数据库服务器中导出当前所述任务 所需的数据文件。
优选地, 所述根据配置文件的配置, 生成用于校验所述数据文件的核 查文件包括: 根据所述配置文件的配置, 对导出的所述数据文件的属性进 行分析; 根据分析结果生成所述核查文件, 其中, 所述核查文件包括以下 至少之一: 所述数据文件的名称、 所述数据文件的大小、 所述数据文件的 记录数、 所述数据文件的时间参数。
优选地, 在将所述数据文件和所述核查文件上传至指定的所述第一目 标地址之前, 所述方法还包括: 判断当前所述任务是否需要执行合并操作; 当需要执行合并操作时, 将所述数据文件和所述核查文件上传至指定的第 二目标地址, 根据所述配置文件中合并节点的配置项, 在所述第二目标地 址内对所述数据文件进行合并和 /或对所述核查文件进行合并。
优选地, 所述合并节点的配置项包括以下至少之一: 合并前源文件所 在路径、 合并文件类型、 文件核查个数、 合并后文件分割最大记录阈值、 文件分割序列号长度、 合并后文件头内容配置、 合并后文件名称、 合并后 文件保存路径、 原始文件备份目录和保存时间、 是否支持文件压缩。
另一方面, 本发明实施例还提供一种数据同步的装置, 包括: 数据导 出单元, 配置为根据配置文件的配置, 从数据库服务器中导出当前任务所 需的数据文件; 上传单元, 配置为根据所述配置文件的配置, 将所述数据 文件上传至指定的第一目标地址, 完成数据同步。
优选地, 所述装置还包括: 核查文件生成单元, 配置为根据所述配置 文件的配置, 生成用于校验所述数据文件的核查文件, 其中, 所述核查文 件中包含数据文件的属性信息; 上传单元配置为将所述核查文件协同所述 数据文件一同上传至指定的所述第一目标地址。
优选地, 所述数据导出单元包括: 第一确定模块, 配置为根据所述配 置文件中的数据库信息配置项, 确定当前所述任务对应的数据库信息; 第 二确定模块, 配置为根据确定的数据库信息, 确定与当前所述任务对应的 数据库服务器, 并与确定的数据库服务器连接; 执行模块, 配置为执行所 述配置文件中的导出脚本文件, 从所述确定的数据库服务器中导出当前所 述任务所需的数据文件。
优选地, 核查文件生成单元包括; 分析模块, 配置为根据所述配置文 件的配置, 对导出的所述数据文件的属性进行分析; 生成模块, 配置为根 据分析结果生成所述核查文件, 其中, 所述核查文件包括以下至少之一: 所述数据文件的名称、 所述数据文件的大小、 所述数据文件的记录数、 所 述数据文件的时间参数。
优选地, 所述装置还包括: 判断单元, 配置为在将所述数据文件和所 述核查文件上传至指定的所述第一目标地址之前, 判断当前所述任务是否 需要执行合并操作; 合并单元, 配置为在所述判断单元确定需要执行合并 操作时, 将所述数据文件和所述核查文件上传至指定的第二目标地址, 根 据所述配置文件中合并节点的配置项, 在所述第二目标地址内对所述数据 文件进行合并和 /或对所述核查文件进行合并。
另一方面, 本发明实施例还提供一种数据同步的系统, 包括: 数据库 客户端、 数据库服务器以及上述的数据同步的装置, 其中, 数据同步的装 置与数据库客户端连接, 配置为通过所述数据库客户端访问所述数据库服 务器。
本发明实施例有益效果如下:
在本发明实施例中, 通过对配置文件的不同配置, 获取数据同步过程 中不同任务所需的数据文件, 以完成不同任务的数据同步, 这种数据同步 的方式有效地解决了相关技术中文件同步方式只能针对特定服务器的特定 功能进行同步, 通用性较差的问题, 提高了数据同步的灵活性。 附图说明
图 1 是本发明实施例一中数据同步的方法的一种优选的流程图; 图 2 是本发明实施例一中数据同步的方法中导出数据文件的一种优选 的流程图;
图 3 是本发明实施例一中数据同步的方法中合并文件的一种优选的流 程图;
图 4是本发明实施例一中数据同步的方法中 FTP上传文件的一种优选 的流程图;
图 5 是本发明实施例二中数据同步的装置的一种优选的结构框图; 图 6是本发明实施例二中数据同步的装置的另一种优选的结构框图; 图 7 是本发明实施例二中数据同步的装置的又一种优选的结构框图; 图 8 是本发明实施例二中数据同步的装置的又一种优选的结构框图。 具体实施方式
为了解决现有技术中文件同步方式只能针对特定服务器的特定功能进 行同步, 通用性较差的问题, 本发明实施例提供了一种数据同步的方法、 装置和系统, 下文中将参考附图并结合实施例来详细说明本发明。 需要说 明的是, 在不冲突的情况下, 本申请中的实施例及实施例中的特征可以相 互组合。
实施例一
本发明优选的实施例提供了一种数据同步的方法, 图 1 示出该方法的 一种优选的流程图, 如图 1所示, 该方法包括如下步骤:
S102 , 根据配置文件的配置, 从数据库服务器中导出当前任务所需的 数据文件;
优选地, 通过数据库客户端访问数据库服务器, 根据配置文件的配置 项, 向数据库服务器发送相关指令, 优选地, 该指令可以是用于导出数据 文件的可执行的导出语句, 也可以是 SQL脚本文件。
具体来说, 在进行数据同步的系统内安装数据库客户端, 通过该客户 端提供远程访问和操作数据库服务器的能力。 数据库服务器主要存储系统 各种原始数据资源, 需要时可导出同步给外部系统。 优选地, 考虑系统的 负载均衡和运行安全因素, 原始数据资源可以分散和备份在多个数据库服 务器上。 在获取数据文件过程中, 根据配置文件的配置, 向对应数据库服 务器发送可执行导出语句或 SQL导出脚本文件, 并根据执行结果返回生成 数据文件。 优选地, 配置文件可支持多任务多数据库模式, 即, 配置文件 可支持同时配置多个数据文件导出任务, 各个导出任务之间相互独立, 每 个任务都可以对多个数据库进行访问和操作, 并导出数据文件。
优选地, 配置文件的各个任务为一个结构化节点配置, 该节点配置具 有扩展性, 可通过复制整个节点来增加新的导出任务配置, 部署时只需按 具体情况稍作修改即可。 优选地, 配置文件各节点配置通常包括如下配置 项: 数据库信息配置、 导出脚本文件配置项 (包括导出前预处理 SQL语句 配置、 导出 SQL语句配置、 导出后 SQL语句配置、 导出数据文件名配置, 导出数据文件存放路径配置)等。
S104, 才艮据配置文件的配置, 将数据文件上传至指定的第一目标地址, 以完成数据同步。
优选地, 根据配置文件的配置, 将数据文件上传至指定的第一目标地 址时, 还包括: 根据配置文件的配置, 生成用以校验数据文件的核查文件, 其中, 核查文件中包含数据文件的属性信息; 将核查文件协同数据文件一 同上传至指定的第一目标地址。
具体来说, 根据配置文件的配置, 对上述导出的数据文件的属性进行 分析, 并记录, 根据分析结果生成核查文件, 即将记录结果作为核查文件, 该核查文件用于对生成的数据文件进行校验。 优选地, 该核查文件包括但 不限于以下参数: 数据文件的名称、 数据文件的大小、 数据文件的记录数、 数据文件的时间参数。
优选地, 核查文件的记录规则可以如下: 无文件头, 一行是一条记录, 以 "\r\n" 结束, 每条记录的各个字段之间以 , 分隔符按顺序相连。 内容 包括导出数据文件名称、 文件大小、 文件总记录数以及文件生成日期时间 等。 进一步地, 核查文件通过配置可实现三种生成模式: 不生成、 ——对 应生成模式以及一对多模式。 这里, ——对应生成模式即一个核查文件只 记录一个导出数据文件; 一对多模式, 即一个核查文件记录多个导出数据 文件。 此外, 核查文件的内容支持自由组合配置, 通过配置可选择性记录 数据文件属性。 优选地, 可支持的变量替换包括导出数据文件名称
{filename} , 文件大小 {filesize}、 文件总记录数 {totalline}以及文件生成曰 期 {datetime} 。 假 定 核 查 文 件 内 容 配 置 如 下 : checkcontent={ filename} | {totalline} | {datetime}, 则核查文件己录内容只包括 导出数据文件名称、 文件总记录数以及文件生成日期三个属性。 将数据文件和核查文件上传至外部系统指定的服务器目录, 通过核查 文件中包含的属性信息对该数据文件进行校验, 保证数据同步。 优选地, 基于文件传输协议(FTP, File Transfer Protocol )同步上传文件。 这里, FTP 是 TCP/IP网络上两台计算机传送文件的协议。 进一步地, 上传过程支持多 任务模式, 每个任务之间相互独立, 各个任务为一个结构化节点配置, 该 节点配置具有扩展性, 可通过复制整个节点来增加新的上传任务配置, 部 署时只需按具体情况稍作修改即可。 各个节点配置通常包括上传文件类型、 对端月良务器 IP地址、 FTP指定端口、 FTP用户名、 FTP密码以及 FTP远程 路径等。 优选地, 在上传过程中, 还支持失败重传机制, 具体地, 在上传 之前判断连接和登录远程服务器是否正常, 正常连接, 则开始同步上传。 如果上传失败, 则继续重传, 当失败次数超过限定值, 则向告警模块发送 文件上传失败信息, 并记录日志备查。 告警模块配置为接收各种告警和错 误通知消息, 并入库保存, 用户可通过巡检工具查询并显示该告警信息。 通知消息, 一般包括发送方进程号、 业务类型标识、 告警级别、 错误码以 及错误描述信息等。 此外, 还可以通过日志模块记录各个模块的操作步骤 和执行的情况, 便于跟踪和定位问题。
在本发明实施例中, 通过对配置文件的不同配置, 获取数据同步过程 中不同任务所需的数据文件, 以完成不同任务的数据同步, 这种数据同步 的方式有效地解决了相关技术中文件同步方式只能针对特定服务器的特定 功能进行同步, 通用性较差的问题, 提高了数据同步的灵活性。
在本发明的一个优选的实施方式中, 还对上述方法进行了优化, 具体 来说, 提供了一种根据配置文件的配置, 从数据库服务器中导出当前任务 所需的数据文件的方案, 该方案包括如下步骤: 根据配置文件中的数据库 信息配置项, 确定当前任务对应的数据库信息; 根据确定的数据库信息, 确定与当前任务对应的数据库服务器, 并与确定的数据库服务器连接; 执 行配置文件中的导出脚本文件, 从确定的数据库服务器中导出当前任务所 需的数据文件。
优选地, 数据库信息配置项为一组字符串, 并且具有扩展性, 支持多 行配置。 优选地, 配置规则如下: 是各字段以分割线 , 作为分隔符按顺 序相连, 它们依次是数据库类型、 数据库服务名、 登录用户名、 登录密码 和导出过程文件名称。 进一步地, 导出脚本文件 (如导出前和导出后 SQL 语句的配置)也支持多行配置, 此时系统识别并组装为 SQL脚本文件。 此 外, 各 SQL语句配置和文件名配置还支持日期变量替换, 包括 YYYY、
MM、 DD, 并可以自由组合, 如 YYYYMMDD表示当前年月日。
下面结合附图对上述导出数据文件的过程进行具体描述:
图 2示出一种导出数据文件的优选的流程图, 如图 2所示, 主要包括 如下步骤:
步骤 202, 在流程开始时, 系统判断定时任务时间是否已经到达, 如果 时间到达, 则执行步骤 204, 否则, 返回并继续等待。
步骤 204,从任务列表中查找到一个任务, 如果任务不存在或者均已经 完成, 则返回结束, 否则, 进入步骤 206。
步骤 206,根据任务和配置节点映射关系, 获取该任务的对应配置项集 合。
步骤 208, 解析配置项集合, 分解数据库信息配置并保存, 对导出文件 名称配置进行变量替换处理, 对所有 SQL语句配置进行变量替换处理后, 生成 SQL脚本文件, 然后进入步骤 210。
步骤 210, 从数据库信息配置中, 获取一个数据库信息, 该数据库信息 包括: 数据库类型、 数据库服务名、 登录用户名、 登录密码和导出过程文 件名称, 如果获取成功, 则进入步骤 212, 否则, 进入步骤 214。
步骤 212,根据获取到的数据库信息,远程连接和登录该数据库服务器, 操作执行 SQL导出脚本, 并根据返回结果, 生成数据文件。
步骤 214, 结束该任务, 保存数据文件到指定目录。 然后转步骤 204, 开始下一个任务。
在本发明的一个优选的实施方式中, 还对上述方法进行了优化, 具体 地, 将数据文件和核查文件上传至指定的第一目标地址之前, 方法还包括; 判断当前任务是否需要执行合并操作; 若判断结果为是, 则将数据文件和 核查文件上传至指定的第二目标地址, 根据配置文件中合并节点的配置项, 在第二目标地址内对数据文件进行合并和 /或对核查文件进行合并。
具体来说, 根据配置文件配置, 对指定服务器目录下指定类型的文件 进行核查并合并, 生成新的数据文件。 此功能作为可选功能, 通常系统在 做数据割接或扩容时, 加载该功能, 将割接后的多个服务器上数据库导出 的数据文件和 /或核查文件合并起来, 合并后的文件名称保持与割接升级前 一致。
进一步地, 该功能支持多任务模式, 每个任务之间相互独立, 各个任 务为一个结构化节点配置, 该节点配置具有扩展性, 可通过复制整个节点 来增加新的合并任务配置。 各节点配置通常包括以下至少之一: 合并前源 文件所在本地路径、 合并文件类型、 文件核查个数、 合并后文件分割最大 记录阈值、 文件分割序列号长度、 合并后文件头内容配置、 并后文件名称、 合并后文件所在本地保存路径、 原始文件备份目录和保存时间以及是否支 持文件压缩等。
优选地, 合并文件类型支持通配符模式。 通配符是一种特殊语句, 主 要有星号 (*)和问号 (?), 用来模糊搜索文件。 文件核查个数是指在合并前巡 检源文件目录, 检索文件类型包含文件个数达到合并要求的最小值。
优选地, 合并后文件支持文件头配置, 若不配置则无文件头, 具体内 容可通过配置直接描述, 其中, 配置可包含的替换变量有: 合并后总记录 数 {totalnum}和日期时间 { datetime}。
优选地, 合并后文件还支持最大记录阈值分割。 具体地, 若配置为空, 则文件记录大小不受限制, 否则, 当超过文件限定的记录数, 对合并后文 件进行分割拆分, 根据文件分割序列号长度和位置配置, 对分割文件重新 命名分配名称。 同样,文件名配置也支持日期变量替换, 包括 YYYY、 ΜΜ、 DD, 并可以自由组合, 如 YYYYMMDD表示当前年月日。 分割序列号在 文件名称位置通过配置变量替换 { SEQ }实现。 假定文件分割序列号长度为 4, 合并后文件名称配置如下:
filename=cardinfo_YYYYMMDD_ {SEQj .txt,
则合并再分割的文件名称形如: cardinfo_20120515_0001.txt。
优选地, 对合并后文件进行压缩, 对原始数据文件复制到指定目录进 行备份, 并定期清理备份目录下过期文件。
下面结合附图对上述合并文件的实现方法进行具体描述:
图 3示出一种合并文件的实现流程图, 如图 3所示, 包括如下步骤: 步骤 302、 在流程开始时, 系统判断定时任务时间是否已经到达, 如果 时间到达, 则执行步骤 304, 否则, 返回继续等待。
步骤 304,从任务列表中查找到一个任务, 如果任务不存在或者均已经 完成, 则返回结束, 否则, 进入步骤 306。
步骤 306,根据任务和配置节点映射关系, 获取该任务的对应配置项集 合。
步骤 308,对该任务配置的目标目录下的文件进行过滤处理,核查是否 与文件类型配置一致、 是否存在文件头且与配置是否一致、 文件内容是否 为空、 文件个数是否达到要求合并的最小值等, 然后, 进入步骤 310。
步骤 310,对目标目录下符合要求的文件进行内容合并处理, 写入一个 临时文件中, 并复制源文件到备份目录, 然后, 进入步骤 312。 步骤 312,对临时文件的总记录数进行校验并判定, 如果超过文件分割 规则设定的阈值, 则进入步骤 314, 否则, 进入步骤 316。
步骤 314,对临时文件按照文件分割规则进行拆分处理, 生成多个数据 文件。 这些数据文件名称通过变量替换获取分割序列号值, 随文件拆分个 数按顺序递增。 在合并后文件名称配置项中, 该分割序列号位置支持自由 配置。 然后, 进入步骤 316。
步骤 316, 改临时文件或拆分后文件为正式文件, 并保存到指定目录, 结束该任务, 然后, 转至步骤 304, 开始下一个任务。
图 4示出一种 FTP上传文件的优选的流程图, 如图 4所示, 包括如下 步骤:
步骤 402, 在流程开始时, 系统判断定时任务时间是否已经到达, 如果 时间到达, 则执行步骤 404, 否则, 返回继续等待。
步骤 404,从任务列表中查找到一个任务, 如果任务不存在或者均已经 完成, 则返回结束, 否则, 进入步骤 406。
步骤 406,根据任务和配置节点映射关系, 获取该任务的对应配置项集 合, 然后, 进入步骤 408。
步骤 408, 解析该任务下配置项集合, 获取远程服务器 FTP相关信息, 判断目标目录下存在需要上传的文件, 然后进行 FTP连接和登录测试。 如 果登录成功, 则进入步骤 410, 否则, 发送告警消息并记录日志, 进入步骤 416。
步骤 410, 开始上传该任务配置的目标目录下符合文件类型要求的文 件, 然后, 进入步骤 412。
步骤 412,对 FTP上传返回结果进行判定,如果失败,则进入步骤 414, 否则, 进入步骤 416。
步骤 414, 对 FTP失败次数进行统计, 如果失败次数低于配置限定值, 则进入步骤 410, 重新上传, 否则, 发送告警消息并记录日志, 进入步骤 416。
步骤 416, 转移目标目录下文件到备份目录, 并结束该任务。 然后, 转 至步骤 404, 开始下一个任务。
实施例二
基于上述实施例一中提供的数据同步的方法, 本优选的实施例提供了 一种数据同步的装置, 图 5 示出上述装置的一种优选的结构框图, 如图 5 所示, 该装置包括:
数据导出单元 502, 配置为根据配置文件的配置, 从数据库服务器中导 出当前任务所需的数据文件; 优选地, 数据导出单元 502通过数据库客户 端访问数据库服务器, 根据配置文件的配置项, 向数据库服务器发送相关 指令, 优选地, 该指令可以是用于导出数据文件的可执行的导出语句, 也 可以是 SQL脚本文件。
具体来说, 在进行数据同步的系统内安装数据库客户端, 数据导出单 元 502通过该客户端提供远程访问和操作数据库服务器的能力。 数据库服 务器主要存储系统各种原始数据资源, 需要时可导出同步给外部系统。 优 选地, 考虑系统的负载均衡和运行安全因素, 原始数据资源可以分散和备 份在多个数据库服务器上。 在获取数据文件过程中, 根据配置文件的配置, 向对应数据库服务器发送可执行导出语句或 SQL导出脚本文件, 并根据执 行结果返回生成数据文件。 优选地, 配置文件可支持多任务多数据库模式, 即, 配置文件可支持同时配置多个数据文件导出任务, 各个导出任务之间 相互独立, 每个任务都可以对多个数据库进行访问和操作, 并导出数据文 件。
优选地, 配置文件的各个任务为一个结构化节点配置, 该节点配置具 有扩展性, 可通过复制整个节点来增加新的导出任务配置, 部署时只需按 具体情况稍作修改即可。 优选地, 配置文件各节点配置通常包括如下配置 项: 数据库信息配置、 导出脚本文件配置项 (包括导出前预处理 SQL语句 配置、 导出 SQL语句配置、 导出后 SQL语句配置、 导出数据文件名配置, 导出数据文件存放路径配置)等。
上传单元 504,与数据导出单元 502连接,配置为根据配置文件的配置, 将数据文件上传至指定的第一目标地址, 以完成数据同步。
优选地, 如图 6所示, 上述装置还包括: 核查文件生成单元 602, 与数 据导出单元 502和上传单元 504连接, 配置为根据配置文件的配置, 生成 用以校验数据文件的核查文件, 其中, 核查文件中包含数据文件的属性信 息, 上传单元 504将核查文件协同数据文件一同上传至指定的第一目标地 址。 在第一目标地址内, 根据核查文件中包含的属性信息对数据文件进行 校验, 以完成数据同步。
优选地, 核查文件生成单元 602 包括: 分析模块, 配置为根据配置文 件的配置, 对导出的数据文件的属性进行分析; 生成模块, 配置为根据分 析结果生成核查文件, 其中, 核查文件包括以下至少之一: 数据文件的名 称、 数据文件的大小、 数据文件的记录数、 数据文件的时间参数。
优选地, 核查文件的记录规则可以如下: 无文件头, 一行是一条记录, 以 "\r\n" 结束, 每条记录的各个字段之间以 , 分隔符按顺序相连。 内容 包括导出数据文件名称、 文件大小、 文件总记录数以及文件生成日期时间 等。 进一步地, 核查文件通过配置可实现三种生成模式: 不生成、 ——对 应生成模式以及一对多模式。 这里, ——对应生成模式即一个核查文件只 记录一个导出数据文件; 一对多模式, 即一个核查文件记录多个导出数据 文件。 此外, 核查文件的内容支持自由组合配置, 通过配置可选择性记录 数据文件属性。 优选地, 可支持的变量替换包括导出数据文件名称 {filename} , 文件大小 {filesize}以及文件总记录数 {totalline} , 文件生成日 期 {datetime} 。 假 定 核 查 文 件 内 容 配 置 如 下 : checkcontent={ filename} | {totalline} | {datetime}, 则核查文件己录内容只包括 导出数据文件名称、 文件总记录数以及文件生成日期三个属性。
将数据文件和核查文件上传至外部系统指定的服务器目录, 通过核查 文件中包含的属性信息对该数据文件进行校验, 保证数据同步。 优选地, 基于 FTP同步上传文件。 这里, FTP是 TCP/IP网络上两台计算机传送文件 的协议。 进一步地, 上传过程支持多任务模式, 每个任务之间相互独立, 各个任务为一个结构化节点配置, 该节点配置具有扩展性, 可通过复制整 个节点来增加新的上传任务配置, 部署时只需按具体情况稍作修改即可。 各个节点配置通常包括上传文件类型、对端服务器 IP地址、 FTP指定端口、 FTP用户名、 FTP密码以及 FTP远程路径等。 优选地, 在上传过程中, 还 支持失败重传机制, 具体地, 在上传之前判断连接和登录远程服务器是否 正常, 正常连接, 则开始同步上传。 如果上传失败, 则继续重传, 当失败 次数超过限定值, 则向告警模块发送文件上传失败信息, 并记录日志备查。 告警模块配置为接收各种告警和错误通知消息, 并入库保存, 用户可通过 巡检工具查询并显示该告警信息。 通知消息, 一般包括发送方进程号、 业 务类型标识、 告警级别、 错误码以及错误描述信息等。 此外, 还可以通过 日志模块记录各个模块的操作步骤和执行的情况, 便于跟踪和定位问题。
在本发明实施例中, 通过对配置文件的不同配置, 获取数据同步过程 中不同任务所需的数据文件, 以完成不同任务的数据同步, 这种数据同步 的方式有效地解决了相关技术中文件同步方式只能针对特定服务器的特定 功能进行同步, 通用性较差的问题, 提高了数据同步的灵活性。
在本发明的一个优选的实施方式中, 还对上述装置进行了优化, 具体 来说, 提供了一种根据配置文件的配置, 从数据库服务器中导出当前任务 所需的数据文件的方案, 如图 7所示, 数据导出单元包括: 第一确定模块 702, 配置为根据配置文件中的数据库信息配置项, 确定 当前任务对应的数据库信息;第二确定模块 704,与第一确定模块 702连接, 配置为根据确定的数据库信息, 确定与当前任务对应的数据库服务器, 并 与确定的数据库服务器连接; 执行模块 706, 与第二确定模块 704连接, 配 置为执行配置文件中的导出脚本文件, 从确定的数据库服务器中导出当前 任务所需的数据文件。
优选地, 数据库信息配置项为一组字符串, 并且具有扩展性, 支持多 行配置。 优选地, 配置规则如下: 是各字段以分割线 , 作为分隔符按顺 序相连, 它们依次是数据库类型、 数据库服务名、 登录用户名、 登录密码 和导出过程文件名称。 进一步地, 导出脚本文件 (如导出前和导出后 SQL 语句的配置)也支持多行配置, 此时系统识别并组装为 SQL脚本文件。 此 外, 各 SQL语句配置和文件名配置还支持日期变量替换, 包括 YYYY、 MM、 DD, 并可以自由组合, 如 YYYYMMDD表示当前年月日。
在本发明的一个优选的实施方式中, 还对上述装置进行了优化, 具体 地, 如图 8所示, 该装置还包括: 判断单元 802, 配置为在将数据文件和核 查文件上传至指定的第一目标地址之前, 判断当前任务是否需要执行合并 操作; 合并单元 804, 与判断单元 802连接, 配置为在判断单元 802确定需 要执行合并操作时, 则将数据文件和核查文件上传至指定的第二目标地址, 根据配置文件中合并节点的配置项, 在第二目标地址内对数据文件和 /或对 核查文件进行合并。 具体来说, 根据配置文件配置, 对指定服务器目录下 指定类型的文件进行核查并合并, 生成新的数据文件。 此功能作为可选功 能, 通常系统在做数据割接或扩容时, 加载该功能, 将割接后的多个服务 器上数据库导出的数据文件和 /或核查文件合并起来, 合并后的文件名称保 持与割接升级前一致。
进一步地, 该功能支持多任务模式, 每个任务之间相互独立, 各个任 务为一个结构化节点配置, 该节点配置具有扩展性, 可通过复制整个节点 来增加新的合并任务配置。 各节点配置通常包括合并前源文件所在本地路 径、 合并文件类型、 文件核查个数、 合并后文件分割最大记录阈值, 文件 分割序列号长度、 合并后文件头内容配置、 合并后文件名称、 合并后文件 所在本地保存路径、 原始文件备份目录和保存时间以及是否支持文件压缩 等。
优选地, 合并文件类型支持通配符模式。 通配符是一种特殊语句, 主 要有星号 (*)和问号 (?), 用来模糊搜索文件。 文件核查个数是指在合并前巡 检源文件目录, 检索文件类型包含文件个数达到合并要求的最小值。
优选地, 合并后文件支持文件头配置, 若不配置则无文件头, 具体内 容可通过配置直接描述, 其中, 配置可包含的替换变量有: 合并后总记录 数 {totalnum}和日期时间 { datetime}。
优选地, 合并后文件还支持最大记录阈值分割。 具体地, 若配置为空, 则文件记录大小不受限制, 否则, 当超过文件限定的记录数, 对合并后文 件进行分割拆分, 根据文件分割序列号长度和位置配置, 对分割文件重新 命名分配名称。 同样,文件名配置也支持日期变量替换, 包括 YYYY、 ΜΜ、 DD, 并可以自由组合, 如 YYYYMMDD表示当前年月日。 分割序列号在 文件名称位置通过配置变量替换 { SEQ }实现。 假定文件分割序列号长度为 4, 合并后文件名称配置如下:
filename=cardinfo_YYYYMMDD_ {SEQj .txt,
则合并再分割的文件名称形如: cardinfo_20120515_0001.txt。
优选地, 对合并后文件进行压缩, 对原始数据文件复制到指定目录进 行备份, 并定期清理备份目录下过期文件。
实际应用时, 数据导出单元、 上传单元、 核查文件生成单元、 判断单 元以及合并单元可由数据同步的装置中的中央处理器 (CPU, Central Processing Unit )、 数字信号处理器(DSP, Digital Signal Processor )或可编 程逻辑阵列 (FPGA, Field - Programmable Gate Array ) 实现。
实施例三
基于上述实施例一提供的数据同步的方法和实施例二中提供的数据同 步的装置, 本优选的实施例提供了一种数据同步的系统, 该系统包括: 数 据库客户端、 数据库服务器以及上述实施例二中记载的数据同步的装置, 其中, 数据同步的装置与数据库客户端连接, 配置为通过数据库客户端访 问数据库服务器。
尽管为示例目的, 已经公开了本发明的优选实施例, 本领域的技术人 员将意识到各种改进、 增加和取代也是可能的, 因此, 本发明的范围应当 不限于上述实施例。

Claims

权利要求书
1、 一种数据同步的方法, 包括:
根据配置文件的配置, 从数据库服务器中导出当前任务所需的数据文 件;
根据所述配置文件的配置, 将所述数据文件上传至指定的第一目标地 址, 完成数据同步。
2、 如权利要求 1所述的方法, 其中, 所述根据所述配置文件的配置, 将所述数据文件上传至指定的第一目标地址时, 所述方法还包括:
根据所述配置文件的配置, 生成用于校验所述数据文件的核查文件, 其中, 所述核查文件中包含所述数据文件的属性信息;
将所述核查文件协同所述数据文件一同上传至指定的所述第一目标地 址。
3、 如权利要求 1或 2所述的方法, 其中, 所述根据配置文件的配置, 从数据库服务器中导出当前任务所需的数据文件包括:
根据所述配置文件中的数据库信息配置项, 确定当前所述任务对应的 数据库信息;
根据确定的数据库信息, 确定与当前所述任务对应的数据库服务器, 并与确定的数据库服务器连接;
执行所述配置文件中的导出脚本文件, 从所述确定的数据库服务器中 导出当前所述任务所需的数据文件。
4、 如权利要求 2所述的方法, 其中, 所述根据所述配置文件的配置, 生成用于检验所述数据文件的核查文件包括:
根据所述配置文件的配置, 对导出的所述数据文件的属性进行分析; 根据分析结果生成所述核查文件, 其中, 所述核查文件包括以下至少 之一: 所述数据文件的名称、 所述数据文件的大小、 所述数据文件的记录 数、 所述数据文件的时间参数。
5、 如权利要求 2所述的方法, 其中, 在将所述数据文件和所述核查文 件上传至指定的所述第一目标地址之前, 所述方法还包括:
判断当前所述任务是否需要执行合并操作;
当需要执行合并操作时, 将所述数据文件和所述核查文件上传至指定 的第二目标地址, 根据所述配置文件中合并节点的配置项, 在所述第二目 标地址内对所述数据文件进行合并和 /或对所述核查文件进行合并。
6、 如权利要求 5所述的方法, 其中, 所述合并节点的配置项包括以下 至少之一: 合并前源文件所在路径、 合并文件类型、 文件核查个数、 合并 后文件分割最大记录阈值、 文件分割序列号长度、 合并后文件头内容配置、 合并后文件名称、 合并后文件保存路径、 原始文件备份目录和保存时间、 是否支持文件压缩。
7、 一种数据同步的装置, 包括:
数据导出单元, 配置为根据配置文件的配置, 从数据库服务器中导出 当前任务所需的数据文件;
上传单元, 配置为根据所述配置文件的配置, 将所述数据文件上传至 指定的第一目标地址, 完成数据同步。
8、 如权利要求 7所述的装置, 其中, 所述装置还包括:
核查文件生成单元, 配置为根据所述配置文件的配置, 生成用于校验 所述所述数据文件的核查文件, 其中, 所述核查文件中包含所述数据文件 的属性信息;
所述上传单元配置为将所述核查文件协同所述数据文件一同上传至指 定的所述第一目标地址。
9、 如权利要求 7或 8所述的装置, 其中, 所述数据导出单元包括: 第一确定模块, 配置为根据所述配置文件中的数据库信息配置项, 确 定当前所述任务对应的数据库信息;
第二确定模块, 配置为根据确定的数据库信息, 确定与当前所述任务 对应的数据库服务器, 并与确定的数据库服务器连接;
执行模块, 配置为执行所述配置文件中的导出脚本文件, 从所述确定 的数据库服务器中导出当前所述任务所需的数据文件。
10、 如权利要求 8所述的装置, 其中, 所述核查文件生成单元包括; 分析模块, 配置为根据所述配置文件的配置, 对导出的所述数据文件 的属性进行分析;
生成模块, 配置为根据分析结果生成所述核查文件, 其中, 所述核查 文件包括以下至少之一: 所述数据文件的名称、 所述数据文件的大小、 所 述数据文件的记录数、 所述数据文件的时间参数。
11、 如权利要求 8所述的装置, 其中, 所述装置还包括:
判断单元, 配置为在将所述数据文件和所述核查文件上传至指定的所 述第一目标地址之前, 判断当前所述任务是否需要执行合并操作;
合并单元, 配置为在所述判断单元确定需要执行合并操作时, 将所述 数据文件和所述核查文件上传至指定的第二目标地址, 根据所述配置文件 中合并节点的配置项, 在所述第二目标地址内对所述数据文件进行合并和 / 或对所述核查文件进行合并。
12、 一种数据同步的系统, 包括: 数据库客户端、 数据库服务器以及 权利要求 7至 11中任一项所述的数据同步的装置, 其中, 所述数据同步的 装置与所述数据库客户端连接, 配置为通过所述数据库客户端访问所述数 据库服务器。
PCT/CN2013/083584 2012-12-14 2013-09-16 一种数据同步的方法、装置及系统 WO2014090002A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201210543604.1 2012-12-14
CN201210543604.1A CN103873517B (zh) 2012-12-14 2012-12-14 一种数据同步的方法、装置和系统

Publications (1)

Publication Number Publication Date
WO2014090002A1 true WO2014090002A1 (zh) 2014-06-19

Family

ID=50911638

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2013/083584 WO2014090002A1 (zh) 2012-12-14 2013-09-16 一种数据同步的方法、装置及系统

Country Status (2)

Country Link
CN (1) CN103873517B (zh)
WO (1) WO2014090002A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111897772A (zh) * 2020-08-05 2020-11-06 光大兴陇信托有限责任公司 一种大文件数据导入方法

Families Citing this family (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104933127A (zh) * 2015-06-12 2015-09-23 北京京东尚科信息技术有限公司 基于MariaDB的跨机房数据库同步设备及方法
CN106445951B (zh) * 2015-08-07 2022-05-17 中兴通讯股份有限公司 一种文件传输方法和装置
CN105897823A (zh) * 2015-11-13 2016-08-24 乐视云计算有限公司 视频上传的方法及系统
CN106708891A (zh) * 2015-11-17 2017-05-24 中兴通讯股份有限公司 一种网管数据同步方法及装置
CN106559496A (zh) * 2016-12-06 2017-04-05 安徽金曦网络科技股份有限公司 网络数据同步系统
CN108173891A (zh) * 2016-12-07 2018-06-15 北京京东尚科信息技术有限公司 基于广播机制实现数据同步的方法及装置
CN108427682A (zh) * 2017-02-14 2018-08-21 北京国双科技有限公司 一种数据文件同步方法及装置
CN108804457B (zh) * 2017-04-28 2021-10-08 北京京东尚科信息技术有限公司 数据同步和处理方法及装置、电子设备和计算机可读介质
CN109032620A (zh) * 2018-07-20 2018-12-18 北京百度网讯科技有限公司 应用程序的配置文件生成方法和装置
CN109376026A (zh) * 2018-09-14 2019-02-22 上海新炬网络信息技术股份有限公司 一种基于脚本的数据同步校验实现方法
CN109739549A (zh) * 2018-12-28 2019-05-10 武汉长光科技有限公司 一种基于微服务的设备性能采集方法
CN110389937A (zh) * 2019-07-26 2019-10-29 上海英方软件股份有限公司 一种基于数据库数据同步传输文件的方法及系统
CN111427938B (zh) * 2020-03-18 2023-08-29 中国建设银行股份有限公司 数据转存的方法和装置
CN111563114B (zh) * 2020-04-29 2022-02-25 北京新致君阳信息技术有限公司 信息处理方法、装置、设备和存储介质
CN112363983A (zh) * 2020-11-10 2021-02-12 北京思特奇信息技术股份有限公司 一种集群主机的文件核查方法和系统
CN112911335B (zh) * 2021-02-03 2022-05-27 烽火通信科技股份有限公司 一种基于视频编码的服务调度方法、视频服务器和机顶盒

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101996067A (zh) * 2009-08-19 2011-03-30 阿里巴巴集团控股有限公司 一种数据导出的方法和装置
CN102637214A (zh) * 2012-04-28 2012-08-15 中国工商银行股份有限公司 基于数据库服务间的通用数据同步方法及其系统
CN102693324A (zh) * 2012-01-09 2012-09-26 西安电子科技大学 一种分布式数据库同步系统、同步方法和节点管理方法

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6973479B2 (en) * 2002-05-01 2005-12-06 Thales Avionics, Inc. Method and system for configuration and download in a restricted architecture network
CN101505225A (zh) * 2008-02-05 2009-08-12 北京掌讯远景数码信息技术有限公司 数据传送方法及系统
CN102033889B (zh) * 2009-09-29 2012-08-22 熊凡凡 分布式数据库并行处理系统

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101996067A (zh) * 2009-08-19 2011-03-30 阿里巴巴集团控股有限公司 一种数据导出的方法和装置
CN102693324A (zh) * 2012-01-09 2012-09-26 西安电子科技大学 一种分布式数据库同步系统、同步方法和节点管理方法
CN102637214A (zh) * 2012-04-28 2012-08-15 中国工商银行股份有限公司 基于数据库服务间的通用数据同步方法及其系统

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111897772A (zh) * 2020-08-05 2020-11-06 光大兴陇信托有限责任公司 一种大文件数据导入方法
CN111897772B (zh) * 2020-08-05 2024-02-20 光大兴陇信托有限责任公司 一种大文件数据导入方法

Also Published As

Publication number Publication date
CN103873517B (zh) 2017-07-14
CN103873517A (zh) 2014-06-18

Similar Documents

Publication Publication Date Title
WO2014090002A1 (zh) 一种数据同步的方法、装置及系统
US11914486B2 (en) Cloning and recovery of data volumes
US20230393953A1 (en) Failover and recovery for replicated data instances
US11907254B2 (en) Provisioning and managing replicated data instances
US8631283B1 (en) Monitoring and automated recovery of data instances
US8938638B2 (en) Recovery service location for a service
JP5443614B2 (ja) 複製されたデータインスタンスのモニタリング
CN108881477B (zh) 一种基于分布式的文件采集监控的方法
WO2018049983A1 (zh) 数据同步方法、系统、同步获取方法及装置
CN110895488B (zh) 任务调度方法及装置
CN110895487B (zh) 分布式任务调度系统
CN110895484A (zh) 任务调度方法及装置
US10318387B1 (en) Automated charge backup modelling
WO2017113694A1 (zh) 文件同步方法、装置及系统
CN110895486B (zh) 分布式任务调度系统
KR101191832B1 (ko) 네트워크 패킷 분석을 통한 데이터베이스 복제 방법 및 시스템
CN110895485A (zh) 任务调度系统
US11079960B2 (en) Object storage system with priority meta object replication
US11074002B2 (en) Object storage system with meta object replication
US11093465B2 (en) Object storage system with versioned meta objects
CN117725130A (zh) 数据同步方法及装置、存储介质和电子设备
Tandel A study of modern cluster-based high availability database solutions
CN115454759A (zh) 一种基于kubernetes的全链路监控方法
CN116955369A (zh) 基于数据库的数据融合方法、装置、电子设备及存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 13863296

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 13863296

Country of ref document: EP

Kind code of ref document: A1