Database migration method and device
By using full-library physical backup and container technology to build a backup library on the second server during the database migration process, the problem of business interruption in database migration is solved, online migration and data recovery are realized, and migration efficiency and business continuity are improved. .
Patent Information
- Application Number
- CN202410927742.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-11-12
AI Technical Summary
During the database migration process, the existing technology needs to interrupt services, affecting the normal use of services.
By deleting the first database on the first server of the database platform and building the second database as the backup library for the third database on the second server, data restoring the second database based on the full library physical backup is realized, thus realizing data migration. Ensure that the database still works properly during the migration process.
It realizes that the normal use of the business does not affect the database migration process, improves the migration efficiency, and reduces manual intervention through the automated process.
Smart Images

Figure CN118939629A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a method and device for database migration. Background Art
[0002] In the era of rapid development of modern science and technology, the demand for storage devices is growing. More and more companies need to use database servers of different storage types to reduce costs and increase efficiency and save resources for the company according to business continuity requirements. Therefore, more and more companies choose to migrate their databases to meet business continuity requirements.
[0003] Generally, when migrating a database, you need to create a new database, interrupt the business of the database to be migrated, and then migrate the data. After the data migration is completed, point the business to the newly created database address, and the entire database migration is completed. However, during the migration process, the business needs to be interrupted, which will affect the normal use of the business.
[0004] Therefore, how to achieve the goal of not affecting the normal use of the business during the database migration process is a technical problem that urgently needs to be solved. Summary of the invention
[0005] The embodiment of the present invention provides a method and device for database migration, which is used to solve the problem in the prior art that during the migration process, services are interrupted and the normal use of services is affected.
[0006] In a first aspect, an embodiment of the present invention provides a method for database migration, comprising: deleting a first database from a first server of a database platform; the first database is in a standby database state and a third database in a master database state is in a normal working state; building a second database on a second server of the database platform, and setting the second database as a standby database for the third database; restoring data of the second database based on a full database physical backup corresponding to the first database, thereby completing data migration; the full database physical backup is performed before deleting the first database; when it is determined that the data of the second database is consistent with the data of the third database, the database migration is completed.
[0007] Optionally, the database platform creates a corresponding independent container for any database through container technology; deletes the first database from the first server of the database platform, including: uninstalling the file system corresponding to the first database from the first server of the database platform and deleting the first container corresponding to the first database; builds the second database on the second server of the database platform, including: registering the second database on the second server of the database platform and building a second container corresponding to the second database.
[0008] Optionally, constructing the second container corresponding to the second database includes: constructing the second container corresponding to the second database and setting the IP address of the second container to be the same as the IP address of the first container.
[0009] Optionally, the second server is determined from the database platform in the following manner, including: obtaining resource requirement information of the first database; and selecting a server in the database platform that is in normal operation, has a database creation function, and whose remaining resources meet the resource requirement information of the first database as the second server.
[0010] Optionally, before deleting the first database from the first server of the database platform, it also includes: when it is detected that the first server is in a down state, using each database of the first server as the first database to be migrated; setting the database in the main database state on the first server to the backup database state and making it unavailable; setting the database in the backup database state on the first server to be unavailable.
[0011] Optionally, detecting that the first server is in a downtime state includes: monitoring a container state of a container corresponding to any database on the first server; and when the container state is abnormal, detecting a network state of the container;
[0012] When the network status is abnormal, the port status of the port corresponding to the server where the container is located is detected; if the port status is abnormal, it is determined that the first server is in a downtime state.
[0013] Optionally, a server in the database platform that is in normal operation, has a function of creating a database, and whose remaining resources meet the resource demand information is used as the second server, including: obtaining an alternative server that is in normal operation and has the function of creating a database from the database platform; determining the alternative server whose remaining resources meet the resource demand information and whose storage type is the same as that of the first server as the second server; if there is no alternative server whose remaining resources meet the resource demand information and whose storage type is the same as that of the first server, determining the alternative server whose remaining resources meet the resource demand information from alternative servers with different storage types as the second server.
[0014] Optionally, the remaining resource requirement information includes CPU information, memory information, and storage space information; an alternative server whose remaining resources meet the resource requirement information and whose storage type is the same as that of the first server is determined as the second server, including: based on the remaining resources of the alternative server, determining an alternative server whose resource information is higher than that of the first database and whose storage type is the same as that of the first server as the target alternative server; determining a first score corresponding to the target alternative server based on the CPU information, memory information, storage space information and their respective corresponding weights in the remaining resources of the target alternative server; and determining the second server based on the first scores corresponding to each target alternative server.
[0015] Optionally, before deleting the first database from the first server of the database platform, it also includes: receiving a migration instruction triggered by a user; the migration instruction includes a first identifier corresponding to the first database to be migrated and a second identifier corresponding to the second server; if the database to be migrated is in a master database state, then based on the migration instruction, performing a full database physical backup of the first database; the first database is a standby database of the database to be migrated.
[0016] Optionally, when it is determined that the data in the second database is consistent with the data in the third database, the database migration is completed, including: after determining that the data in the second database is consistent with the data in the third database, setting the second database as the primary database and the third database as the backup database; after performing a full database physical backup of the third database, deleting the third database; building a fourth database on a third server of the database platform, and setting the fourth database as a backup database for the second database; restoring data in the fourth database based on the full database physical backup corresponding to the third database, thereby completing data migration; when it is determined that the data in the second database is consistent with the data in the fourth database, the database migration is completed.
[0017] In a second aspect, an embodiment of the present invention provides a device for database migration, comprising: an acquisition unit, used to delete a first database from a first server of a database platform; the first database is in a standby database state and a third database in a master database state is in a normal working state; a processing unit, used to build a second database on a second server of the database platform, and set the second database as a standby database for the third database; based on a full database physical backup corresponding to the first database, data of the second database is restored to complete data migration; the full database physical backup is performed before deleting the first database; when it is determined that the data of the second database is consistent with the data of the third database, the database migration is completed.
[0018] Optionally, the database platform creates a corresponding independent container for any database through container technology; the acquisition unit is specifically used to: uninstall the file system corresponding to the first database from the first server of the database platform and delete the first container corresponding to the first database. The processing unit is specifically used to: register the second database on the second server of the database platform and build a second container corresponding to the second database.
[0019] Optionally, the processing unit is specifically configured to: construct a second container corresponding to the second database and set an IP address of the second container to be the same as the IP address of the first container.
[0020] Optionally, the processing unit is specifically used to: obtain resource demand information of the first database; and use a server in the database platform that is in normal operation, has a database creation function, and has remaining resources that meet the resource demand information as the second server.
[0021] Optionally, the acquisition unit is also used to: when it is detected that the first server is in a down state, use each database of the first server as the first database to be migrated; set the database in the main database state on the first server to the backup database state and be unavailable; set the database in the backup database state on the first server to be unavailable.
[0022] Optionally, the acquisition unit is specifically used to: monitor the container status of a container corresponding to any database on the first server; when the container status is abnormal, detect the network status of the container; when the network status is abnormal, detect the port status of the port corresponding to the server where the container is located; if the port status is abnormal, determine that the first server is in a downtime state.
[0023] Optionally, the processing unit is specifically used to: obtain from the database platform an alternative server that is in normal operation and has the function of creating a database; determine as the second server an alternative server whose remaining resources meet the resource requirement information and whose storage type is the same as that of the first server; if there is no alternative server whose remaining resources meet the resource requirement information and whose storage type is the same as that of the first server, determine as the second server an alternative server whose remaining resources meet the resource requirement information from alternative servers with different storage types.
[0024] Optionally, the resource requirement information includes CPU information, memory information, and storage space information; the processing unit is specifically used to: determine, based on the remaining resources of the alternative server, an alternative server whose resource information is higher than that of the first database and whose storage type is the same as that of the first server as a target alternative server; determine a first score corresponding to the target alternative server based on the CPU information, memory information, storage space information and their respective corresponding weights in the remaining resources of the target alternative server; and determine a second server based on the first score corresponding to each target alternative server.
[0025] Optionally, the acquisition unit is also used to: receive a migration instruction triggered by a user; the migration instruction includes a first identifier corresponding to the first database to be migrated and a second identifier corresponding to the second server; if the database to be migrated is in the master database state, then based on the migration instruction, performing a full database physical backup of the first database; the first database is a standby database of the database to be migrated.
[0026] Optionally, the acquisition unit is specifically used to: after determining that the data in the second database is consistent with the data in the third database, set the second database as the main database and the third database as the backup database; after performing a full database physical backup of the third database, delete the third database; build a fourth database on a third server of the database platform, and set the fourth database as the backup database of the second database; based on the full database physical backup corresponding to the third database, restore the data of the fourth database, thereby completing data migration; when it is determined that the data in the second database is consistent with the data in the fourth database, the database migration is completed.
[0027] In a third aspect, an embodiment of the present invention further provides a computing device, comprising at least one processor and at least one memory, wherein the memory stores a computer program, and when the program is executed by the processor, the processor executes a database migration method of the first aspect above.
[0028] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program executable by a computer device. When the program runs on the computer device, the computer device executes a method for database migration according to the first aspect.
[0029] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program stored on a computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer device, the computer device executes the steps of the method for migrating any database in the first aspect above. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0031] Figure 1 A flowchart of a method for database migration provided by an embodiment of the present invention;
[0032] Figure 2 A flow chart of a method for determining a server downtime of a database provided by an embodiment of the present invention;
[0033] Figure 3 A flowchart of a method for database preprocessing provided by an embodiment of the present invention;
[0034] Figure 4 A flowchart of another method for preprocessing a database provided by an embodiment of the present invention;
[0035] Figure 5 A flow chart of a method for determining a second server provided by an embodiment of the present invention;
[0036] Figure 6 A flow chart of a method for determining a second server provided in an embodiment of the present invention;
[0037] Figure 7 A flow chart of a method for determining a second server provided by an embodiment of the present invention;
[0038] Figure 8 A flowchart of a method for database migration provided by an embodiment of the present invention;
[0039] Fig. 9 A flowchart of a method for database migration provided by an embodiment of the present invention;
[0040] Fig.10 A schematic diagram of the state of database migration provided by an embodiment of the present invention;
[0041] Fig.11 A schematic diagram of the structure of a computing device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0043] The data of the MySQL database is stored on disks, and the storage media used are usually SAN, local disks, local solid-state disks (SSDs), etc. SAN is a storage architecture that connects storage devices and application servers through a network. The server and SAN storage (such as G600) are connected by optical fiber lines, so the speed is slow and the access latency is high when the application reads and writes data. When the optical fiber line connecting the storage is touched, there will be disadvantages such as data interruption. In terms of physical location, a SAN storage connected to a database cluster needs to be placed in a cabinet, which takes up space in the computer room. Compared with SAN storage, local disks and SSDs are directly plugged into the server, and storage does not require an additional cabinet. In terms of performance, compared with SAN and local disks, SSDs have faster read and write speeds and higher performance.
[0044] In the embodiment of the present invention, online databases require high read / write and high performance, and need to use a local SSD server; management databases and unimportant business systems can use a SAN or local disk server.
[0045] In one possible scenario, when an unimportant business is launched, SAN storage or local disk servers are used. However, as the business changes, the status of the business gradually increases, so it needs to be replaced with a local SSD server. Conversely, when an important business is launched, a local SSD server is used. However, as the business changes, the status of the business gradually decreases, so it needs to be replaced with a SAN storage or local disk server.
[0046] In another possible scenario, when the database storage type resources are insufficient, the database can be temporarily migrated to another database, and then migrated to the original database after the new storage resources of the original database are in place.
[0047] In another possible scenario, when an exception occurs in the database, the data is migrated to other databases to ensure business continuity.
[0048] In one possible scenario, when migrating a database, you need to create a new database, interrupt the business of the database to be migrated, and then migrate the data. After the data migration is completed, point the business to the newly created database address, and the entire database migration is completed. In this migration method, the database service IP before and after changes, and the business party needs to manually connect to the database address. In addition, during the migration process, the business needs to be interrupted, which will affect the normal use of the business.
[0049] In summary, the embodiment of the present invention provides a method for database migration, which is used to realize online migration of a database to a database of the same storage or a different storage type, and then automatically restore the data through a full database physical backup to achieve database migration and data recovery. The entire process is automated, thereby improving the efficiency of database migration.
[0050] like Figure 1 FIG. 1 is a flowchart of a method for database migration provided by an embodiment of the present invention, and the method comprises the following steps:
[0051] Step 101: Delete a first database from a first server of a database platform.
[0052] In the embodiment of the present invention, in order to realize online migration of the database, the database is a database with a master-slave mode, wherein the third database is in the master database state and the first database is in the slave database state. First, the first database needs to be deleted from the first server of the database platform, wherein since the third database is in a normal working state, even if the first database is deleted, it does not affect the normal business processing of the database. Specifically, the file system corresponding to the first database is uninstalled from the first server of the database platform and the first container corresponding to the first database is deleted.
[0053] Step 102: construct a second database on a second server of the database platform, and set the second database as a backup database for the third database.
[0054] In an embodiment of the present invention, after deleting the first database on the first server of the database platform, a second database is constructed on the second server of the database platform, and the second database is set as a backup database for the third database. Specifically, the second database is registered on the second server of the database platform and a second container corresponding to the second database is constructed.
[0055] Step 103: restore the data of the second database based on the full database physical backup corresponding to the first database, thereby completing the data migration.
[0056] In an embodiment of the present invention, before deleting the first database, a full database physical backup is performed on the first database, and then after building the second database, data of the second database is restored based on the full database physical backup corresponding to the first database, thereby completing data migration to the second database.
[0057] Step 104: When it is determined that the data in the second database is consistent with the data in the third database, the database migration is completed.
[0058] In the embodiment of the present invention, since the second database is a standby database of the third database, it is necessary to determine whether the data of the second database is consistent with the data of the third database. If they are consistent, it means that the standby database migration is successful.
[0059] It can be seen from the above steps 101 to 104 that, since the database is a database with a master-slave mode, when the standby database is deleted for database migration, the master database can still perform business normally, thereby realizing online migration of the database to the server, and then restoring the data through the physical backup of the entire database, thereby realizing the migration of the database itself and the data in the migration database.
[0060] Optionally, a second container corresponding to the second database is constructed and the IP address of the second container is set to be the same as the IP address of the first container, so that the IP address remains unchanged before and after the database migration. In this way, the business side does not need to make any changes and the application is unaware.
[0061] Optionally, there are two situations that trigger database migration. One is that the database needs to be migrated due to business needs or business adjustments. The other is that the database server is down and the database needs to be migrated. If the database needs to be migrated due to business needs or business adjustments, both the primary database and the standby database need to be migrated, that is, both the first database and the third database need to be migrated. If the database server is down and the database needs to be migrated, only the database on the down server needs to be migrated, where the database on the down server may be the primary database or the standby database, so that when the server is down, the normal use of the database is not affected while migrating the database. If the database on the down server is the primary database, the primary-standby switch is performed so that the database on the down server is switched to the standby database. Therefore, this solution monitors the status of the database server, and if the database server is down, the database migration is triggered. The following describes how to determine whether the database server is down.
[0062] like Figure 2 FIG. 1 is a flow chart of a method for determining a server crash of a database provided by an embodiment of the present invention, the method comprising the following steps:
[0063] Step 201: monitor the container status of any container corresponding to a database on a first server.
[0064] In the embodiment of the present invention, the container status of any database corresponding to the container on the first server is detected. If the container status is normal, it means that the first server is working normally. If the container status is abnormal, it means that there may be an abnormality in the first server, which requires further investigation.
[0065] Step 202: When the container status is abnormal, detect the network status of the container.
[0066] In the embodiment of the present invention, when the container status is abnormal, it is necessary to detect the network status of the container. If the network status of the container is normal, it means that the first server is working normally. If the network status of the container is abnormal, it means that there may be an abnormality in the first server, which requires further investigation.
[0067] Step 203: When the network status is abnormal, detect the port status of the port corresponding to the server where the container is located.
[0068] In the embodiment of the present invention, when the network status is abnormal, it means that the first server is abnormal, and it is necessary to detect the port status of the port corresponding to the server where the container is located to determine the status of the first server.
[0069] Step 204: If the port status is abnormal, determine that the first server is in a downtime state.
[0070] It can be seen from the above steps 201 to 204 that by monitoring the status of the server of the database, the downed server can be monitored in time, and the database on the server can be migrated in time when the server is down, thereby reducing the loss caused by the server downtime.
[0071] In a possible case, if the database server is down, in order not to affect the normal processing of the database business, the database needs to be preprocessed before step 101. The following describes how to preprocess the database.
[0072] like Figure 3 FIG. 1 is a flowchart of a method for preprocessing a database provided by an embodiment of the present invention, and the method comprises the following steps:
[0073] Step 301: When it is detected that the first server is in a downtime state, each database of the first server is used as a first database to be migrated.
[0074] In the embodiment of the present invention, when it is detected that the first server is in a downtime state, each database on the first server needs to be used as a first database to be migrated for database migration, thereby reducing the loss caused by the server downtime.
[0075] Step 302: Set the database in the primary database state on the first server to the standby database state and make it unavailable.
[0076] In the embodiment of the present invention, since each database on the first server may be a primary database or a standby database, in order to achieve that the normal use of the database is not affected during the database migration, if the database on the first server is the primary database, a primary-standby switch is performed, and the database is switched to a standby database and is made unavailable, and the original standby database is switched to the primary database for normal business processing. In this way, the database on the first server is switched to a standby database, which not only facilitates the subsequent database migration of the database, but also does not affect the normal operation of the database during the database migration.
[0077] Step 303: Set the database in the standby state on the first server to be unavailable.
[0078] In the embodiment of the present invention, if the database on the first pair of servers is a standby database, the standby database is directly set to be unavailable, and then the database migration is directly performed subsequently.
[0079] It can be seen from the above steps 301 to 303 that when the database server is down, it is necessary to migrate the database on the down server, so as to switch the database on the down server to the standby database and then migrate the database, so as not to affect the normal use of the database.
[0080] In another possible case, if database migration is required according to business needs or business adjustments, the database needs to be preprocessed before step 101. The following describes how to preprocess the database.
[0081] like Figure 4 FIG. 1 is a flowchart of another method for preprocessing a database provided by an embodiment of the present invention, the method comprising the following steps:
[0082] Step 401: receiving a migration instruction triggered by a user.
[0083] In an embodiment of the present invention, if database migration is required according to business needs or business adjustments, a migration instruction triggered by a user needs to be received, wherein the migration instruction is used to instruct to migrate the first database to be migrated to the second server. The migration instruction includes a first identifier corresponding to the first database to be migrated and a second identifier corresponding to the second server.
[0084] Step 402: If the database to be migrated is in the master database state, a full database physical backup is performed on the first database to be migrated based on the migration instruction; the first database to be migrated is a standby database of the database to be migrated.
[0085] In an embodiment of the present invention, the database to be migrated may be in the master database state or the standby database state. If the database to be migrated is in the master database state, based on the migration instruction, a full database physical backup is performed on the standby database of the database to be migrated, wherein the database to be migrated is the first database to be migrated. This facilitates data restoration based on the full database physical backup of the standby database when the database to be migrated is deleted and rebuilt later. If the database to be migrated is in the standby database state, the database to be migrated is the first database to be migrated, and a full database physical backup is performed on the database to be migrated according to the migration instruction.
[0086] It can be seen from the above steps 401 to 402 that by performing a full database physical backup on the standby database, when the standby database is subsequently deleted and rebuilt, data can be restored based on the full database physical backup, thereby achieving database data migration.
[0087] To achieve database migration, after step 101, a second database needs to be built on the second server so that the second database replaces the first database as a backup database for the third database, thereby achieving database migration. To achieve database migration to a suitable server, the following describes how to determine the second server.
[0088] like Figure 5 FIG. 1 is a flow chart of a method for determining a second server provided by an embodiment of the present invention, the method comprising the following steps:
[0089] Step 501: Obtain resource demand information of a first database.
[0090] In the embodiment of the present invention, resource requirement information of the first database is obtained, wherein the resource requirement information includes CPU information, memory information, and storage space information. By obtaining the resource requirement information of the first database, it is convenient to subsequently determine the second server according to the resource requirement information of the first database.
[0091] Step 502: A server in the database platform that is in normal operation, has a database creation function, and has remaining resources that meet the resource demand information of the first database is used as the second server.
[0092] In the embodiment of the present invention, Figure 6 As shown, it is a flow chart of a method for determining a second server provided by an embodiment of the present invention, and the method comprises the following steps:
[0093] Step 601: Obtain from the database platform a candidate server that is in normal operation and has a database creation function.
[0094] In the embodiment of the present invention, a database that is in a normal operating state and has a database creation function is selected from the database platform as a candidate server.
[0095] Step 602, determine whether the remaining resources of the candidate server meet the resource demand information, if so, execute step 603, if not, execute step 604.
[0096] In the embodiment of the present invention, the candidate servers are determined through step 601, and then the remaining resources of the candidate servers need to be determined, wherein the remaining resources include CPU information, memory information, and storage space information. It is determined whether the remaining resources of each candidate server are higher than the resource requirement information of the first database and the storage type is the same as the first server. If so, the candidate server with higher resource requirement information than the first database and the same storage type as the first server is used as the target candidate server. If the remaining resources of the candidate servers with the same storage type as the first server are all lower than the resource requirement information of the first database, the candidate server whose remaining resources meet the resource requirement information is determined from the candidate servers with different storage types as the second server.
[0097] Step 603: determine the candidate server whose remaining resources meet the resource demand information and whose storage type is the same as that of the first server as the second server.
[0098] In the embodiment of the present invention, Figure 7 FIG. 1 is a flow chart of a method for determining a second server provided by an embodiment of the present invention, the method comprising the following steps:
[0099] Step 701: According to the remaining resources of the candidate servers, a candidate server having higher resource information than the first database and the same storage type as the first server is determined as a target candidate server.
[0100] In an embodiment of the present invention, if, based on the remaining resources of the alternative servers, there is an alternative server with higher resource information than the first database and the same storage type as the first server, then the alternative server with higher resource information than the first database and the same storage type as the first server is determined as the target alternative server.
[0101] Step 702: Determine a first score corresponding to the target candidate server based on CPU information, memory information, storage space information and their corresponding weights in the remaining resources of the target candidate server.
[0102] In the embodiment of the present invention, based on the CPU information, memory information, storage space information and their corresponding weights in the remaining resources of the target candidate server, the first score corresponding to the target candidate server is determined. The first score corresponding to the target candidate server can be determined according to Formula 1, as shown in Formula 1:
[0103] First score = CPU*CM+MEM*MM+STR*SM Formula 1
[0104] Among them, CPU is CPU information, CM is the weight corresponding to CPU information. MEM is memory information, MM is the weight corresponding to memory information. STR is storage space information, SM is the weight corresponding to storage space information.
[0105] Optionally, the CPU information may be a remaining resource percentage of the CPU resources, the memory information may be a remaining resource amount of the memory resources, and the storage space information may be a remaining resource amount of the storage space resources.
[0106] According to Formula 1, the first score corresponding to each target candidate server can be determined. For example, the target candidate servers include server 1, server 2, server 3, server 4, server 5 and server 6. The first score of each target candidate server is determined according to Formula 1, as shown in Table 1.
[0107] Table 1 The first score of each target candidate server
[0108] CPU Information Memory information Storage space information First Rating Server 1 100 100 100 91 Server 2 73 74 88 69 Server 3 71 72 86 67 Server 4 71 72 86 67 Server 5 67 68 95 65 Server 6 71 72 94 68
[0109] Step 703: Determine a second server according to the first score corresponding to each target candidate server.
[0110] In the embodiment of the present invention, according to the first scores corresponding to the target candidate servers, the target candidate server with the highest first score is determined as the second server.
[0111] It can be seen from the above steps 701 to 703 that by comparing the remaining resources of the alternative servers with the resource demand information of the first database, it is possible to determine the target alternative servers that meet the conditions, and then by determining the first score of each target alternative server, the target alternative server with the highest score is determined as the second server, thereby determining the better server as the second server.
[0112] Step 604: Determine, from the candidate servers of different storage types, a candidate server whose remaining resources meet the resource demand information as the second server.
[0113] In an embodiment of the present invention, if there is no alternative server whose remaining resources meet the resource requirement information and whose storage type is the same as that of the first server, the target alternative server that meets the resource requirement information continues to be selected in order of priority of the storage type, and then the second server can be determined from multiple target alternative servers according to steps 702 to 703.
[0114] It can be seen from the above steps 601 to 604 that multiple target candidate servers can be determined more accurately based on the remaining resources of the candidate servers and the resource demand information of the first database, and then the target candidate servers are sorted according to the first scoring scores to obtain the second server.
[0115] It can be seen from the above steps 501 to 502 that the resource requirement information of the first server can be used to more accurately determine the resource requirement information of the second server.
[0116] In another possible case, the server input by the user can be determined as the second server. Specifically, the identifier of the pre-selected server input by the user is received, and then the remaining resources of the pre-selected server and the resource requirement information of the first database are obtained, wherein the storage type of the pre-selected server may be the same as that of the first server, or may be different from that of the first server, which is not limited here. If the remaining resources of the pre-selected server are higher than the resource requirement information of the first server, the pre-selected server is determined as the second server. If the remaining resources of the pre-selected server are lower than the resource requirement information of the first server, an error notification is sent to the user, wherein the error notification is used to notify the user that the pre-selected server does not meet the requirements of becoming the second server and needs to re-enter the identifier of another server.
[0117] In the embodiment of the present invention, after the second server is determined, when the condition for database migration is triggered, database migration is started. The following first introduces how to perform database migration when the triggering condition is a business demand or a business adjustment.
[0118] like Figure 8 FIG. 1 is a flowchart of a method for database migration provided by an embodiment of the present invention, and the method comprises the following steps:
[0119] Step 801: receiving a migration instruction triggered by a user.
[0120] In the embodiment of the present invention, the specific content of this step is substantially the same as that of step 401 and will not be described in detail herein.
[0121] Step 802: Obtain database information of the database to be migrated according to the migration instruction.
[0122] In an embodiment of the present invention, the database to be migrated is a database with a master-slave mode, wherein the database in the master database state is called the third database, and the database in the slave database state is called the first database. Database information of the database to be migrated is obtained, wherein the database information to be migrated includes the state information of the database to be migrated and the data of the third database and the first database. If the state information of the database to be migrated is in a normal state and the data of the third database is consistent with that of the first database, the migration of the database to be migrated can be performed. If the state information of the database to be migrated is in an abnormal state and / or the data of the third database is inconsistent with that of the first database, the migration of the database to be migrated is terminated.
[0123] Step 803 , determining whether the database information to be migrated meets a preset condition, if so, executing step 804 , if not, executing step 805 .
[0124] In the embodiment of the present invention, if the status information of the database to be migrated is in a normal state and the data of the third database is consistent with the data of the first database, the database migration can be performed. If the status information of the database to be migrated is in an abnormal state and / or the data of the third database is inconsistent with the data of the first database, it means that there is an abnormality in the database to be migrated, and the database migration cannot be performed through subsequent methods.
[0125] Step 804: Perform a full database physical backup of the first database according to the migration instruction.
[0126] In the embodiment of the present invention, according to the migration instruction, it is determined that the database to be migrated needs to be migrated. Therefore, it is necessary to perform a full database physical backup on the standby database, that is, the first database. In this way, it is convenient to perform data restoration based on the full database physical backup later.
[0127] Step 805, terminate the migration of the database.
[0128] Step 806: Delete the first database from the first server of the database platform.
[0129] In the embodiment of the present invention, since the database is migrated online, the database can still work normally while migrating the database, so the standby database needs to be migrated first, so that the main database can still be used normally. To migrate the standby database, the first database needs to be deleted from the first server of the library platform. Specifically, the file system corresponding to the first database is uninstalled from the first server of the database platform and the first container corresponding to the first database is deleted.
[0130] Step 807: construct a second database on a second server of the database platform.
[0131] In the embodiment of the present invention, in step 806, the first database is deleted from the first server of the database platform, and then the second database is constructed on the second server of the database platform, wherein a second container corresponding to the second database is constructed and the IP address of the second container is set to be the same as the IP address of the first container. In this way, the service IP before and after the database migration remains unchanged, the business party does not need to make any changes, the application is unaware, and the user experience is improved.
[0132] Step 808: Based on the full database physical backup corresponding to the first database, restore the data of the second database, thereby completing the data migration.
[0133] In the embodiment of the present invention, the specific content of this step is substantially the same as that of step 103 and will not be described in detail herein.
[0134] Step 809: after determining that the data in the second database is consistent with the data in the third database, the second database is set as the primary database and the third database is set as the backup database.
[0135] In an embodiment of the present invention, if the data of the second database is inconsistent with the data of the third database, it means that the database is abnormal, the migration of the standby database fails, and the database migration ends. If the data of the second database is consistent with the data of the third database, it means that the migration of the standby database is completed. Since the migration condition is a business demand or a business adjustment, the migration condition requires both the primary database and the standby database to perform database migration. Therefore, after the migration of the standby database is completed, it is necessary to perform database migration on the primary database. It should be noted that since it is necessary to ensure that the database can be used normally during the database migration, it is necessary to set the second database as the primary database and the third database as the standby database. In this way, the second database that has completed the migration is used as the primary database, which can ensure that the database can be used normally. After the third database is set as the standby database, the third database is migrated. The specific content is the same as the principle of the above steps 805 to 807.
[0136] Step 810: After performing a full database physical backup on the third database, delete the third database.
[0137] In the embodiment of the present invention, since the third database is set as a standby database, it is necessary to perform a full database physical backup of the third database before migrating the database. After performing a full database physical backup of the third database, the third database needs to be deleted. By deleting the third database, the IP address of the subsequently constructed database can be the same as that of the third database. In this way, the third database can be replaced by the subsequently constructed database without the business party having to make any changes and the application being unaware, thereby improving the user experience.
[0138] Step 811: construct a fourth database on the third server of the database platform, and set the fourth database as a backup database for the second database.
[0139] Step 812: restore data of the fourth database based on the full database physical backup corresponding to the third database, thereby completing data migration.
[0140] Step 813: When it is determined that the data in the second database is consistent with the data in the fourth database, the database migration is completed.
[0141] It can be seen from the above steps 801 to 813 that by performing the active / standby switching, normal use of the database is not affected while the database is being migrated.
[0142] like Fig. 9 FIG. 1 is a flowchart of a method for database migration provided by an embodiment of the present invention, and the method comprises the following steps:
[0143] Step 901: When it is detected that the first server is in a downtime state, obtain the second server.
[0144] In the embodiment of the present invention, when it is detected that the first server is in a downtime state, a second server is obtained, wherein the second server may be determined through steps 501 to 502. For details, please refer to steps 501 to 502, which will not be described again.
[0145] Step 902: Delete the first database from the first server of the database platform.
[0146] In the embodiment of the present invention, the specific content of this step is the same as step 101 and will not be described in detail here.
[0147] Step 903: construct a second database on a second server of the database platform.
[0148] In the embodiment of the present invention, the specific content of this step is the same as step 102 and will not be described in detail here.
[0149] Step 904: restore the data of the second database based on the full database physical backup corresponding to the first database, thereby completing the data migration.
[0150] Step 905: When it is determined that the data in the second database is consistent with the data in the third database, the database migration is completed.
[0151] It can be seen from the above steps 901 to 905 that when the database server is down, only the database on the down server needs to be migrated. Therefore, the database on the down server is switched to a standby database. This allows the normal use of the database to be maintained while the database migration is being performed.
[0152] Based on the same technical concept, the embodiment of the present application provides a device for database migration, which can be seen in Fig.10 The device 1000 includes: an acquisition unit 1001, which is used to delete a first database from a first server of a database platform; the first database is in a standby database state and a third database in a master database state is in a normal working state; a processing unit 1002, which is used to build a second database on a second server of the database platform, and set the second database as a standby database of the third database; based on the full database physical backup corresponding to the first database, the data of the second database is restored, thereby completing the data migration; the full database physical backup is performed before deleting the first database; when it is determined that the data of the second database is consistent with the data of the third database, the database migration is completed.
[0153] Optionally, the database platform creates a corresponding independent container for any database through container technology; the acquisition unit 1001 is specifically used to: uninstall the file system corresponding to the first database from the first server of the database platform and delete the first container corresponding to the first database. The processing unit 1002 is specifically used to: register the second database on the second server of the database platform and build a second container corresponding to the second database.
[0154] Optionally, the processing unit 1002 is specifically configured to: construct a second container corresponding to the second database and set the IP address of the second container to be the same as the IP address of the first container.
[0155] Optionally, the processing unit 1002 is specifically used to: obtain resource demand information of the first database; and use a server in the database platform that is in normal operation, has a database creation function, and has remaining resources that meet the resource demand information as a second server.
[0156] Optionally, the acquisition unit 1001 is also used to: when it is detected that the first server is in a down state, use each database of the first server as the first database to be migrated; set the database in the main database state on the first server to the backup database state and be unavailable; set the database in the backup database state on the first server to be unavailable.
[0157] Optionally, the acquisition unit 1001 is specifically used to: monitor the container status of a container corresponding to any database on the first server; when the container status is abnormal, detect the network status of the container; when the network status is abnormal, detect the port status of the port corresponding to the server where the container is located; if the port status is abnormal, determine that the first server is in a down state.
[0158] Optionally, processing unit 1002 is specifically used to: obtain from the database platform an alternative server that is in normal operation and has the function of creating a database; determine as the second server an alternative server whose remaining resources meet the resource requirement information and whose storage type is the same as that of the first server; if there is no alternative server whose remaining resources meet the resource requirement information and whose storage type is the same as that of the first server, determine as the second server an alternative server whose remaining resources meet the resource requirement information from alternative servers with different storage types.
[0159] Optionally, the resource requirement information includes CPU information, memory information, and storage space information; the processing unit 1002 is specifically used to: determine, based on the remaining resources of the alternative servers, an alternative server whose resource information is higher than that of the first database and whose storage type is the same as that of the first server as a target alternative server; determine a first score corresponding to the target alternative server based on the CPU information, memory information, storage space information and their respective corresponding weights in the remaining resources of the target alternative server; and determine a second server based on the first scores corresponding to each target alternative server.
[0160] Optionally, the acquisition unit 1001 is also used to: receive a migration instruction triggered by a user; the migration instruction includes a first identifier corresponding to the first database to be migrated and a second identifier corresponding to the second server; if the database to be migrated is in the master database state, then based on the migration instruction, a full database physical backup is performed on the first database; the first database is a standby database of the database to be migrated.
[0161] Optionally, the acquisition unit 1001 is specifically used to: after determining that the data in the second database is consistent with the data in the third database, set the second database as the main database and the third database as the backup database; after performing a full database physical backup of the third database, delete the third database; build a fourth database on a third server of the database platform, and set the fourth database as the backup database of the second database; based on the full database physical backup corresponding to the third database, restore the data of the fourth database, thereby completing the data migration; when it is determined that the data in the second database is consistent with the data in the fourth database, the database migration is completed.
[0162] Based on the same technical concept, the present application embodiment provides a computing device, such as Fig.11 As shown, it includes at least one processor 1101 and a memory 1102 connected to the at least one processor. The specific connection medium between the processor 1101 and the memory 1102 is not limited in the embodiment of the present application. Fig.11 For example, the processor 1101 and the memory 1102 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, etc.
[0163] In the embodiment of the present application, the memory 1102 stores instructions that can be executed by at least one processor 1101, and the at least one processor 1101 can perform the steps of the above-mentioned database migration method by executing the instructions stored in the memory 1102.
[0164] Among them, the processor 1101 is the control center of the computing device, and can use various interfaces and lines to connect various parts of the computing device, and realize the method of database migration by running or executing instructions stored in the memory 1102 and calling data stored in the memory 1102. Optionally, the processor 1101 may include one or more processing units, and the processor 1101 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor can also be integrated into the processor 1101. In some embodiments, the processor 1101 and the memory 1102 can be implemented on the same chip, and in some embodiments, they can also be implemented separately on independent chips.
[0165] Processor 1101 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware processor for execution, or can be executed by a combination of hardware and software modules in the processor.
[0166] Memory 1102, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules. Memory 1102 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (Random Access Memory, RAM), static random access memory (Static Random Access Memory, SRAM), programmable read-only memory (Programmable Read Only Memory, PROM), read-only memory (Read Only Memory, ROM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), magnetic memory, disk, optical disk, etc. Memory 1102 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer device, but is not limited thereto. The memory 1102 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0167] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium storing a computer program executable by a computer device. When the program runs on the computer device, the computer device executes the steps of the above-mentioned database migration method.
[0168] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0169] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0170] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0171] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0172] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for database migration, characterized in that: include: Deleting the first database from the first server of the database platform; The first database is in a standby database state and the third database in a master database state is in a normal working state; Building a second database on a second server of the database platform, and setting the second database as a standby database of the third database; Based on the full database physical backup corresponding to the first database, restore the data of the second database, thereby completing the data migration; The full database physical backup is performed before deleting the first database; When it is determined that the data in the second database is consistent with the data in the third database, the database migration is completed.
2. The method according to claim 1, characterized in that The database platform uses container technology to create a corresponding independent container for any database; Deleting a first database from a first server of a database platform includes: Uninstalling a file system corresponding to a first database from a first server of a database platform and deleting a first container corresponding to the first database; Building a second database on a second server of the database platform includes: A second database is registered on a second server of the database platform and a second container corresponding to the second database is constructed.
3. The method according to claim 2, characterized in that Constructing a second container corresponding to the second database includes: A second container corresponding to the second database is constructed and an IP address of the second container is set to be the same as the IP address of the first container.
4. The method according to any one of claims 1 to 3, characterized in that Determining the second server from the database platform in the following manner includes: Acquiring resource demand information of the first database; A server in the database platform that is in normal operation, has a database creation function, and whose remaining resources meet the resource demand information of the first database is used as the second server.
5. The method according to claim 4, characterized in that Before deleting the first database from the first server of the database platform, the method further includes: When detecting that the first server is in a downtime state, taking each database of the first server as a first database to be migrated; Setting the database in the primary database state on the first server to the standby database state and making it unavailable; The database in the standby state on the first server is set to be unavailable.
6. The method according to claim 5, characterized in that Detecting that the first server is in a down state includes: Monitoring the container status of any container corresponding to the database on the first server; When the container status is abnormal, detecting the network status of the container; When the network status is abnormal, detecting the port status of the port corresponding to the server where the container is located; If the port status is abnormal, it is determined that the first server is in a downtime state.
7. The method according to claim 5, characterized in that The server in the database platform that is in a normal operating state, has a database creation function, and has remaining resources that meet the resource demand information is used as a second server, including: Acquire a candidate server in normal operation and having a database creation function from the database platform; Determine a candidate server whose remaining resources meet the resource requirement information and whose storage type is the same as that of the first server as the second server; If there is no candidate server whose remaining resources meet the resource requirement information and whose storage type is the same as that of the first server, a candidate server whose remaining resources meet the resource requirement information is determined from candidate servers of different storage types as the second server.
8. The method according to claim 4, characterized in that The remaining resource demand information includes CPU information, memory information, and storage space information; Determining a candidate server whose remaining resources meet the resource requirement information and whose storage type is the same as that of the first server as the second server includes: According to the remaining resources of the candidate servers, determining the candidate servers whose resource information is higher than that of the first database and whose storage type is the same as that of the first server as the target candidate servers; Determine a first score corresponding to the target candidate server based on CPU information, memory information, storage space information and respective corresponding weights in the remaining resources of the target candidate server; A second server is determined according to the first score corresponding to each target candidate server.
9. The method according to claim 4, characterized in that Before deleting the first database from the first server of the database platform, the method further includes: Receiving a migration instruction triggered by a user; the migration instruction includes a first identifier corresponding to the database to be migrated and a second identifier corresponding to the second server; If the database to be migrated is in the master database state, a full database physical backup is performed on the first database based on the migration instruction; the first database is a standby database of the database to be migrated.
10. The method according to claim 9, characterized in that When it is determined that the data in the second database is consistent with the data in the third database, the database migration is completed, including: After determining that the data in the second database is consistent with the data in the third database, setting the second database as a primary database and setting the third database as a backup database; After performing a full database physical backup on the third database, deleting the third database; Building a fourth database on a third server of the database platform, and setting the fourth database as a standby database of the second database; Based on the full database physical backup corresponding to the third database, data of the fourth database is restored, thereby completing the data migration; When it is determined that the data in the second database is consistent with the data in the fourth database, the database migration is completed.
11. A device for database migration, characterized in that: include: An acquisition unit, used for deleting a first database from a first server of a database platform; The first database is in a standby database state and the third database in a master database state is in a normal working state; A processing unit, configured to construct a second database on a second server of the database platform, and set the second database as a standby database of the third database; Based on the full database physical backup corresponding to the first database, restore the data of the second database, thereby completing the data migration; The full database physical backup is performed before deleting the first database; When it is determined that the data in the second database is consistent with the data in the third database, the database migration is completed.
12. A computing device, characterized in that: The method comprises at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program, and when the program is executed by the processing unit, the processing unit executes any one of the methods of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: It stores a computer program executable by a computing device, and when the program is run on the computing device, the computing device executes any one of the methods of claims 1 to 10.
14. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to claim 1 are implemented.
Citation Information
Patent Citations
Detection method of downtime server and high-availability recovery method and device of database
CN114443341A
Database elastic method, database elastic device and database elastic service system
CN114996351A
Database migration method and device, electronic equipment and readable storage medium
CN115098469A
Data migration method and device based on MasterHA and storage medium
CN116821092A
Automated self-healing database system and method for implementing the same
US20180239677A1
