A Method, Device, Equipment and Storage Medium for Database Migration to the Cloud

By determining the validity checksum type of physical backup files on the cloud platform, the problem of low storage occupancy and efficiency in database migration to the cloud is solved, and safe and efficient data migration is achieved.

CN114328463BActive Publication Date: 2025-07-25SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111678589.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-31
Publication Date
2025-07-25
Estimated Expiration
2041-12-31

AI Technical Summary

Technical Problem

In the process of database migration to the cloud, physical backup files occupy a large amount of storage space, cannot determine the file legality, data import efficiency is low, and conflicts cannot be effectively handled.

Method used

By physically backing up the target database, uploading it to the distributed object storage of the cloud platform, and performing validity verification, determining the import type, import the file into the cloud platform database instance.

Benefits of technology

It realizes safe and efficient database physical backup data migration, reduces storage usage, improves data import efficiency and handles import conflicts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114328463B_ABST
    Figure CN114328463B_ABST
Patent Text Reader

Abstract

The present application discloses a method, apparatus, device and storage medium for migrating a database to the cloud, including: performing a physical backup on the entire target database to obtain a target physical backup file, and uploading the target physical backup file to a distributed object storage on the same cloud platform; obtaining a validity verification result obtained by the cloud platform for performing validity verification on the target physical backup file; if the validity verification result indicates that the target physical backup file is a valid file, determining the import type of the target physical backup file; and importing some or all of the target physical backup files into a target database instance on the cloud platform according to the import type. The present application imports in the form of physical files and pre-verifies the physical backup files before import to prevent the impact caused by directly importing into the target database instance, and can migrate the physical backup data of the database to the cloud database instance more safely and efficiently.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database technologies, and particularly to a method, apparatus, device, and storage medium for migrating a database to the cloud. Background Art

[0002] In the current Internet environment with massive traffic, cloud databases, as the underlying data aggregation and access support for application systems, their rich and diverse database types, highly reliable and flexibly definable specification deployment methods, and distributed disaster recovery and expansion capabilities are important directions for the current development of databases.

[0003] Users' business data in the database, as important enterprise assets, should be migrated to the database instance on the cloud simultaneously when migrating the database application. However, due to the operating environment of traditional business systems often not having the condition of external network access, or the security policies of users not allowing direct access to the database instance of the original business system. In this case, users can choose to quickly back up the data by directly packaging the physical data files of the existing database instance or by using data backup tools. Database products on the cloud can implement database migration to the cloud based on the physical backup data provided by users.

[0004] In the above scenarios and technical trends of database migration to the cloud, how to securely and efficiently migrate the physical backup data provided by traditional databases under the cloud to the cloud database instance is the first problem to be solved in the cloudification of traditional application systems. Currently, the mainstream database backup and recovery methods for MySQL (a relational database management system) usually perform a complete recovery of the entire database instance or filter data based on the intermediate logical export results. The above technical solutions have the following problems: 1. The physical backup files of data are large, and directly uploading them to the user's database instance will occupy additional storage space; 2. It is impossible to determine whether the physical backup data is legal; 3. Filtering data based on the data logical export method has low execution efficiency; 4. It is impossible to effectively handle the conflict problem of imported data.

[0005] Therefore, how to securely and efficiently migrate the physical backup data of the database to the cloud database instance is a problem that still needs to be further solved at present. Summary of the Invention

[0006] In view of this, the purpose of this application is to provide a method, apparatus, device, and storage medium for migrating a database to the cloud, which can securely and efficiently migrate the physical backup data of the database to the cloud database instance. The specific solutions are as follows:

[0007] In a first aspect, this application discloses a method for migrating a database to the cloud, including:

[0008] Perform a physical backup of the entire target database to obtain a target physical backup file, and upload the target physical backup file to the distributed object storage of the same cloud platform;

[0009] Obtain the validity check result obtained by the cloud platform for the validity check of the target physical backup file;

[0010] If the validity check result indicates that the target physical backup file is a valid file, determine the import type of the target physical backup file; the import type includes full import into an instance, partial import into an empty instance, and partial import into a non-empty instance;

[0011] Import some or all of the target physical backup files into the target database instance of the cloud platform according to the import type.

[0012] Optionally, the uploading the target physical backup file to the distributed object storage of the same cloud platform includes:

[0013] Obtain the storage location information, storage space information, and database version information assigned by the user for the target physical backup file on the distributed object storage of the same cloud platform;

[0014] Upload the target physical backup file to the distributed object storage according to the storage location information;

[0015] Determine the target database container image corresponding to the database version information from the image repository of the cloud platform, and start the database instance container of the corresponding version of the target database container image;

[0016] Mount a distributed storage space for the database instance container based on the storage space information to obtain a temporary database instance.

[0017] Optionally, the obtaining the validity check result obtained by the cloud platform for the validity check of the target physical backup file includes:

[0018] Download the target physical backup file in the distributed object storage to the temporary database instance, and start the database service of the temporary database instance;

[0019] If the database service fails to start, determine that the validity check result of the target physical backup file is an invalid file;

[0020] If the database service is successfully started, obtain the running log information of the database service, and analyze whether there is error log information in the log information that affects the use of the temporary database instance. If there is, determine that the validity check result of the target physical backup file is an invalid file; if not, determine that the validity check result of the target physical backup file is a valid file.

[0021] Optionally, importing all the target physical backup files into the target database instance of the cloud platform according to the import type includes:

[0022] If the import type is to import all into the instance, import all the data of the target physical backup file in the temporary database instance into the target database instance of the cloud platform.

[0023] Optionally, determining the import type of the target physical backup file includes:

[0024] When the first database table to be imported selected by the user from the target physical backup file is obtained, determine whether there is old data in the preset target database instance;

[0025] If there is no old data in the target database instance, determine that the import type of the target physical backup file is to partially import into an empty instance;

[0026] Correspondingly, importing some of the target physical backup files into the target database instance of the cloud platform according to the import type includes:

[0027] Download the target physical backup file in the temporary database instance to the target database instance of the cloud platform according to the preset first renamed database table mapping relationship, and start the database service of the target database instance;

[0028] Calculate the complement of the unselected database tables corresponding to the first database table to be imported, delete the database table complement by executing SQL commands, and then delete the target physical backup file in the temporary database instance.

[0029] Optionally, determining the import type of the target physical backup file includes:

[0030] When the second database table to be imported selected by the user from the target physical backup file is obtained, determine whether there is old data in the preset target database instance;

[0031] If there is old data in the target database instance, determine that the import type of the target physical backup file is to partially import into a non-empty instance;

[0032] Correspondingly, importing some of the target physical backup files into the target database instance of the cloud platform according to the import type includes:

[0033] Create a new database table in the target database instance according to the second database table to be imported, download the second database table to be imported from the temporary database instance to the new database table according to the preset second renamed database table mapping relationship, and delete the target physical backup file in the temporary database instance.

[0034] Optionally, before importing some or all of the target physical backup files into the target database instance of the cloud platform according to the import type, it further includes:

[0035] Obtain the parameter information of the target physical backup file; the parameter information includes the database version information of the target physical backup file and the size of the target physical backup file;

[0036] Judge whether the target database instance meets the preset migration conditions according to the parameter information, and if it meets, execute the step of importing some or all of the target physical backup files into the target database instance of the cloud platform according to the import type.

[0037] In a second aspect, the present application discloses a database migration to cloud device, including:

[0038] A physical backup module, configured to perform a physical backup on the entire target database to obtain a target physical backup file, and upload the target physical backup file to a distributed object storage of the same cloud platform;

[0039] A validity verification module, configured to obtain the validity verification result obtained by the cloud platform for performing validity verification on the target physical backup file;

[0040] An import type determination module, configured to determine the import type of the target physical backup file when the validity verification result indicates that the target physical backup file is a valid file; the import type includes full import to an instance, partial import to an empty instance, and partial import to a non-empty instance;

[0041] A file import module, configured to import some or all of the target physical backup files into the target database instance of the cloud platform according to the import type.

[0042] In a third aspect, the present application discloses an electronic device, including a processor and a memory; wherein, when the processor executes the computer program stored in the memory, the foregoing database migration to cloud method is implemented.

[0043] Fourthly, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the foregoing method for migrating a database to the cloud is implemented.

[0044] It can be seen that the present application first performs a physical backup on the entire target database to obtain a target physical backup file, and uploads the target physical backup file to a distributed object storage on the same cloud platform. Then, it obtains the validity check result obtained by the cloud platform for validating the target physical backup file. When the validity check result indicates that the target physical backup file is a valid file, it determines the import type of the target physical backup file; the import type includes full import into an instance, partial import into an empty instance, and partial import into a non-empty instance. Then, according to the import type, part or all of the target physical backup file is imported into the target database instance on the cloud platform. It can be seen that the present application imports in the form of physical files and pre-checks the physical backup files before import to prevent the impact caused by directly importing into the target database instance, and can migrate the physical backup data of the database to the cloud database instance more safely and efficiently. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained according to the provided drawings.

[0046] Figure 1 It is a flowchart of a method for migrating a database to the cloud disclosed by the present application;

[0047] Figure 2 It is a flowchart of a specific method for migrating a database to the cloud disclosed by the present application;

[0048] Figure 3 It is a flowchart of a specific method for migrating a database to the cloud disclosed by the present application;

[0049] Figure 4 It is a flowchart of a specific method for migrating a database to the cloud disclosed by the present application;

[0050] Figure 5 It is a schematic structural diagram of a device for migrating a database to the cloud disclosed by the present application;

[0051] Figure 6 It is a structural diagram of an electronic device disclosed by the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0052] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts shall fall within the protection scope of the present application.

[0053] An embodiment of the present application discloses a method for migrating a database to the cloud. As shown in Figure 1 the following, this method includes:

[0054] Step S11: Perform a physical backup of the entire target database to obtain a target physical backup file, and upload the target physical backup file to the distributed object storage of the same cloud platform.

[0055] In this embodiment, first, it is necessary to perform a physical backup of all the data in the target database to obtain a target physical backup file, and then upload the obtained target physical backup file after backup to the distributed object storage of the same cloud platform. Among them, the target physical backup file can be a file in the form of a compressed complete data directory after the target database stops running normally, or a backup file obtained by compressing all the data in the target database using a data backup tool; the target database includes, but is not limited to, MySQL databases, Oracle databases, etc.

[0056] Step S12: Obtain the validity check result obtained by the cloud platform for performing a validity check on the target physical backup file.

[0057] In this embodiment, after physically backing up the entire target database to obtain a target physical backup file and uploading the target physical backup file to the distributed object storage of the same cloud platform, the cloud platform can verify the validity of the obtained target physical backup file to obtain a corresponding validity verification result. In a specific implementation manner, before uploading the target physical backup file to the distributed object storage of the same cloud platform, the description information of the target physical backup file specified by the user can be obtained; the description information includes but is not limited to the storage location information of the target physical backup file on the distributed object storage (such as access address, storage bucket, and account, etc.), database version information, and the estimated occupied storage space, etc. Then, the target physical backup file is saved according to the storage location information in the description information input by the user, and then the target database container image is pulled from the image repository of different versions of database container images pre-stored on the cloud platform according to the database version information in the description information input by the user, and a database instance container with the same version as the target database container image is started. Further, the corresponding storage space is allocated to the database instance container according to the estimated occupied storage space in the description information to obtain a temporary database instance. Further, the target physical backup file in the distributed object storage is downloaded to the temporary database instance. It can be understood that when the target physical backup file is a compressed file, during the above download process, the streaming decompression technology can be used to decompress while downloading to obtain a decompressed file in the corresponding directory form, and the database service is started on the directory of the decompressed file, and the running log of the database service is analyzed. If there is no error information affecting the normal operation of the temporary database instance in the running log, it can be determined that the target physical backup file is a valid file. If there is error information affecting the normal operation of the temporary database instance in the running log, it can be determined that the target physical backup file is an invalid file. Further, if it is determined that the target physical backup file is an invalid file, the target physical backup file in the temporary database instance can be deleted to release the storage space of the temporary database instance.

[0058] In addition, after obtaining the validity verification result obtained by the cloud platform for verifying the validity of the target physical backup file, the definition description files of the database and database tables included in the target physical backup file can also be exported through the database client tool, and the definition description files and the above validity verification result are returned to the front-end application together. So that when the validity verification result is a valid file, the databases and database tables included in the definition description file are displayed on the front-end page, which is convenient for users to select the target database tables that need to be migrated to the cloud according to their own backup needs.

[0059] Step S13: If the validity check result indicates that the target physical backup file is a valid file, determine the import type of the target physical backup file; the import type includes full import to an instance, partial import to an empty instance, and partial import to a non-empty instance.

[0060] In this embodiment, after obtaining the validity check result obtained by the cloud platform for the target physical backup file, if the validity check result indicates that the above target physical backup file is a valid file, the import type of the target physical backup file can be determined according to the user's selection; wherein, the import type includes full import to an instance, partial import to an empty instance, and partial import to a non-empty instance; full import to an instance means migrating all the data in the target physical backup file to the target database instance preset by the cloud platform; partial import to an empty instance means importing part of the data in the target physical backup file to the target database instance preset by the cloud platform according to the user's selection, and no data is saved in the target database instance; partial import to a non-empty instance means importing part of the data in the target physical backup file to the target database instance preset by the cloud platform according to the user's selection, and data has been saved in the target database instance.

[0061] Step S14: Import some or all of the target physical backup files to the target database instance of the cloud platform according to the import type.

[0062] In this embodiment, after determining the import type of the target physical backup file, all the data in the above target physical backup file or part of the data to be backed up selected by the user can be saved to the target database instance located on the cloud platform preselected by the user according to the import type.

[0063] In a specific implementation manner, the importing all of the target physical backup files to the target database instance of the cloud platform according to the import type may specifically include: if the import type is full import to an instance, import all the data of the target physical backup file in the temporary database instance to the target database instance of the cloud platform. It can be understood that when receiving the instruction from the user to back up all the data of the target physical backup file, all the data of the target physical backup file can be directly imported to the above target database instance, and the target physical backup file in the temporary database instance is deleted after the import is completed.

[0064] In this embodiment, before importing some or all of the target physical backup files into the target database instance of the cloud platform according to the import type, the following steps are specifically further included: obtaining the parameter information of the target physical backup files; the parameter information includes the database version information of the target physical backup files and the size of the target physical backup files; judging whether the target database instance meets the preset migration conditions according to the parameter information, and if so, executing the step of importing some or all of the target physical backup files into the target database instance of the cloud platform according to the import type. It can be understood that before importing the target physical backup files into the target database instance of the cloud platform, the parameter information including the database version information corresponding to the target physical backup files and the size of the target physical backup files can be obtained first, and then it is judged whether the database version information corresponding to the target physical backup files matches the target database instance according to the parameter information. If they match, the remaining storage space of the target database instance and the size of the target physical backup files are further compared to obtain a comparison result, and it is judged whether the preset conditions are met according to the comparison result. If so, the step of importing some or all of the target physical backup files into the target database instance of the cloud platform according to the import type can be executed.

[0065] It can be seen that in the embodiment of the present application, the entire target database is physically backed up first to obtain the target physical backup files, and the target physical backup files are uploaded to the distributed object storage of the same cloud platform. Then, the validity check result obtained by the cloud platform for the target physical backup files is obtained. When the validity check result indicates that the target physical backup files are valid files, the import type of the target physical backup files is determined; the import type includes importing all into the instance, importing part into the empty instance, and importing part into the non-empty instance. Then, some or all of the target physical backup files are imported into the target database instance of the cloud platform according to the import type. It can be seen that the present application imports through the physical file method and pre-checks the physical backup files before importing to prevent the impact caused by directly importing into the target database instance, and can migrate the physical backup data of the database to the cloud database instance more safely and efficiently.

[0066] The embodiment of the present application discloses a specific method for migrating a database to the cloud. Refer to Figure 2 as shown, this method includes:

[0067] Step S21: Physically back up the entire target database to obtain the target physical backup files.

[0068] Step S22: Obtain the storage location information, storage space information, and database version information assigned by the user for the target physical backup file on the distributed object storage of the same cloud platform.

[0069] In this embodiment, after performing a physical backup on the entire target database to obtain the target physical backup file, the storage location information, storage space information, and database version information assigned by the user in advance for the above-mentioned target physical backup file on the distributed object storage of the same cloud platform can be obtained.

[0070] Step S23: Upload the target physical backup file to the distributed object storage according to the storage location information.

[0071] In this embodiment, after obtaining the storage location information, storage space information, and database version information assigned by the user for the target physical backup file on the distributed object storage of the same cloud platform, the target physical backup file can be sent to the distributed object storage according to the storage location information specified by the user.

[0072] Step S24: Determine a target database container image corresponding to the database version information from the image repository of the cloud platform, and start a database instance container corresponding to the version of the target database container image.

[0073] In this embodiment, after uploading the target physical backup file to the distributed object storage according to the storage location information, a target database container image of the corresponding version can be determined from the image repository of the cloud platform according to the database version information specified by the user. Specifically, based on the database version information and using container technology, the target database container image can be pulled from the image repository in a very short time (in seconds) in the public resource space of the virtualization platform (such as the K8S environment), and then a database instance container corresponding to the version of the target database container image is started.

[0074] Step S25: Mount a distributed storage space for the database instance container based on the storage space information to obtain a temporary database instance.

[0075] In this embodiment, after determining a target database container image corresponding to the database version information from the image repository of the cloud platform and starting a database instance container corresponding to the version of the target database container image, a distributed storage space of the corresponding size can be mounted for the database instance container according to the storage space information to obtain a temporary database instance.

[0076] Step S26: Download the target physical backup file in the distributed object storage to the temporary database instance, and start the database service of the temporary database instance.

[0077] In this embodiment, after mounting the distributed storage space to the database instance container based on the storage space information to obtain a temporary database instance, the above-mentioned target physical backup file saved in the distributed object storage is downloaded to the temporary database instance, and the database service of the temporary database instance is started.

[0078] Step S27: If the database service fails to start, determine that the validity check result of the target physical backup file is an invalid file.

[0079] In this embodiment, after downloading the target physical backup file in the distributed object storage to the temporary database instance and starting the database service of the temporary database instance, if the above database service fails to start, it indicates that there is a problem with the target physical backup file, and it is determined that the target physical backup file is an invalid file and deleted from the temporary database instance. At the same time, the invalid file is returned to the front-end application as the validity check result of the target physical backup file.

[0080] Step S28: If the database service starts successfully, obtain the running log information of the database service, and analyze whether there is error log information that affects the use of the temporary database instance in the log information. If it exists, determine that the validity check result of the target physical backup file is an invalid file; if it does not exist, determine that the validity check result of the target physical backup file is a valid file.

[0081] In this embodiment, after downloading the target physical backup file in the distributed object storage to the temporary database instance and starting the database service of the temporary database instance, if the above database service starts successfully, obtain the running log information of the database service and analyze the log information to determine whether there is error log information that affects the use of the temporary database instance. If there is error log information that affects the use of the temporary database instance, it indicates that there is a problem with the target physical backup file and it cannot be directly migrated to the cloud platform. Then, determine that the validity check result of the target physical backup file is an invalid file, delete it from the temporary database instance, and at the same time return the invalid file to the front-end application as the validity check result of the target physical backup file. If there is no error log information that affects the use of the temporary database instance, determine that the validity check result of the target physical backup file is a valid file, and return the valid file to the front-end application as the validity check result of the target physical backup file.

[0082] Step S29: If the validity check result indicates that the target physical backup file is a valid file, determine the import type of the target physical backup file; the import type includes full import into the instance, partial import into an empty instance, and partial import into a non-empty instance.

[0083] Step S210: Import some or all of the target physical backup files into the target database instance of the cloud platform according to the import type.

[0084] Among them, for the more specific processing procedures of the above steps S21, S29, and S210, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be elaborated herein.

[0085] It can be seen that in the embodiment of the present application, the temporary database instance created in the cloud platform can pre-check the correctness and integrity of the target physical backup file obtained by physical backup, discover the problems existing in the target physical backup file early, prevent the impact caused by directly importing into the target database instance, and prevent the problem that the target database instance cannot be used after the import fails.

[0086] The embodiment of the present application discloses a specific method for migrating a database to the cloud. Refer to Figure 3 As shown, the method includes:

[0087] Step S31: Physically back up the entire target database to obtain a target physical backup file, and upload the target physical backup file to the distributed object storage of the same cloud platform.

[0088] Step S32: Obtain the validity check result obtained by the cloud platform for the target physical backup file.

[0089] Step S33: If the validity check result indicates that the target physical backup file is a valid file and the first database table to be imported selected by the user from the target physical backup file is obtained, determine whether there is old data in the preset target database instance.

[0090] In this embodiment, if the validity check result indicates that the target physical backup file is a valid file and the database table to be imported selected by the user from the above target physical backup file, that is, the first database table to be imported, it is further determined whether there is old data in the cloud database instance specified by the user for data import in advance, that is, it is determined whether there is data in the target database instance.

[0091] Step S34: If there is no old data in the target database instance, determine that the import type of the target physical backup file is partial import into an empty instance.

[0092] In this embodiment, if there is no data in the target database instance, it is determined that the import type of the target physical backup file is partial import into an empty instance, that is, the selected partial database tables in the target physical backup file are imported into the empty instance without saved data.

[0093] Step S35: Download the target physical backup file in the temporary database instance to the target database instance of the cloud platform according to the preset first renamed database table mapping relationship, and start the database service of the target database instance.

[0094] In this embodiment, if there is no old data in the target database instance, after determining that the import type of the target physical backup file is partial import into an empty instance, first download the target physical backup file in the temporary database instance to the target database instance of the cloud platform according to the preset first renamed database table mapping relationship, and then start the database service of the target database instance.

[0095] Step S36: Calculate the complement of the unselected database tables corresponding to the first database table to be imported, delete the database table complement by executing SQL commands, and then delete the target physical backup file in the temporary database instance.

[0096] In this embodiment, after downloading the target physical backup file in the temporary database instance to the target database instance of the cloud platform according to the preset first renamed database table mapping relationship and starting the database service of the target database instance, calculate the database tables not selected by the user corresponding to the first database table to be imported, that is, the complement of the first database table to be imported, and then delete the database table complement by executing SQL (Structured Query Language) commands, and then delete the target physical backup file in the temporary database instance.

[0097] Among them, for the more specific processing procedures of the above steps S31 and S32, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be elaborated here.

[0098] It can be seen that when the import type of the target physical backup file in the embodiment of the present application is partial import to an empty instance, the target physical backup file in the temporary database instance is first downloaded to the target database instance of the cloud platform according to the preset first renamed database table mapping relationship, and the database service of the target database instance is started. Then, the complement of the database tables that are not selected corresponding to the first database tables to be imported is calculated, and the complement of the database tables is deleted by executing SQL commands. It can be seen that the embodiment of the present application can implement on-demand database table import according to the user's selection, and can refine the filtering level of data import to the table level, improving the efficiency of data import.

[0099] The embodiment of the present application discloses a specific method for migrating a database to the cloud. Refer to Figure 4 as shown, the method includes:

[0100] Step S41: Physically back up the entire target database to obtain a target physical backup file, and upload the target physical backup file to the distributed object storage of the same cloud platform.

[0101] Step S42: Obtain the validity check result obtained by the cloud platform for validating the target physical backup file.

[0102] Step S43: If the validity check result indicates that the target physical backup file is a valid file and the second database tables to be imported selected by the user from the target physical backup file are obtained, then determine whether there is old data in the preset target database instance.

[0103] In this embodiment, if the validity check result indicates that the above target physical backup file is a valid file and the database tables to be imported selected by the user from the above target physical backup file, that is, the second database tables to be imported, then further determine whether there is old data in the cloud database instance selected by the user for data import, that is, determine whether there is data in the target database instance.

[0104] Step S44: If there is old data in the target database instance, determine that the import type of the target physical backup file is partial import to a non-empty instance.

[0105] In this embodiment, if there is data in the target database instance, determine that the import type of the target physical backup file is partial import to a non-empty instance, that is, import the database tables selected by the user in the target physical backup file to a non-empty instance that already stores data.

[0106] Step S45: Create a new database table in the target database instance according to the second database table to be imported, download the second database table to be imported from the temporary database instance to the new database table according to the preset second database table renaming mapping relationship, and delete the target physical backup file in the temporary database instance.

[0107] In this embodiment, after determining that the import type of the target physical backup file is partial import to a non-empty instance, a new database table is created in the above-mentioned target database instance according to the second database table to be imported. For example, the new database is created through a database client tool, and then the second database table to be imported is circularly imported from the temporary database instance to the new database table according to the preset second database table renaming mapping relationship, that is, the second database table to be imported is renamed according to the second database table renaming mapping relationship and imported into the new database table. After the download is completed, the target physical backup file in the temporary database instance is deleted. It should be noted that in the process of downloading the second database table to be imported from the temporary database instance to the new database table according to the preset second database table renaming mapping relationship, in order to avoid the existence of a database table with the same name as the second database table to be imported in the target database instance, it can be first determined whether there is a database with the same name as the target database corresponding to the second database table to be imported in the target database instance. If it exists, a timestamp suffix (such as _20210731164500) will be added to the target database to be imported. Further, it is determined whether there are duplicate database tables under the database table with the same name as the second database table to be imported in the target database instance. If it exists, a timestamp suffix will be added to the database table with the same name.

[0108] Among them, for the more specific processing procedures of the above steps S41 and S42, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be elaborated here.

[0109] It can be seen that when the import type of the target physical backup file in the embodiment of the present application is partial import to a non-empty instance, a new database table is created in the target database instance according to the second database table to be imported, and the second database table to be imported is downloaded from the temporary database instance to the new database table according to the preset second database table renaming mapping relationship. It can be seen that the embodiment of the present application can meet the user's customized data migration requirements, directly complete the import using physical files, and can refine the data import filtering level to the table level, improving the data import efficiency.

[0110] Correspondingly, the embodiment of the present application also discloses a database migration to cloud device, see Figure 5As shown, the device includes:

[0111] A physical backup module 11 for physically backing up the entire target database to obtain a target physical backup file and uploading the target physical backup file to a distributed object storage on the same cloud platform;

[0112] A validity verification module 12 for obtaining a validity verification result obtained by the cloud platform for validity verification of the target physical backup file;

[0113] An import type determination module 13 for determining the import type of the target physical backup file when the validity verification result indicates that the target physical backup file is a valid file; the import type includes full import to an instance, partial import to an empty instance, and partial import to a non-empty instance;

[0114] A file import module 14 for importing some or all of the target physical backup files into a target database instance of the cloud platform according to the import type.

[0115] Among them, the specific working processes of the above-mentioned various modules can refer to the corresponding content disclosed in the foregoing embodiments, and will not be elaborated here.

[0116] It can be seen that in the embodiments of the present application, first, the entire target database is physically backed up to obtain a target physical backup file, and the target physical backup file is uploaded to a distributed object storage on the same cloud platform, and then the validity verification result obtained by the cloud platform for validity verification of the target physical backup file is obtained. When the validity verification result indicates that the target physical backup file is a valid file, the import type of the target physical backup file is determined; the import type includes full import to an instance, partial import to an empty instance, and partial import to a non-empty instance, and then some or all of the target physical backup files are imported into a target database instance of the cloud platform according to the import type. It can be seen that the present application imports in the form of physical files and pre-verifies the physical backup files before import to prevent the impact caused by directly importing into the target database instance, and can migrate the physical backup data of the database to the cloud database instance more safely and efficiently.

[0117] In some specific embodiments, the physical backup module 11 may specifically include:

[0118] A first information acquisition unit for acquiring storage location information, storage space information, and database version information assigned by the user to the target physical backup file on the distributed object storage on the same cloud platform;

[0119] A file upload unit, configured to upload the target physical backup file to the distributed object storage according to the storage location information;

[0120] A container image determination unit, configured to determine a target database container image corresponding to the database version information from an image repository of the cloud platform, and start a database instance container corresponding to the version of the target database container image;

[0121] A storage space mounting unit, configured to mount a distributed storage space for the database instance container based on the storage space information to obtain a temporary database instance.

[0122] In some specific embodiments, the validity verification module 12 may specifically include:

[0123] A file download unit, configured to download the target physical backup file in the distributed object storage to the temporary database instance, and start the database service of the temporary database instance;

[0124] A first invalid file determination unit, configured to determine that the validity verification result of the target physical backup file is an invalid file if the startup of the database service fails;

[0125] A log information acquisition unit, configured to acquire the running log information of the database service if the startup of the database service is successful;

[0126] A log information analysis unit, configured to analyze whether there is error log information affecting the use of the temporary database instance in the log information;

[0127] A second invalid file determination unit, configured to determine that the validity verification result of the target physical backup file is an invalid file if there is error log information affecting the use of the temporary database instance;

[0128] A valid file determination unit, configured to determine that the validity verification result of the target physical backup file is a valid file if there is no error log information affecting the use of the temporary database instance.

[0129] In some specific embodiments, the file import module 14 may specifically include:

[0130] A first data import unit, configured to, when the import type is all imported into the instance, import all the data of the target physical backup file in the temporary database instance into the target database instance of the cloud platform.

[0131] In some specific embodiments, the import type determination module 13 may specifically include:

[0132] A first judgment unit, configured to judge whether there is old data in a preset target database instance when a first database table to be imported selected by a user from the target physical backup file is obtained;

[0133] A first import type determination unit, configured to determine that the import type of the target physical backup file is partial import to an empty instance when there is no old data in the target database instance;

[0134] Correspondingly, the file import module 14 may specifically include:

[0135] A first file download unit, configured to download the target physical backup file in the temporary database instance to the target database instance of the cloud platform according to a preset first renamed database table mapping relationship, and start the database service of the target database instance;

[0136] A calculation unit, configured to calculate a complement of database tables that are not selected corresponding to the first database table to be imported;

[0137] A deletion unit, configured to delete the complement of the database tables by executing an SQL command, and then delete the target physical backup file in the temporary database instance.

[0138] In some specific embodiments, the import type determination module 13 may specifically include:

[0139] A second judgment unit, configured to judge whether there is old data in a preset target database instance when a second database table to be imported selected by a user from the target physical backup file is obtained;

[0140] A second import type determination unit, configured to determine that the import type of the target physical backup file is partial import to a non-empty instance when there is old data in the target database instance;

[0141] Correspondingly, the file import module 14 may specifically include:

[0142] A database table creation unit, configured to create a new database table in the target database instance according to the second database table to be imported;

[0143] A second file download unit, configured to download the second database table to be imported from the temporary database instance to the new database table according to a preset second renamed database table mapping relationship, and delete the target physical backup file in the temporary database instance.

[0144] In some specific embodiments, before the file import module 14, it may further include:

[0145] A second information acquisition unit, configured to acquire parameter information of the target physical backup file; the parameter information includes database version information of the target physical backup file and the size of the target physical backup file;

[0146] A third determination unit, configured to determine whether the target database instance meets a preset migration condition according to the parameter information;

[0147] An execution unit, configured to, when the target database instance meets the preset migration condition, execute the step of importing some or all of the target physical backup file into the target database instance of the cloud platform according to the import type.

[0148] Furthermore, an embodiment of the present application also discloses an electronic device, Figure 6 which is a structural diagram of an electronic device 20 shown according to an exemplary embodiment, and the content in the figure should not be considered as any limitation to the scope of use of the present application.

[0149] Figure 6 This is a schematic structural diagram of an electronic device 20 provided by an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. Among them, the memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the database migration to the cloud method disclosed in any of the foregoing embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0150] In this embodiment, the power supply 23 is used to provide working voltages for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows is any communication protocol applicable to the technical solution of the present application, and no specific limitation is imposed on it here; the input / output interface 25 is used to acquire external input data or output data to the outside, and its specific interface type can be selected according to specific application needs, and no specific limitation is made here.

[0151] In addition, as a carrier for resource storage, the memory 22 may be a read-only memory, a random access memory, a magnetic disk, or an optical disc, etc., and the resources stored thereon may include an operating system 221, a computer program 222, etc., and the storage method may be short-term storage or permanent storage.

[0152] Among them, the operating system 221 is used to manage and control each hardware device and computer program 222 on the electronic device 20, and it can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program that can be used to complete the database migration to the cloud method executed by the electronic device 20 disclosed in any of the foregoing embodiments, the computer program 222 can further include computer programs that can be used to complete other specific tasks.

[0153] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the database migration to the cloud method disclosed above. For the specific steps of this method, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be repeated here.

[0154] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. For the same or similar parts among the various embodiments, reference can be made to each other. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and reference can be made to the description of the method part for related parts.

[0155] Those skilled in the art can further realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the components and steps of each example have been generally described according to their functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.

[0156] The steps of the method or algorithm described in combination with the embodiments disclosed in this article can be directly implemented by hardware, software modules executed by a processor, or a combination of the two. The software modules can be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium well-known in the technical field.

[0157] Finally, it should also be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the said element.

[0158] The above has introduced in detail a database migration to the cloud method, apparatus, device and storage medium provided by this application. Specific examples are used in this text to elaborate on the principle and implementation manner of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application; at the same time, for those of ordinary skill in the art, according to the idea of this application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to this application.

Claims

1. A method for migrating a database to the cloud, characterized in that, Including: Performing a physical backup on the entire target database to obtain a target physical backup file, and uploading the target physical backup file to a distributed object storage of the same cloud platform; Obtaining a validity check result obtained by the cloud platform for performing a validity check on the target physical backup file; If the validity check result indicates that the target physical backup file is a valid file, determining the import type of the target physical backup file; the import type includes all imported into an instance, partially imported into an empty instance, and partially imported into a non-empty instance; Importing some or all of the target physical backup files into a target database instance of the cloud platform according to the import type; The determining the import type of the target physical backup file includes: when a second database table to be imported selected by the user from the target physical backup file is obtained, determining whether there is old data in a preset target database instance; if there is old data in the target database instance, determining that the import type of the target physical backup file is partially imported into a non-empty instance; Correspondingly, the importing some of the target physical backup files into the target database instance of the cloud platform according to the import type includes: creating a new database table in the target database instance according to the second database table to be imported, downloading the second database table to be imported from a temporary database instance to the new database table according to a preset second renamed database table mapping relationship, and deleting the target physical backup file in the temporary database instance; During the process of downloading the second database table to be imported from the temporary database instance to the new database table according to the preset second renamed database table mapping relationship, it further includes: determining whether there is a database with the same name as the target database corresponding to the second database table to be imported in the target database instance, and if so, adding a timestamp suffix to the target database to be imported; determining whether there are duplicate database tables under a database with the same name as the second database table to be imported in the target database instance, and if so, adding a timestamp suffix to the database tables with the same name; The uploading the target physical backup file to a distributed object storage of the same cloud platform includes: obtaining storage location information, storage space information, and database version information assigned by the user for the target physical backup file on the distributed object storage of the same cloud platform; uploading the target physical backup file to the distributed object storage according to the storage location information; determining a target database container image corresponding to the database version information from a mirror repository of the cloud platform, and starting a database instance container of the corresponding version of the target database container image; mounting a distributed storage space for the database instance container based on the storage space information to obtain a temporary database instance; Obtaining the validity check result obtained by the cloud platform for performing a validity check on the target physical backup file includes: downloading the target physical backup file in the distributed object storage to the temporary database instance, and starting the database service of the temporary database instance; if the database service fails to start, determining that the validity check result of the target physical backup file is an invalid file; if the database service starts successfully, obtaining the operation log information of the database service, and analyzing whether there is error log information affecting the use of the temporary database instance in the log information, if so, determining that the validity check result of the target physical backup file is an invalid file, if not, determining that the validity check result of the target physical backup file is a valid file.

2. The method for migrating a database to the cloud according to claim 1, wherein Importing all the target physical backup files into the target database instance of the cloud platform according to the import type includes: If the import type is to import all into the instance, importing all the data of the target physical backup file in the temporary database instance into the target database instance of the cloud platform.

3. The method for migrating a database to the cloud according to claim 1, wherein Determining the import type of the target physical backup file includes: When the first database table to be imported selected by the user from the target physical backup file is obtained, determining whether there is old data in the preset target database instance; If there is no old data in the target database instance, determining that the import type of the target physical backup file is to import part into an empty instance; Correspondingly, importing part of the target physical backup files into the target database instance of the cloud platform according to the import type includes: Downloading the target physical backup file in the temporary database instance to the target database instance of the cloud platform according to the preset first renamed database table mapping relationship, and starting the database service of the target database instance; Calculating the complement of the unselected database tables corresponding to the first database table to be imported, deleting the database table complement by executing SQL commands, and then deleting the target physical backup file in the temporary database instance.

4. The database migration to the cloud method according to any one of claims 1 to 3, characterized in that Before importing part or all of the target physical backup files into the target database instance of the cloud platform according to the import type, it further includes: Obtaining the parameter information of the target physical backup file; the parameter information includes the database version information of the target physical backup file and the size of the target physical backup file; Judging whether the target database instance meets the preset migration conditions according to the parameter information, if so, performing the step of importing part or all of the target physical backup files into the target database instance of the cloud platform according to the import type.

5. A database migration device to the cloud, characterized in that, Including: A physical backup module for performing a physical backup on the entire target database to obtain a target physical backup file, and uploading the target physical backup file to the distributed object storage of the same cloud platform; The validity verification module is used to obtain the validity verification result obtained by the cloud platform for the validity verification of the target physical backup file; The import type determination module is used to determine the import type of the target physical backup file when the validity verification result indicates that the target physical backup file is a valid file; the import types include all imported into an instance, partially imported into an empty instance, and partially imported into a non-empty instance; The file import module is used to import some or all of the target physical backup files into the target database instance of the cloud platform according to the import type; Specifically, when the second database table to be imported selected by the user from the target physical backup file is obtained, the import type determination module is used to determine whether there is old data in the preset target database instance; If there is old data in the target database instance, it is determined that the import type of the target physical backup file is partially imported into a non-empty instance; Correspondingly, the file import module is specifically used to create a new database table in the target database instance according to the second database table to be imported, download the second database table to be imported from the temporary database instance to the new database table according to the preset second renamed database table mapping relationship, and delete the target physical backup file in the temporary database instance; The device is further used to determine whether there is a database in the target database instance with the same name as the target database corresponding to the second database table to be imported, and if so, add a timestamp suffix to the target database to be imported; determine whether there are duplicate database tables under the database with the same name as the second database table to be imported in the target database instance, and if so, add a timestamp suffix to the database tables with the same name; Specifically, the physical backup module is used to obtain the storage location information, storage space information, and database version information assigned by the user for the target physical backup file on the distributed object storage in the same cloud platform; upload the target physical backup file to the distributed object storage according to the storage location information; determine the target database container image corresponding to the database version information from the image repository of the cloud platform, and start the database instance container corresponding to the version of the target database container image; mount the distributed storage space for the database instance container based on the storage space information to obtain a temporary database instance; The validity verification module is specifically configured to download the target physical backup file in the distributed object storage to the temporary database instance and start the database service of the temporary database instance; if the startup of the database service fails, it is determined that the validity verification result of the target physical backup file is an invalid file; if the startup of the database service is successful, it obtains the operation log information of the database service and analyzes whether there is error log information that affects the use of the temporary database instance in the log information. If there is, it is determined that the validity verification result of the target physical backup file is an invalid file, and if not, it is determined that the validity verification result of the target physical backup file is a valid file.

6. An electronic device, characterized in that, It includes a processor and a memory; wherein, when the processor executes the computer program stored in the memory, it implements the database migration to the cloud method according to any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, It is used to store a computer program; wherein, when the computer program is executed by a processor, it implements the database migration to the cloud method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Data processing method and related equipment

    CN111240897A

  • Tomcat application deployment method based on docker technology and application

    CN112799692A

  • Database service method and system

    CN113515499A