CN112835874A - Method, device and system for building main and standby databases - Google Patents

Method, device and system for building main and standby databases Download PDF

Info

Publication number
CN112835874A
CN112835874A CN202110318064.6A CN202110318064A CN112835874A CN 112835874 A CN112835874 A CN 112835874A CN 202110318064 A CN202110318064 A CN 202110318064A CN 112835874 A CN112835874 A CN 112835874A
Authority
CN
China
Prior art keywords
database
standby
main
file
password
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.)
Pending
Application number
CN202110318064.6A
Other languages
Chinese (zh)
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.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
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 Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202110318064.6A priority Critical patent/CN112835874A/en
Publication of CN112835874A publication Critical patent/CN112835874A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Quality & Reliability (AREA)
  • Data Mining & Analysis (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A method, a device and a system for building a master and standby database can be used in the financial field or other fields. The method comprises the following steps: acquiring a main database server IP and a standby database server IP, and determining the file size and the file number of main database instance information, a directory list and an online redo log; creating a redo log of the standby database in the main database according to the size and the number of the files; generating a connection character string, and adding the connection character string into a descriptor configuration file of a main database server; acquiring a password file, a parameter file and a descriptor configuration file from a main database, and synchronizing the password file, the parameter file and the descriptor configuration file to a standby database according to the IP of a standby database server; and according to the directory list of the main database, creating a directory list of the standby database in the standby database, and storing each file under the directory list of the standby database so that the standby database acquires the redo log of the standby database from the main database and copies data. The invention reduces the professional threshold for building the main and standby databases and improves the accuracy, efficiency and quality of daily operation and maintenance.

Description

Method, device and system for building main and standby databases
Technical Field
The invention relates to the technical field of databases, in particular to a method, a device and a system for building a main database and a standby database.
Background
At present, the construction of a main and standby database can be generally realized through the construction of a Data Guard, which is an enterprise-level database high-availability scheme promoted by Oracle and aims to achieve Data consistency by continuously synchronizing online log streams Redo Stream of main and standby nodes. When the master node fails, Data Guard can implement Data disaster recovery by fast switching.
At present, the Data Guard is built manually, the traditional manual building method is complex in steps, the labor cost and the time cost are relatively high, and the method is specifically embodied as follows:
1. related fields such as Oracle and SQL are professional knowledge, and the professional DBA (database administrator) can only be competent, and if the DBA time cannot be arranged, the work can only be delayed.
2. Many database parameters are modified in the building process, most parameters need to be modified according to the main and standby machine environments, steps are complex, human intervention factors are too many, human errors are easily introduced, and the whole building fails.
3. One person is taken as a unit, the traditional scheme cannot realize parallel construction and only can be executed in sequence, and the working efficiency and the progress are seriously influenced.
Disclosure of Invention
Aiming at the problems in the prior art, the embodiment of the invention mainly aims to provide a method, a device and a system for building a main and standby database, so that the professional requirement of personnel for building the main and standby database is reduced, and the accuracy, the efficiency and the quality of building are greatly improved.
In order to achieve the above object, an embodiment of the present invention provides a method for building a master/slave database, where the method includes:
acquiring a main database server IP and a standby database server IP, and determining instance information, a directory list and the file size and the file number of an online redo log of a main database according to the main database server IP;
creating a backup database redo log in the main database according to the size of the files and the number of the files;
generating a connection character string according to the IP of the main database server, the IP of the standby database server and the instance information, and adding the connection character string into a descriptor configuration file of the main database server;
acquiring a password file, a parameter file and a descriptor configuration file added with a connection character string from the main database, and synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database according to the IP of the standby database server;
and according to a master database directory list, creating a slave database directory list which is the same as the master database directory list in a slave database, and storing the password file, the parameter file and the descriptor configuration file added with the connection character string under the slave database directory list so that the slave database acquires the slave database redo log from the master database and copies the data in the master database.
Optionally, in an embodiment of the present invention, the method includes:
acquiring a main database server password and a standby database server password, and encrypting the main database server password and the standby database server password to obtain a main database server encryption password and a standby database server encryption password;
and generating a database table according to the IP of the main database server, the IP of the standby database server, the encryption password of the main database server and the encryption password of the standby database server, inserting an execution progress field into the database table, and initializing the value of the execution progress field.
Optionally, in an embodiment of the present invention, the synchronizing, according to the standby database server IP, the password file, the parameter file, and the descriptor configuration file to which the connection string is added to the standby database includes:
and according to the encrypted password of the standby database server and the IP access of the standby database server, synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database.
Optionally, in an embodiment of the present invention, the method further includes: and after the backup database acquires the redo log of the backup database from the main database and copies the data in the main database, updating the value of the execution progress field.
An embodiment of the present invention further provides a device for building a host/standby database, where the device includes:
the information acquisition module is used for acquiring a main database server IP and a standby database server IP and determining example information, a directory list and the file size and the file number of an online redo log of a main database according to the main database server IP;
the log creating module is used for creating a redo log of the standby database in the main database according to the size of the files and the number of the files;
the connection character string module is used for generating a connection character string according to the IP of the main database server, the IP of the standby database server and the instance information, and adding the connection character string into a descriptor configuration file of the main database server;
the file synchronization module is used for acquiring the password file, the parameter file and the descriptor configuration file added with the connection character string from the main database, and synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database according to the IP of the standby database server;
and the connection establishing module is used for establishing a standby database directory list which is the same as the main database directory list in a standby database according to the main database directory list, and storing the password file, the parameter file and the descriptor configuration file added with the connection character string under the standby database directory list so that the standby database acquires the redo log of the standby database from the main database and copies the data in the main database.
Optionally, in an embodiment of the present invention, the apparatus further includes:
the password acquisition module is used for acquiring a main database server password and a standby database server password and encrypting the main database server password and the standby database server password to obtain a main database server encryption password and a standby database server encryption password;
and the database table module is used for generating a database table according to the main database server IP, the standby database server IP, the main database server encryption password and the standby database server encryption password, inserting an execution progress field into the database table, and initializing the value of the execution progress field.
Optionally, in an embodiment of the present invention, the file synchronization module is further configured to access the standby database according to the encrypted password of the standby database server and the IP of the standby database server, and synchronize the password file, the parameter file, and the descriptor configuration file to which the connection string is added to the standby database.
Optionally, in an embodiment of the present invention, the database table module is further configured to update the value of the execution progress field after the standby database obtains the redo log of the standby database from the main database and copies the data in the main database.
An embodiment of the present invention further provides a system for building a host/standby database, where the system includes: the system comprises a main database, a standby database and a main and standby database building server which are in communication connection with the main database and the standby database;
the master and standby database building server is used for acquiring a master database server IP and a standby database server IP and determining instance information, a directory list and the file size and the file number of online redo logs of a master database according to the master database server IP; creating a backup database redo log in the main database according to the size of the files and the number of the files; generating a connection character string according to the IP of the main database server, the IP of the standby database server and the instance information, and adding the connection character string into a descriptor configuration file of the main database server;
the master and standby database building server is also used for acquiring a password file, a parameter file and a descriptor configuration file added with a connection character string from the master database, and synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database according to the IP of the standby database server; according to a main database directory list, a standby database directory list which is the same as the main database directory list is created in a standby database, and the password file, the parameter file and the descriptor configuration file added with the connection character string are stored under the standby database directory list;
and the standby database establishes connection with the main database according to the descriptor configuration file added with the connection character string, acquires the redo log of the standby database from the main database, performs data replication from the main database, and stores replicated data according to the standby database directory list.
Optionally, in an embodiment of the present invention, the master/standby database building server is further configured to obtain a master database server password and a standby database server password, and encrypt the master database server password and the standby database server password to obtain a master database server encryption password and a standby database server encryption password; and generating a database table according to the IP of the main database server, the IP of the standby database server, the encryption password of the main database server and the encryption password of the standby database server, inserting an execution progress field into the database table, and initializing the value of the execution progress field.
Optionally, in an embodiment of the present invention, the primary and secondary database building server is further configured to access the secondary database according to the encrypted password of the secondary database server and the IP of the secondary database server, and synchronize the password file, the parameter file, and the descriptor configuration file to which the connection character string is added to the secondary database.
Optionally, in an embodiment of the present invention, the primary and standby database building server is further configured to update the value of the execution progress field after the standby database obtains the redo log of the standby database from the primary database and copies the data in the primary database.
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method when executing the program.
The present invention also provides a computer-readable storage medium storing a computer program for executing the above method.
According to the invention, through the automatic construction of the main and standby databases, the professional threshold for constructing the main and standby databases is reduced, the construction process is simple to operate and easy to operate, and parallel operation is supported, so that the accuracy, efficiency and quality of daily operation and maintenance work are greatly improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained based on these drawings without creative efforts.
Fig. 1 is a flowchart of a method for building a master/slave database according to an embodiment of the present invention;
FIG. 2 is a flow chart of creating a database table in an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a master-slave database building system according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of module connection of a master-slave database building system according to an embodiment of the present invention;
FIG. 5 is a flowchart of the operation of the master-slave database building system according to the embodiment of the present invention;
fig. 6 is a schematic structural diagram of a device for building a master/slave database according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a master-slave database building device in an embodiment of the present invention;
fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The embodiment of the invention provides a method, a device and a system for building a master-slave database, which can be used in the financial field or other fields.
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1, a flowchart of a method for building a master/slave database according to an embodiment of the present invention is shown, where an execution main body of the method for building a master/slave database according to the embodiment of the present invention includes, but is not limited to, a computer, and may specifically be a server for building a master/slave database. The method shown in the figure comprises the following steps:
and step S1, acquiring a main database server IP and a standby database server IP, and determining the example information of a main database, a directory list and the file size and the file number of the online redo log according to the main database server IP.
The method comprises the steps of obtaining a server IP address of a main database and a server IP address of a standby database. In addition, the servers of the main and standby databases are all provided with Oracle tools so as to complete the construction of the main and standby databases (Data Guard). And accessing the main database according to the acquired server IP address of the main database, thereby determining the file size and the file number of the instance information, the directory list and the online redo log in the main database.
Specifically, the instance information includes an instance name and the like, and an online redo log (online redo) records all changes in the master database. Furthermore, the size and the number of the online redo log files of the main database are confirmed according to the online redo log view.
And step S2, creating a redo log of the standby database in the main database according to the size and the number of the files.
Wherein, referring to the Oracle official specification, a backup database redo log is created in the master database. Specifically, the number of the redo logs of the standby database is equal to the number of the files of the online redo logs of the main database plus one, and the size of the redo logs of the standby database is the same as that of the files of the online redo logs of the main database.
Step S3, generating a connection character string according to the IP of the main database server, the IP of the standby database server and the instance information, and adding the connection character string to the descriptor configuration file of the main database server.
The connection character string is used for establishing connection between the main database and the standby database, and comprises information such as a main database server IP, a standby database server IP and example information. And adding the connection character strings of the main database and the standby database in the connection descriptor configuration file of the main database server to prepare for subsequent connection.
Step S4, obtaining the password file, the parameter file, and the descriptor configuration file with the connection string from the primary database, and synchronizing the password file, the parameter file, and the descriptor configuration file with the connection string to the secondary database according to the IP of the secondary database server.
The password file records user password information, and the parameter file records parameter information in the database, such as information of storage space, storage address and the like required by different types of data. And accessing the standby database according to the IP of the standby database server, and synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database. Specifically, each file may be synchronized to the standby database by using a Python third-party module paramiko, and each file synchronized to the standby database may be stored in a form of being cached in a temporary cache region.
Step S5, according to the master database directory list, creating a backup database directory list in the backup database that is the same as the master database directory list, and storing the password file, the parameter file, and the descriptor configuration file added with the connection string under the backup database directory list, so that the backup database obtains the backup database redo log from the master database and copies the data in the master database.
And the standby database directory list which is the same as the main database directory list is created in the standby database according to the main database directory list, and the password file, the parameter file and the descriptor configuration file added with the connection character string are stored to the position corresponding to the standby database directory list.
Further, the connection between the backup database and the main database is established by using the descriptor configuration file added with the connection character string, the backup database acquires the backup database redo log from the main database through the connection, and executes a replication (duplicate) command to replicate data from the main database. And storing the copied data to a corresponding position under a standby database directory list.
As an embodiment of the present invention, as shown in fig. 2, the method further includes:
and step S21, acquiring a main database server password and a standby database server password, and encrypting the main database server password and the standby database server password to obtain a main database server encryption password and a standby database server encryption password.
The main database server password and the standby database server password are used for controlling access authority, and the main database server password and the standby database server password can be encrypted to ensure the security of the passwords. Specifically, the md5 algorithm may be used to encrypt the primary and secondary database server passwords, thereby obtaining the primary and secondary database server encryption passwords.
And step S22, generating a database table according to the primary database server IP, the standby database server IP, the primary database server encryption password and the standby database server encryption password, inserting an execution progress field into the database table, and initializing the value of the execution progress field.
The method comprises the steps of storing a main database server IP, a standby database server IP, a main database server encryption password and a standby database server encryption password, and creating a database table for storing information such as the main database server IP, the standby database server IP, the main database server encryption password and the standby database server encryption password. And inserting an execution progress field into the database table, and initializing the value of the execution progress field, namely setting the value of the execution progress field to zero.
Further, the execution progress field represents the current master-slave database building process state, and specifically, the building process state can be recorded by updating the value of the execution progress field. For example, when the value of the execution progress field is zero, it is indicated as a new construction task, and preprocessing such as state checking of a main database and a standby database is required; when the value of the execution progress field is 1, finishing the preprocessing and starting to build; and when the value of the execution progress field is 2, completing the construction of the main and standby databases.
In this embodiment, synchronizing the password file, the parameter file, and the descriptor configuration file to which the connection string is added to the backup database according to the backup database server IP includes: and according to the encrypted password of the standby database server and the IP access of the standby database server, synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database.
And the server IP accesses the standby database according to the standby database, and synchronizes the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database. Specifically, each file may be synchronized to the standby database by using a Python third-party module paramiko, and each file synchronized to the standby database may be stored in a form of being cached in a temporary cache region.
In this embodiment, the method further includes: and after the backup database acquires the redo log of the backup database from the main database and copies the data in the main database, updating the value of the execution progress field.
The execution progress field represents the current master-slave database building process state, and specifically, the building process state can be recorded by updating the value of the execution progress field. For example, when the value of the execution progress field is zero, it is indicated as a new construction task, and preprocessing such as state checking of a main database and a standby database is required; when the value of the execution progress field is 1, finishing the preprocessing and starting to build; and when the value of the execution progress field is 2, completing the construction of the main and standby databases. Specifically, after the backup database acquires the redo log of the backup database from the main database and copies the data in the main database, if the construction of the main and backup databases is completed, the value of the execution progress field is updated to 2.
Fig. 3 is a schematic structural diagram of a master-slave database building system according to an embodiment of the present invention, where the system shown in the diagram includes: the system comprises a main database, a standby database and a main and standby database building server which are in communication connection with the main database and the standby database;
the master and standby database building server is used for acquiring a master database server IP and a standby database server IP and determining example information, a directory list and the file size and the file number of the online redo log of the master database according to the master database server IP; creating a redo log of the standby database in the main database according to the size of the files and the number of the files; generating a connection character string according to the IP of the main database server, the IP of the standby database server and the instance information, and adding the connection character string into a descriptor configuration file of the main database server;
the master and standby database building server is also used for acquiring the password file, the parameter file and the descriptor configuration file added with the connection character string from the master database, and synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database; according to the IP of the standby database server and the directory list of the main database, a standby database directory list which is the same as the directory list of the main database is established in a standby database, and a password file, a parameter file and a descriptor configuration file added with a connection character string are stored under the directory list of the standby database;
and the standby database establishes connection with the main database according to the descriptor configuration file added with the connection character string, acquires a standby database redo log from the main database, performs data replication from the main database, and stores replicated data according to a standby database directory list.
The master and standby database building server further comprises a prerequisite (Prereq _ check) verification module, a DataGuard automatic building (Autodg _ process) module and a synchronous checking (Autodg _ check) module. As shown in fig. 4, the connection and operation process of each module are schematically illustrated.
Specifically, the automatic building module for the main and standby databases specifically comprises the following processes:
1. all changes in the database are recorded by the online redo log online redo, in order to ensure the consistency of subsequent main backup, the forced log mode parameter Force Logging of the main library is firstly adjusted to Yes, and the online redo log view v $ log is checked to confirm the size and the number n of files of the online redo log online redo. According to the result and the Oracle official specification, n +1 standby redo logs standby redo with the same size as the online redo are created.
2. According to the IP addresses, instance names and other information of the main server and the standby server, the connection character strings of the main library and the standby library are added to a main server connection descriptor configuration file tnsnames.
3. Under the default condition, the parameters of the main library do not meet the set-up precondition, and the parameters of the main library are automatically modified through the shell before operation: a local archive path log _ archive _ dest _1, a remote (i.e., backup) archive path log _ archive _ dest _2, a file auto-management parameter standby _ file _ management, and the like.
4. And automatically collecting related files such as a master library tnstandards.ora, password files, parameter files, pfile and the like, and simultaneously recording related directory lists such as master library instance data files, redo logs, audits and the like so as to be used by the backup library.
5. The master library tnsnnames.ora, the password file, the directory list file and the like are synchronized to the standby library through a python third-party module paramiko.
6. And reading a directory list synchronized from the master library, creating necessary directories (a data file directory, a redo log directory, an audit directory and the like) in the standby library, and then giving read-write permission so as to build a DataGuard and smoothly generate a corresponding file. And (3) referring to the primary library tnstandards. ora, adding a connection character string of the primary library and the secondary library in a configuration file of the secondary library, and simultaneously adding a monitoring configuration file listener. ora in the secondary library so as to carry out network connection through monitoring in the subsequent process. According to the condition of the standby library, partial parameters (log _ archive _ dest _1, log _ archive _ dest _2, standby _ file _ management and the like) of the main library pfile are modified to be used as a standby library parameter file.
7. Starting the standby library to a nomount state and starting monitoring. And then, connecting the main library and the standby library through an Oracle backup and recovery tool (recovery manager), and executing a duplicate command to complete the construction work of the standby library. The duplicate execution process starts the standby library state to the mount state, and after the duplicate command is executed, an application process MRP (managed recovery process) is started to apply the redo log to the standby library, so that the construction work is completed.
As an embodiment of the present invention, the primary and standby database building servers are further configured to obtain a primary database server password and a standby database server password, and encrypt the primary database server password and the standby database server password to obtain a primary database server encryption password and a standby database server encryption password; and generating a database table according to the IP of the main database server, the IP of the standby database server, the encryption password of the main database server and the encryption password of the standby database server, inserting an execution progress field into the database table, and initializing the value of the execution progress field.
The main database server password and the standby database server password are used for controlling access authority, and in order to ensure the security of the passwords, the main database server and the standby database server passwords can be encrypted by the main database server and the standby database server building servers. Specifically, the md5 algorithm may be used to encrypt the primary and secondary database server passwords, thereby obtaining the primary and secondary database server encryption passwords.
Further, the master and standby database building server stores the master database server IP, the standby database server IP, the master database server encryption password and the standby database server encryption password, and creates a database table for storing information such as the master database server IP, the standby database server IP, the master database server encryption password and the standby database server encryption password. And inserting an execution progress field into the database table, and initializing the value of the execution progress field, namely setting the value of the execution progress field to zero.
In this embodiment, the primary and secondary database building server is further configured to access the secondary database according to the encrypted password of the secondary database server and the IP of the secondary database server, and synchronize the password file, the parameter file, and the descriptor configuration file to which the connection character string is added to the secondary database.
The main and standby database building server accesses the standby database according to the standby database server IP, and synchronizes the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database. Specifically, each file may be synchronized to the standby database by using a Python third-party module paramiko, and each file synchronized to the standby database may be stored in a form of being cached in a temporary cache region.
In this embodiment, the primary and secondary database building server is further configured to update the value of the execution progress field after the secondary database obtains the redo log of the secondary database from the primary database and copies the data in the primary database.
The execution progress field represents the current master-slave database building process state, and specifically, the building process state can be recorded by updating the value of the execution progress field. For example, when the value of the execution progress field is zero, it is indicated as a new construction task, and preprocessing such as state checking of a main database and a standby database is required; when the value of the execution progress field is 1, finishing the preprocessing and starting to build; and when the value of the execution progress field is 2, completing the construction of the main and standby databases. Specifically, after the backup database acquires the redo log of the backup database from the main database and copies the data in the main database, if the construction of the main and backup databases is completed, the value of the execution progress field is updated to 2.
In addition, a prerequisite verification module in the master and backup database building server is used for checking and confirming before building the master and backup database environment. Specifically, each server can be normally communicated and logged in; the software and hardware environment is consistent, including but not limited to Oracle version number (viewing version number view v $ version); the file system, the authority and the owner are the same; confirming that the master library instance is operated through the instance operation condition view v $ instance; executing the archive log list command ensures that the archive has been opened by the master library.
Further, a synchronization check module in the master and backup database building server is used for verifying after building is completed so as to ensure synchronization of the master and backup databases. Specifically, the synchronous check module confirms that a redo log corresponding to a remote (i.e. backup) archive path dest _ id of 2 in a primary repository archive log view v $ archive _ log is continuously applied (applied); or after the master library test table inserts the random number, the master library test table confirms that the backup libraries are synchronized within the appointed time.
In addition, all functions of the prerequisite verification module, the main and standby database automatic building module and the synchronous inspection module are realized through a plurality of (11 in this embodiment) shell scripts, and relevant information is stored in a database table auto _ dg _ config, so that a convenience program can be automatically called, and the table structure is shown in table 1, for example.
TABLE 1
module_name Module name
operation Name of step
which_server In which role server the steps are executed (Master or Standby library)
command Shell script corresponding to steps
filename The related file names are used for subsequent audit trail or synchronization of the main and standby libraries
The information exchange, the sequence control and the like among the shell scripts are uniformly scheduled by a python program, so that the construction work of a single set of main and standby database environments can be completed. In order to fully improve the operation and maintenance efficiency and liberate labor force. The system utilizes a mysql database trigger event driving mechanism on the basis of the automation, starts multiple processes in parallel, can complete automatic construction work of multiple sets of environments at the same time, and has a system work flow chart as shown in fig. 5, which specifically comprises the following steps:
1. a user logs in a browser interface of the automatic building system of the main and standby databases and inputs core elements such as an IP (Internet protocol) of the main and standby servers, a user name, a password and the like.
2. The system basically checks and judges the input elements, for example, the ip address meets the specification, the user name and the password are input, and the next step is carried out after the verification is passed.
3. In order to prevent information from being tampered or intercepted maliciously, the system completes the algorithm encryption of the master server password md5 to obtain an encryption password authentication _ string, and then inserts the encryption password authentication _ string into a database table (dataguard _ env) together with information such as the IP (Internet protocol) of the server to be monitored, a user name and an execution progress field PROCESS _ FLAG (the initial value is 0). The DataGuard _ env records the DataGuard construction progress, and relevant field representations are shown in table 2, for example.
TABLE 2
primary_ip Ip address of main server
primary_username Master server user
primary_authentication_string Master server password encryption character string
standby_ip Ip address of standby server
standby_username Backup server user
standby_authentication_string Password encryption character string of standby server
PROCESS_FLAG Execution progress field
Wherein, each value of PROCESS _ FLA: 0 is an initial value; 1 represents that the Prereq _ check module has executed normally; 2 represents that the Autodg _ process module has executed normally; 3, the Autodg _ check module is normally executed, and the whole construction project is normally finished; 100 represents a module being executed.
Further, the dataguard _ env table opens multiple related processes to operate concurrently if multiple PROCESS _ FLAG fields equal to 0, 1 or 2 occur simultaneously.
4. In order to realize the multi-concurrency of the construction work, the database table is monitored by utilizing the characteristics of the trigger, and relevant operations are executed according to specified rules on the conditions of increasing, deleting, modifying and the like of records or fields. The name of the trigger of the system is as follows: the datasguard _ env _ trigger monitors the PROCESS _ FLAG field of the table datasguard _ env and calls the operating system script through the sys _ eval function (open source item mysqludf) according to different code values of the field. The specific process is as follows:
1) the newly inserted data PROCESS _ FLAG is 0 record, a new PROCESS is generated by the sys _ eval calling the prerequisite verification module Prereq _ check, and the PROCESS _ FLAG is modified to 100 to step 5. If multiple records are inserted simultaneously (representing the requirement of building multiple sets of main and standby databases at the same time), the actions are executed for multiple times.
2) And modifying the execution progress field PROCESS _ FLAG from 0 to 1, calling an automatic building module Autodg _ Process through sys _ eval to create a new PROCESS, and simultaneously modifying the PROCESS _ FLAG to 100 to go to step 6. If multiple records are modified at the same time, this operation is performed multiple times.
3) And the execution progress field PROCESS _ FLAG is changed from 1 to 2 to record, which shows that the built main work is completed, and the synchronous condition of the main and standby machines is checked by calling the sys _ eval synchronous checking module Autodg _ check. Similarly, if there are multiple record fields PROCESS _ FLAG modified from 1 to 2, multiple check processes will be generated simultaneously. After the step is finished, the PROCESSS _ FLAG is modified to 3, the whole construction project is finished (prerequisite verification, automatic construction and synchronous inspection), and the program is fed back to a front-end page according to different conditions.
4) The execution progress field PROCESS _ FLAG is modified from 2 to 3 or from another value to 100, and the system does not need to generate an additional PROCESS.
5. The step is mainly to finish the prerequisite verification work according to 'preq _ check' of module _ name in auto _ dg _ config, and modify the corresponding record PROCESS _ FLAG field from 0 to 1 after the prerequisite verification work is finished, so that the automatic building module Autodg _ PROCESS is conveniently called by detecting the modification by the dataguard _ env _ trigger.
6. The step is mainly completed according to 'Autodg _ PROCESS' of module _ name in auto _ dg _ config, and after the completion, the corresponding record PROCESSS _ FLAG field is modified from 1 to 2, so that the dataguard _ env _ trigger can conveniently detect that the modification calls the synchronous check module Autodg _ check.
The method overcomes the defects of strong specificity, excessive manual intervention, high error tendency, incapability of paralleling and the like of the traditional manual construction of the main and standby databases, reduces the construction and learning threshold of the main and standby databases, can easily construct a set of main and standby databases even if operators do not understand SQL operation and understand the tarnished principle of the main and standby databases, has simple operation and easy operation in the whole construction process, supports parallel operation, and greatly improves the accuracy, efficiency and quality of daily operation and maintenance work.
Fig. 6 is a schematic structural diagram of a device for building a master/slave database according to an embodiment of the present invention, where the device includes:
the information acquisition module 10 is configured to acquire a primary database server IP and a backup database server IP, and determine instance information of a primary database, a directory list, and a file size and a file number of an online redo log according to the primary database server IP.
The method comprises the steps of obtaining a server IP address of a main database and a server IP address of a standby database. In addition, the servers of the main and standby databases are all provided with Oracle tools so as to complete the construction of the main and standby databases (Data Guard). And accessing the main database according to the acquired server IP address of the main database, thereby determining the file size and the file number of the instance information, the directory list and the online redo log in the main database.
Specifically, the instance information includes an instance name and the like, and an online redo log (online redo) records all changes in the master database. Furthermore, the size and the number of the online redo log files of the main database are confirmed according to the online redo log view.
And the log creating module 20 is configured to create a redo log of the backup database in the primary database according to the file size and the number of the files.
Wherein, referring to the Oracle official specification, a backup database redo log is created in the master database. Specifically, the number of the redo logs of the standby database is equal to the number of the files of the online redo logs of the main database plus one, and the size of the redo logs of the standby database is the same as that of the files of the online redo logs of the main database.
And a connection character string module 30, configured to generate a connection character string according to the primary database server IP, the backup database server IP, and the instance information, and add the connection character string to a descriptor configuration file of the primary database server.
The connection character string is used for establishing connection between the main database and the standby database, and comprises information such as a main database server IP, a standby database server IP and example information. And adding the connection character strings of the main database and the standby database in the connection descriptor configuration file of the main database server to prepare for subsequent connection.
And the file synchronization module 40 is configured to acquire the password file, the parameter file, and the descriptor configuration file to which the connection character string is added from the master database, and synchronize the password file, the parameter file, and the descriptor configuration file to which the connection character string is added to the backup database according to the backup database server IP.
The password file records user password information, and the parameter file records parameter information in the database, such as information of storage space, storage address and the like required by different types of data. And accessing the standby database according to the IP of the standby database server, and synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database. Specifically, each file may be synchronized to the standby database by using a Python third-party module paramiko, and each file synchronized to the standby database may be stored in a form of being cached in a temporary cache region.
And the connection establishing module 50 is configured to create a standby database directory list identical to the main database directory list in the standby database according to the main database directory list, and store the password file, the parameter file, and the descriptor configuration file to which the connection character string is added to the standby database directory list, so that the standby database obtains the rework log of the standby database from the main database and copies data in the main database.
And the standby database directory list which is the same as the main database directory list is created in the standby database according to the main database directory list, and the password file, the parameter file and the descriptor configuration file added with the connection character string are stored to the position corresponding to the standby database directory list.
Further, the connection between the backup database and the main database is established by using the descriptor configuration file added with the connection character string, the backup database acquires the backup database redo log from the main database through the connection, and executes a replication (duplicate) command to replicate data from the main database. And storing the copied data to a corresponding position under a standby database directory list.
As an embodiment of the present invention, as shown in fig. 7, the apparatus further includes:
a password obtaining module 60, configured to obtain a primary database server password and a secondary database server password, and encrypt the primary database server password and the secondary database server password to obtain a primary database server encryption password and a secondary database server encryption password;
a database table module 70, configured to generate a database table according to the primary database server IP, the standby database server IP, the primary database server encryption password, and the standby database server encryption password, insert an execution progress field in the database table, and initialize a value of the execution progress field.
In this embodiment, the file synchronization module is further configured to access the standby database according to the encrypted password of the standby database server and the IP of the standby database server, and synchronize the password file, the parameter file, and the descriptor configuration file to which the connection string is added to the standby database.
In this embodiment, the database table module is further configured to update the value of the execution progress field after the standby database obtains the redo log of the standby database from the main database and copies the data in the main database.
Based on the same application concept as the main and standby database building method, the invention also provides the main and standby database building device. Because the principle of solving the problems of the master and slave database building device is similar to that of a master and slave database building method, the implementation of the master and slave database building device can refer to the implementation of the master and slave database building method, and repeated parts are not described again.
According to the invention, the main and standby databases are automatically built, so that the professional threshold for building the main and standby databases is reduced, the building process is simple to operate and easy to operate, parallel operation is supported, and the accuracy, efficiency and quality of daily operation and maintenance work are greatly improved.
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method when executing the program.
The present invention also provides a computer-readable storage medium storing a computer program for executing the above method.
As shown in fig. 8, the electronic device 600 may further include: communication module 110, input unit 120, audio processing unit 130, display 160, power supply 170. It is noted that the electronic device 600 does not necessarily include all of the components shown in FIG. 8; furthermore, the electronic device 600 may also comprise components not shown in fig. 8, which may be referred to in the prior art.
As shown in fig. 8, the central processor 100, sometimes referred to as a controller or operational control, may include a microprocessor or other processor device and/or logic device, the central processor 100 receiving input and controlling the operation of the various components of the electronic device 600.
The memory 140 may be, for example, one or more of a buffer, a flash memory, a hard drive, a removable media, a volatile memory, a non-volatile memory, or other suitable device. The information relating to the failure may be stored, and a program for executing the information may be stored. And the central processing unit 100 may execute the program stored in the memory 140 to realize information storage or processing, etc.
The input unit 120 provides input to the cpu 100. The input unit 120 is, for example, a key or a touch input device. The power supply 170 is used to provide power to the electronic device 600. The display 160 is used to display an object to be displayed, such as an image or a character. The display may be, for example, an LCD display, but is not limited thereto.
The memory 140 may be a solid state memory such as Read Only Memory (ROM), Random Access Memory (RAM), a SIM card, or the like. There may also be a memory that holds information even when power is off, can be selectively erased, and is provided with more data, an example of which is sometimes called an EPROM or the like. The memory 140 may also be some other type of device. Memory 140 includes buffer memory 141 (sometimes referred to as a buffer). The memory 140 may include an application/function storage section 142, and the application/function storage section 142 is used to store application programs and function programs or a flow for executing the operation of the electronic device 600 by the central processing unit 100.
The memory 140 may also include a data store 143, the data store 143 for storing data, such as contacts, digital data, pictures, sounds, and/or any other data used by the electronic device. The driver storage portion 144 of the memory 140 may include various drivers of the electronic device for communication functions and/or for performing other functions of the electronic device (e.g., messaging application, address book application, etc.).
The communication module 110 is a transmitter/receiver 110 that transmits and receives signals via an antenna 111. The communication module (transmitter/receiver) 110 is coupled to the central processor 100 to provide an input signal and receive an output signal, which may be the same as in the case of a conventional mobile communication terminal.
Based on different communication technologies, a plurality of communication modules 110, such as a cellular network module, a bluetooth module, and/or a wireless local area network module, may be provided in the same electronic device. The communication module (transmitter/receiver) 110 is also coupled to a speaker 131 and a microphone 132 via an audio processor 130 to provide audio output via the speaker 131 and receive audio input from the microphone 132 to implement general telecommunications functions. Audio processor 130 may include any suitable buffers, decoders, amplifiers and so forth. In addition, an audio processor 130 is also coupled to the central processor 100, so that recording on the local can be enabled through a microphone 132, and so that sound stored on the local can be played through a speaker 131.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The principle and the implementation mode of the invention are explained by applying specific embodiments in the invention, and the description of the embodiments is only used for helping to understand the method and the core idea of the invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (14)

1. A method for constructing a master-slave database is characterized by comprising the following steps:
acquiring a main database server IP and a standby database server IP, and determining instance information, a directory list and the file size and the file number of an online redo log of a main database according to the main database server IP;
creating a backup database redo log in the main database according to the size of the files and the number of the files;
generating a connection character string according to the IP of the main database server, the IP of the standby database server and the instance information, and adding the connection character string into a descriptor configuration file of the main database server;
acquiring a password file, a parameter file and a descriptor configuration file added with a connection character string from the main database, and synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database according to the IP of the standby database server;
and according to a master database directory list, creating a slave database directory list which is the same as the master database directory list in a slave database, and storing the password file, the parameter file and the descriptor configuration file added with the connection character string under the slave database directory list so that the slave database acquires the slave database redo log from the master database and copies the data in the master database.
2. The method of claim 1, further comprising:
acquiring a main database server password and a standby database server password, and encrypting the main database server password and the standby database server password to obtain a main database server encryption password and a standby database server encryption password;
and generating a database table according to the IP of the main database server, the IP of the standby database server, the encryption password of the main database server and the encryption password of the standby database server, inserting an execution progress field into the database table, and initializing the value of the execution progress field.
3. The method of claim 2, wherein the synchronizing the password file, the parameter file, and the descriptor configuration file with the appended connection string to the backup database according to the backup database server IP comprises:
and according to the encrypted password of the standby database server and the IP access of the standby database server, synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database.
4. The method of claim 2, further comprising: and after the backup database acquires the redo log of the backup database from the main database and copies the data in the main database, updating the value of the execution progress field.
5. A master and backup database building device, characterized in that the device comprises:
the information acquisition module is used for acquiring a main database server IP and a standby database server IP and determining example information, a directory list and the file size and the file number of an online redo log of a main database according to the main database server IP;
the log creating module is used for creating a redo log of the standby database in the main database according to the size of the files and the number of the files;
the connection character string module is used for generating a connection character string according to the IP of the main database server, the IP of the standby database server and the instance information, and adding the connection character string into a descriptor configuration file of the main database server;
the file synchronization module is used for acquiring the password file, the parameter file and the descriptor configuration file added with the connection character string from the main database, and synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database according to the IP of the standby database server;
and the connection establishing module is used for establishing a standby database directory list which is the same as the main database directory list in a standby database according to the main database directory list, and storing the password file, the parameter file and the descriptor configuration file added with the connection character string under the standby database directory list so that the standby database acquires the redo log of the standby database from the main database and copies the data in the main database.
6. The apparatus of claim 5, further comprising:
the password acquisition module is used for acquiring a main database server password and a standby database server password and encrypting the main database server password and the standby database server password to obtain a main database server encryption password and a standby database server encryption password;
and the database table module is used for generating a database table according to the main database server IP, the standby database server IP, the main database server encryption password and the standby database server encryption password, inserting an execution progress field into the database table, and initializing the value of the execution progress field.
7. The apparatus of claim 6, wherein the file synchronization module is further configured to synchronize the password file, the parameter file, and the descriptor configuration file with the connection string added to the backup database according to the backup database server encryption password and the backup database server IP accessing the backup database.
8. The apparatus of claim 6, wherein the database table module is further configured to update the value of the execution progress field after the backup database obtains the backup database redo log from the primary database and copies data in the primary database.
9. A master and backup database building system, characterized in that the system comprises: the system comprises a main database, a standby database and a main and standby database building server which are in communication connection with the main database and the standby database;
the master and standby database building server is used for acquiring a master database server IP and a standby database server IP and determining instance information, a directory list and the file size and the file number of online redo logs of a master database according to the master database server IP; creating a backup database redo log in the main database according to the size of the files and the number of the files; generating a connection character string according to the IP of the main database server, the IP of the standby database server and the instance information, and adding the connection character string into a descriptor configuration file of the main database server;
the master and standby database building server is also used for acquiring a password file, a parameter file and a descriptor configuration file added with a connection character string from the master database, and synchronizing the password file, the parameter file and the descriptor configuration file added with the connection character string to the standby database according to the IP of the standby database server; according to a main database directory list, a standby database directory list which is the same as the main database directory list is created in a standby database, and the password file, the parameter file and the descriptor configuration file added with the connection character string are stored under the standby database directory list;
and the standby database establishes connection with the main database according to the descriptor configuration file added with the connection character string, acquires the redo log of the standby database from the main database, performs data replication from the main database, and stores replicated data according to the standby database directory list.
10. The system of claim 9, wherein the primary and secondary database building servers are further configured to obtain a primary database server password and a secondary database server password, and encrypt the primary database server password and the secondary database server password to obtain a primary database server encryption password and a secondary database server encryption password; and generating a database table according to the IP of the main database server, the IP of the standby database server, the encryption password of the main database server and the encryption password of the standby database server, inserting an execution progress field into the database table, and initializing the value of the execution progress field.
11. The system according to claim 10, wherein the primary and backup database building server is further configured to access the backup database according to the backup database server encryption password and the backup database server IP, and synchronize the password file, the parameter file, and the descriptor configuration file to which the connection string is added to the backup database.
12. The system of claim 10, wherein the primary and backup database construction servers are further configured to update the value of the execution progress field after the backup database obtains the backup database redo log from the primary database and copies data in the primary database.
13. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method of any one of claims 1 to 4 when executing the computer program.
14. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program for executing the method of any one of claims 1 to 4.
CN202110318064.6A 2021-03-25 2021-03-25 Method, device and system for building main and standby databases Pending CN112835874A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110318064.6A CN112835874A (en) 2021-03-25 2021-03-25 Method, device and system for building main and standby databases

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110318064.6A CN112835874A (en) 2021-03-25 2021-03-25 Method, device and system for building main and standby databases

Publications (1)

Publication Number Publication Date
CN112835874A true CN112835874A (en) 2021-05-25

Family

ID=75930587

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110318064.6A Pending CN112835874A (en) 2021-03-25 2021-03-25 Method, device and system for building main and standby databases

Country Status (1)

Country Link
CN (1) CN112835874A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116708420A (en) * 2023-07-28 2023-09-05 联想凌拓科技有限公司 Method, device, equipment and medium for data transmission

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116708420A (en) * 2023-07-28 2023-09-05 联想凌拓科技有限公司 Method, device, equipment and medium for data transmission
CN116708420B (en) * 2023-07-28 2023-11-03 联想凌拓科技有限公司 Method, device, equipment and medium for data transmission

Similar Documents

Publication Publication Date Title
US11068449B2 (en) Data migration method, apparatus, and storage medium
WO2021169277A1 (en) Data synchronization method, apparatus and device, and computer-readable storage medium
CN110400142B (en) Data processing method, device and storage medium
US10944740B2 (en) Cluster claim
US8700569B1 (en) System and method for the merging of databases
US9881034B2 (en) Systems and methods for automating management of distributed databases
CN108932282B (en) Database migration method and device and storage medium
US8245192B1 (en) Independent software development zones
US11182403B2 (en) Systems and methods of launching new nodes in a blockchain network
US9015530B2 (en) Reliably testing virtual machine failover using differencing disks
JP2018200683A (en) Method and design of automated examination system
CN110688261A (en) Heterogeneous electronic file cloud disaster recovery system based on block chain
CN112364049B (en) Data synchronization script generation method, system, terminal and storage medium
WO2018001200A1 (en) Data processing method, cluster manager, resource manager and data processing system
US20200278911A1 (en) Synchronization storage solution after an offline event
CN105827683A (en) Data synchronization method, server and electronic device
CN111737227A (en) Data modification method and system
CN112835874A (en) Method, device and system for building main and standby databases
CN111339551A (en) Data verification method and related device and equipment
CN113190531A (en) Database migration method, device, equipment and storage medium
CN112948354A (en) Method and device for creating copy cluster, electronic device and storage medium
US20150347425A1 (en) System and method for validating replication of mutable operations performed on a file system object during a migration
CN112506579A (en) Multi-service multi-environment management method and system
US10693670B2 (en) Information processing apparatus, information processing system, and information processing method
CN112015715A (en) Industrial Internet data management service testing method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination