Java-based database backup and restoration method and device, electronic equipment and medium

CN115658387BActive Publication Date: 2026-10-20BEIJING VRV SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211355576.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-01
Publication Date
2026-10-20
Estimated Expiration
2042-11-01

AI Technical Summary

Technical Problem

在现有的信息系统设计中,数据库是一种常用的数据存储载体,目前在对数据库进行备份的操作中,通常需要借助数据库管理系统本身所提供的工具进行,这些工具的使用通常需要一些专业知识进行支持,维护操作相对繁琐

Benefits of technology

[0044]本公开实施例提供的基于Java的数据库备份还原方法、装置、电子设备及介质,通过接收并响应数据备份还原指令,所述指令包括源数据库及目标数据库;获取所述源数据库的待备份还原信息,将所述待备份还原信息记录在预设格式的文件中,生成所述源数据库对应的备份文件;获取所述目标数据库的数据库信息,基于所述备份文件及目标数据库的数据库信息,将所述源数据库的待备份还原信息还原至所述目标数据库中。使数据库的备份还原可以脱离数据库管理系统提供的工具的同时,能够支持不同数据库间的数据迁移,简化数据迁移过程,提高数据迁移效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115658387B_ABST
    Figure CN115658387B_ABST
Patent Text Reader

Abstract

The embodiment of the present disclosure discloses a Java-based database backup and restoration method and device, electronic equipment and medium, the method comprises: receiving and responding to a data backup and restoration instruction, the instruction comprises a source database and a target database; obtaining the table structure information of the source database and the data in the table, recording the to-be-backup-restored information in a file in a preset format, and generating a backup file corresponding to the source database; obtaining the database information of the target database, and based on the backup file and the database information of the target database, restoring the to-be-backup-restored information of the source database to the target database. The embodiment of the present disclosure can support data migration between different databases, simplify the data migration process, and improve the data migration efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of data processing technology, and in particular to a Java-based database backup and restore method, apparatus, electronic device, and medium. Background Technology

[0002] During the maintenance of information systems, it is usually necessary to back up the data generated by the system to prevent data loss in case of unexpected situations. In the current information system design, databases are a commonly used data storage medium. Currently, database backup operations usually require the tools provided by the database management system itself. The use of these tools often requires some professional knowledge, making the maintenance operation relatively cumbersome.

[0003] Furthermore, backup files generated by a database backup tool can only be restored on databases of the same type, and cannot provide support for data migration across different database types.

[0004] Therefore, there is an urgent need to provide a method that supports the backup and restore of multiple data sets. Summary of the Invention

[0005] In view of this, embodiments of the present disclosure provide a Java-based database backup and restore method, apparatus, electronic device, and medium that can support data migration between multiple databases, simplify the data migration process, and improve data migration efficiency.

[0006] Firstly, this disclosure provides a Java-based database backup and restore method, employing the following technical solution:

[0007] The method includes:

[0008] Receive and respond to data backup and restore commands, the commands including source database and target database;

[0009] Obtain the backup and restore information of the source database, record the backup and restore information in a file with a preset format, and generate a backup file corresponding to the source database;

[0010] Obtain the database information of the target database, and based on the backup file and the database information of the target database, restore the backup and restore information of the source database to the target database.

[0011] Optionally, before obtaining the backup and restore information of the source database, recording the backup and restore information in a file with a preset format, and generating a backup file corresponding to the source database, the method further includes:

[0012] Obtain the status of the source database and verify the status of the source database, which includes restore status, backup status and normal status.

[0013] When the source database is not in a restore state, the step of obtaining the backup and restore information of the source database is executed;

[0014] When the source database is in a restored state, a preset alarm message is output.

[0015] Optionally, before recording the backup and restore information in a file with a preset format, the method further includes:

[0016] Set the state of the source database to the backup state.

[0017] Optionally, before obtaining the database information of the target database and restoring the backup and restore information of the source database to the target database based on the backup file and the database information of the target database, the method further includes:

[0018] The status of the target database is obtained and verified. The status of the target database includes restore status, backup status and normal status.

[0019] When the target database is not in a backup state, the step of obtaining the database information of the target database is executed;

[0020] When the target database is in backup mode, a preset alarm message is output.

[0021] Optionally, before obtaining the database information of the target database and restoring the backup and restore information of the source database to the target database based on the backup file and the database information of the target database, the method further includes:

[0022] The state of the target database is set to the restored state.

[0023] Optionally, the information to be backed up and restored includes: metadata information, table structure information, and data information, wherein the table structure information includes: table field information, primary key information, foreign key information, and index information.

[0024] Optionally, the step of obtaining the backup and restore information of the source database, recording the backup and restore information in a file with a preset format, and generating a backup file corresponding to the source database further includes:

[0025] The source database information is obtained through the Java standard database access interface and recorded as database metadata information in the file of the preset format;

[0026] All table structure information of the source database is obtained through the Java standard database access interface and recorded as database table information in the file with the preset format.

[0027] Data from the table is retrieved sequentially using the Java standard database access interface and recorded as table data information in the file with the preset format.

[0028] Generate a backup file corresponding to the source database.

[0029] Optionally, the step of restoring the backup and restore information of the source database to the target database based on the backup file and the database information of the target database further includes:

[0030] Obtain metadata information from the target database through the Java standard database access interface;

[0031] The metadata information of the source database in the backup file is read through the Java standard database access interface;

[0032] Determine the metadata information of the target database and the source database in the backup file;

[0033] If they match, the backup and restore information is restored to the target database based on the database table structure information in the backup file; if they do not match, the database table structure information in the backup file is converted according to standard syntax, and the backup and restore information is restored to the target database based on the converted database table structure information.

[0034] Secondly, this disclosure also provides a data backup and restore apparatus, characterized in that the apparatus includes:

[0035] The receiving module is used to receive and respond to data backup and restore commands, the commands including source database and target database;

[0036] The backup module is used to obtain the backup and restore information of the source database, convert the table structure information and data in the table of the source database into a format, and generate a backup file of the source database in a preset data format.

[0037] The restore module is used to obtain the database information of the target database, and restore the backup and restore information of the source database to the target database based on the backup file and the database information of the target database.

[0038] Thirdly, this disclosure also provides an electronic device that adopts the following technical solution:

[0039] The electronic device includes:

[0040] At least one processor; and,

[0041] A memory communicatively connected to the at least one processor; wherein,

[0042] The memory stores instructions that can be executed by the at least one processor, which enables the at least one processor to perform any of the Java-based database backup and restore methods described above.

[0043] Fourthly, embodiments of this disclosure also provide a computer-readable storage medium storing computer instructions for causing a computer to execute any of the Java-based database backup and restore methods described above.

[0044] The Java-based database backup and restore method, apparatus, electronic device, and medium provided in this disclosure receive and respond to data backup and restore instructions, including a source database and a target database; obtain the backup and restore information of the source database, record the backup and restore information in a file with a preset format, and generate a backup file corresponding to the source database; obtain the database information of the target database, and restore the backup and restore information of the source database to the target database based on the backup file and the database information of the target database. This allows database backup and restore to be performed independently of tools provided by a database management system, while supporting data migration between different databases, simplifying the data migration process, and improving data migration efficiency.

[0045] The above description is merely an overview of the technical solution disclosed herein. In order to better understand the technical means of this disclosure and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this disclosure more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0046] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0047] Figure 1 A flowchart illustrating a Java-based database backup and restore method provided in this embodiment of the disclosure;

[0048] Figure 2 for Figure 1 Detailed flowchart of step S3;

[0049] Figure 3 for Figure 1 Detailed flowchart of step S5;

[0050] Figure 4 A schematic diagram of the modules of a Java-based database backup and restore device provided in an embodiment of this disclosure;

[0051] Figure 5 This is a schematic block diagram of an electronic device provided in an embodiment of the present disclosure. Detailed Implementation

[0052] The embodiments of this disclosure will now be described in detail with reference to the accompanying drawings.

[0053] It should be understood that the following specific examples illustrate the implementation of this disclosure, and those skilled in the art can easily understand other advantages and effects of this disclosure from the content disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. This disclosure can also be implemented or applied through other different specific implementation methods, and the details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this disclosure. It should be noted that, in the absence of conflict, the following embodiments and features in the embodiments can be combined with each other. Based on the embodiments in this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.

[0054] It should be noted that various aspects of embodiments within the scope of the appended claims are described below. It will be apparent that the aspects described herein can be embodied in a wide variety of forms, and any particular structure and / or function described herein is merely illustrative. Based on this disclosure, those skilled in the art will understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects set forth herein can be used to implement the device and / or practice the method. Additionally, this device and / or method can be implemented using structures and / or functionalities other than one or more of the aspects set forth herein.

[0055] It should also be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this disclosure. The drawings only show the components related to this disclosure and are not drawn according to the number, shape and size of the components in actual implementation. In actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0056] Furthermore, specific details are provided in the following description to facilitate a thorough understanding of the examples. However, those skilled in the art will understand that the described aspects can be practiced without these specific details.

[0057] During the maintenance of information systems, it is usually necessary to back up the data generated by the system to prevent data loss in case of unexpected situations. In the current information system design, databases are a commonly used data storage medium. Currently, database backup operations usually require the tools provided by the database management system itself. The use of these tools often requires some professional knowledge, making the maintenance operation relatively cumbersome.

[0058] Furthermore, backup files generated by a database backup tool can only be restored on databases of the same type, and cannot provide support for data migration across different database types.

[0059] To address the above problems, the inventors creatively proposed the following method: By receiving and responding to data backup and restore commands, including a source database and a target database; obtaining the backup and restore information of the source database, recording this information in a file with a preset format, and generating a backup file corresponding to the source database; obtaining the database information of the target database, and restoring the backup and restore information of the source database to the target database based on the backup file and the target database information. This allows database backup and restore to be performed independently of tools provided by the database management system, while supporting data migration between different databases, simplifying the data migration process, and improving data migration efficiency.

[0060] This disclosure provides a Java-based database backup and restore method.

[0061] like Figure 1 As shown, the Java-based database backup and restore method includes steps S1-S3.

[0062] S1. Receive and respond to data backup and restore instructions, the instructions including source database and target database.

[0063] The data backup and restore command can be issued by the user in real time through the user terminal device, or it can be issued at a set time. No restriction is imposed here.

[0064] In this embodiment, the source database is the information database to be backed up and restored, and the target database is the database used to store the data of the information database to be backed up and restored. The source database and the target database can be the same type of database or different types of databases, and there is no restriction here.

[0065] S3. Obtain the backup and restore information of the source database, record the backup and restore information in a file with a preset format, and generate a backup file corresponding to the source database.

[0066] The information to be backed up and restored includes metadata information, table structure information, and data information of the source database. The table structure information includes: table field information, primary key information, foreign key information, and index information, etc.

[0067] Specifically, the source database information is obtained through the Java standard database access interface, including but not limited to the database product name, database product version number, database character encoding, and case sensitivity settings. This data is recorded as database metadata in a file with a predefined format. All table structure information of the source database is obtained through the Java standard database access interface, including but not limited to table field information, primary key information, foreign key information, and index information. This data is recorded as database table information in a file with a predefined format. Data in the tables is sequentially obtained through the Java standard database access interface, and this data is recorded as table data information in a file with a predefined format. Finally, a backup file is generated.

[0068] As one implementation method, such as Figure 2 As shown, step S3 can be achieved through the following steps;

[0069] S31. Obtain source database information through the Java standard database access interface and record it as database metadata information in the file with the preset format.

[0070] The source database information includes, but is not limited to, the database product name, database product version number, database character encoding, and case sensitivity settings.

[0071] S32. Obtain all table structure information of the source database through the Java standard database access interface, and record it as database table information in the file with the preset format.

[0072] S33. Obtain the data in the table sequentially through the Java standard database access interface, and record it as table data information in the file with the preset format.

[0073] S34. Generate a backup file corresponding to the source database.

[0074] As one implementation method, the execution of each detailed step in generating backup files is carried out in a multi-threaded manner, that is, there is at least a database backup processing thread and a backup message processing thread. The database backup processing thread executes the main database backup operation and generates backup messages during the completion of each specific step, which are consumed by the backup message processing thread to improve backup efficiency.

[0075] S5. Based on the backup file and target database information, restore the backup and restore information of the source database to the target database.

[0076] As one implementation method, such as Figure 3 As shown, step S5 can be achieved through the following steps;

[0077] S51. Obtain the target database's metadata information through the Java standard database access interface.

[0078] The target database information includes, but is not limited to, the database product name, database product version number, database character encoding, and case sensitivity settings.

[0079] S52. Read the metadata information of the source database in the backup file through the Java standard database access interface.

[0080] S53. Determine the metadata information of the target database and the source database in the backup file.

[0081] S54. If they match, the backup and restore information is restored to the target database based on the database table structure information in the backup file.

[0082] It is understandable that when the metadata information of the target database and the source database in the backup file is consistent, it means that the target database and the source database in the backup file belong to the same type of database, and the table structure information in the backup file is directly used for restoration.

[0083] Specifically, firstly, all table structure information of the target database is obtained through the Java standard database access interface. This table structure information includes, but is not limited to, table field information, primary key information, foreign key information, and index information. Then, all table structure information in the target database is deleted. Considering the existence of table dependencies in the target database, the deletion should be performed in the order of foreign keys and then tables, based on the obtained information. Finally, the table structure information in the backup file is restored to the target database, and the data information in the tables in the backup file is restored to the target database.

[0084] S55. If there is a discrepancy, the database table structure information in the backup file is converted according to standard syntax, and the backup and restore information is restored to the target database based on the converted database table structure information.

[0085] It is understandable that when the metadata information of the target database and the source database in the backup file is consistent, it means that the target database and the source database in the backup file are not of the same type of database. In this case, the above restoration operation is performed in sequence after converting the database table structure information in the backup file according to standard SQL syntax.

[0086] As one implementation method, the execution of each detailed step in the above restoration process is carried out in a multi-threaded manner, that is, there is at least a database restoration processing thread and a restoration message processing thread. The database restoration processing thread executes the above database restoration main operation and generates restoration messages during the completion of each specific step, which are consumed by the restoration message processing thread to improve the database restoration efficiency.

[0087] This disclosure provides another Java-based database backup and restore method.

[0088] The Java-based database backup and restore method includes steps S1-S6.

[0089] S1. Receive and respond to data backup and restore commands;

[0090] S2. Obtain the status of the source database and verify the status of the source database. If the source database is not in the restoration state, proceed to step S3; otherwise, proceed to step S5.

[0091] S3. Obtain the backup and restore information of the source database, record the backup and restore information in a file with a preset format, and generate a backup file corresponding to the source database.

[0092] S4. Obtain the status of the target database and verify its status. If the target database is not in backup state, proceed to step S5; otherwise, proceed to step S6.

[0093] S5. Based on the backup file and target database information, restore the backup and restore information of the source database to the target database;

[0094] S6. Output preset alarm information.

[0095] The specific implementation methods of steps S1, S3, and S5 are basically the same as those in the aforementioned embodiments, and will not be repeated here.

[0096] In this embodiment, the database status includes: backup status, restore status, and normal status. Users have different access permissions to the database depending on its status.

[0097] Specifically, when the source database is not in a restore state, backup and regular read / write operations can be performed on the source database; when the target database is not in a backup state, restore and regular read / write operations can be performed on the target database. During the database backup and restore process, the database status is verified. If the source database is in a restore state during the backup process, or if the target database is in a backup state during the restore process, a pre-defined error code is returned before the backup and restore operation is performed, preventing invalid backup and restore operations.

[0098] Furthermore, before performing a database backup, the source database must be placed in backup mode. This includes setting shared semaphores, setting the database and tables to read-only mode, and setting the database user's permissions. In this state, the source database will reject restore operations. Before performing a database restore, the target database must be placed in restore mode. This includes setting shared semaphores and setting the database user's permissions. In this state, the target database will reject backup operations. After both the database backup and restore are complete, the source and target databases must be returned to normal mode, and the database user's normal operation permissions for the source database must be restored.

[0099] Based on the same inventive concept, this application also provides a Java database backup and restore apparatus for implementing the aforementioned method. The solution provided by this apparatus is similar to the solution described in the above method; therefore, the specific limitations in the Java database backup and restore apparatus embodiments provided below can be found in the limitations of the Java database backup and restore method described above, and will not be repeated here.

[0100] In one embodiment, such as Figure 4 The diagram shown is a schematic of the modules of a Java-based database backup and restore device 100 in an embodiment of this application, which includes: a receiving module 110, a backup module 120 and a restore module 130.

[0101] The receiving module 110 is used to receive and respond to data backup and restore instructions, the instructions including a source database and a target database;

[0102] Backup module 120 is used to obtain the backup and restore information of the source database, convert the table structure information and data in the table of the source database into a format, and generate a backup file of the source database in a preset data format.

[0103] The restore module 130 is used to obtain the database information of the target database and restore the backup and restore information of the source database to the target database based on the backup file and the database information of the target database.

[0104] Furthermore, the device also includes a verification module 140.

[0105] The verification module 140 is used to obtain the status of the source database and verify the status of the source database; and to obtain the status of the target database and verify the status of the target database.

[0106] Furthermore, the device also includes an alarm module 150.

[0107] The alarm module 150 is used to output preset alarm information when the source database is in a restore state and when the target database is in a backup state.

[0108] Furthermore, the device also includes a status adjustment module 160.

[0109] The status adjustment module 160 is used to put the source database into a backup state and, after the backup is completed, put the source database into a normal state.

[0110] The state adjustment module 160 is also used to set the state of the target database to a restored state, and after the restoration is completed, set the state of the target database to a normal state.

[0111] The specific implementation methods of the above-described apparatus embodiments are basically the same as those of the method embodiments described above, and will not be repeated here.

[0112] Each module in the above-mentioned device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0113] An electronic device according to embodiments of the present disclosure includes a memory and a processor. The memory is used to store non-transitory computer-readable instructions. Specifically, the memory may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may, for example, include random access memory (RAM) and / or cache memory. The non-volatile memory may, for example, include read-only memory (ROM), a hard disk, flash memory, etc.

[0114] The processor may be a central processing unit (CPU) or other processing unit with data processing and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions. In one embodiment of this disclosure, the processor is used to execute computer-readable instructions stored in the memory, causing the electronic device to perform all or part of the steps of the Java-based database backup and restore method described in the foregoing embodiments of this disclosure.

[0115] Those skilled in the art will understand that, in order to solve the technical problem of how to achieve a good user experience, this embodiment may also include well-known structures such as communication buses and interfaces, and these well-known structures should also be included within the protection scope of this disclosure.

[0116] like Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. It illustrates a structural schematic diagram suitable for implementing the electronic device in the embodiment of the present disclosure. Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.

[0117] like Figure 5 As shown, an electronic device may include a processing unit (such as a central processing unit, graphics processing unit, etc.) that can perform various appropriate actions and processes based on a program stored in read-only memory (ROM) or a program loaded from a storage device into random access memory (RAM). The RAM also stores various programs and data required for the operation of the electronic device. The processing unit, ROM, and RAM are interconnected via a bus. Input / output (I / O) interfaces are also connected to the bus.

[0118] Typically, the following devices can be connected to the I / O interface: input devices, such as sensors or visual information acquisition devices; output devices, such as displays; storage devices, such as magnetic tapes or hard drives; and communication devices. Communication devices allow electronic devices to communicate wirelessly or wiredly with other devices (such as edge computing devices) to exchange data. Although Figure 5 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have alternatively.

[0119] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processing device, all or part of the steps of the Java-based database backup and restore method of embodiments of this disclosure are performed.

[0120] For a detailed description of this embodiment, please refer to the corresponding descriptions in the foregoing embodiments, which will not be repeated here.

[0121] A computer-readable storage medium according to embodiments of the present disclosure stores non-transitory computer-readable instructions. When these non-transitory computer-readable instructions are executed by a processor, all or part of the steps of the Java-based database backup and restore methods described in the foregoing embodiments of the present disclosure are performed.

[0122] The aforementioned computer-readable storage media include, but are not limited to: optical storage media (e.g., CD-ROM and DVD), magneto-optical storage media (e.g., MO), magnetic storage media (e.g., magnetic tape or portable hard drive), media with built-in rewritable non-volatile memory (e.g., memory card), and media with built-in ROM (e.g., ROM cartridge).

[0123] For a detailed description of this embodiment, please refer to the corresponding descriptions in the foregoing embodiments, which will not be repeated here.

[0124] The basic principles of this disclosure have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in this disclosure are merely examples and not limitations, and should not be considered as essential features of each embodiment of this disclosure. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the scope of this disclosure to the necessity of employing the aforementioned specific details for implementation.

[0125] In this disclosure, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The block diagrams of devices, apparatuses, devices, and systems involved in this disclosure are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As those skilled in the art will recognize, these devices, apparatuses, devices, and systems can be connected, arranged, and configured in any manner. Words such as "comprising," "including," "having," etc., are open-ended terms meaning "including but not limited to," and are used interchangeably with them. The terms "or" and "and" as used herein refer to the terms "and / or," and are used interchangeably with them unless the context clearly indicates otherwise. The term "such as" as used herein refers to the phrase "such as but not limited to," and is used interchangeably with it.

[0126] Additionally, as used herein, the “or” used in a list of items beginning with “at least one” indicates a separate list, such that a list of, for example, “at least one of A, B, or C” means A or B or C, or AB or AC or BC, or ABC (i.e., A and B and C). Furthermore, the word “exemplary” does not imply that the described example is preferred or better than other examples.

[0127] It should also be noted that in the systems and methods of this disclosure, the components or steps can be decomposed and / or recombined. These decompositions and / or recombinations should be considered as equivalent solutions to this disclosure.

[0128] Various changes, substitutions, and modifications can be made to the technology described herein without departing from the teachings defined by the appended claims. Furthermore, the scope of the claims of this disclosure is not limited to the specific aspects of the processes, machines, manufactures, events, means, methods, and actions described above. Currently existing or later-developed processes, machines, manufactures, events, means, methods, or actions that perform substantially the same function or achieve substantially the same result as the corresponding aspects described herein can be utilized. Therefore, the appended claims include such processes, machines, manufactures, events, means, methods, or actions within their scope.

[0129] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use this disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of this disclosure. Therefore, this disclosure is not intended to be limited to the aspects shown herein, but rather to be carried out within the widest scope consistent with the principles and novel features disclosed herein.

[0130] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of this disclosure to the forms disclosed herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations thereof.

Claims

1. A Java-based database backup and restore method, characterized in that, The method includes: Receive and respond to data backup and restore commands, the commands including source database and target database; Obtain the status of the source database and verify the status of the source database, which includes restore status, backup status and normal status. If the source database is not in a restore state, the backup and restore information of the source database is obtained, the backup and restore information is recorded in a file with a preset format, and a backup file corresponding to the source database is generated. Obtain the status of the target database and verify the status of the target database, which includes restore status, backup status and normal status; If the target database is not in backup state and the source database is in restoration state, then the database information of the target database is obtained, and based on the backup file and the database information of the target database, the backup and restore information of the source database is restored to the target database. Before performing a database backup, the source database must be placed in backup mode. This includes setting shared semaphores, setting the database and tables to read-only mode, and setting the database user's permissions. At this point, the source database will reject the restore operation. Before performing a database restore, the target database must be placed in restore mode. This includes setting shared semaphores and setting the database user's permissions. At this point, the target database will reject the backup operation. After both the database backup and restore are complete, the source and target databases must be returned to normal mode, and the database user's normal permissions for the source database must be restored.

2. The Java-based database backup and restore method according to claim 1, characterized in that, Before obtaining the backup and restore information of the source database, recording the backup and restore information in a file with a preset format, and generating the backup file corresponding to the source database, the method further includes: When the source database is in a restored state, a preset alarm message is output.

3. The Java-based database backup and restore method according to claim 1, characterized in that, Before obtaining the database information of the target database and restoring the backup and restore information of the source database to the target database based on the backup file and the database information of the target database, the method further includes: When the target database is in backup mode, a preset alarm message is output.

4. The Java-based database backup and restore method according to claim 1, characterized in that, The information to be backed up and restored includes: metadata information, table structure information, and data information. The table structure information includes: table field information, primary key information, foreign key information, and index information.

5. The Java-based database backup and restore method according to claim 4, characterized in that, The step of obtaining the backup and restore information of the source database, recording the backup and restore information in a file with a preset format, and generating a backup file corresponding to the source database further includes: The source database information is obtained through the Java standard database access interface and recorded as database metadata information in the file of the preset format; All table structure information of the source database is obtained through the Java standard database access interface and recorded as database table information in the file with the preset format. Data from the table is retrieved sequentially using the Java standard database access interface and recorded as table data information in the file with the preset format. Generate a backup file corresponding to the source database.

6. The Java-based database backup and restore method according to claim 4, characterized in that, The step of restoring the backup and restore information of the source database to the target database based on the backup file and the database information of the target database further includes: Obtain metadata information from the target database through the Java standard database access interface; The metadata information of the source database in the backup file is read through the Java standard database access interface; Determine the metadata information of the target database and the source database in the backup file; If they match, the backup and restore information is restored to the target database based on the database table structure information in the backup file; if they do not match, the database table structure information in the backup file is converted according to standard syntax, and the backup and restore information is restored to the target database based on the converted database table structure information.

7. A data backup and restore device, characterized in that, include: The receiving module is used to receive and respond to data backup and restore commands, the commands including source database and target database; The backup module is used to obtain the status of the source database and verify the status of the source database, which includes restore status, backup status and normal status. If the source database is not in a restoration state, the backup and restoration information of the source database is obtained, the table structure information and data in the table of the source database are converted into a format, and a backup file of the preset data format corresponding to the source database is generated. The restore module is used to obtain the status of the target database and verify the status of the target database, which includes restore status, backup status and normal status. If the target database is not in backup state and the source database is in restoration state, then the database information of the target database is obtained, and based on the backup file and the database information of the target database, the backup and restore information of the source database is restored to the target database. Before performing a database backup, the source database must be placed in backup mode. This includes setting shared semaphores, setting the database and tables to read-only mode, and setting the database user's permissions. At this point, the source database will reject the restore operation. Before performing a database restore, the target database must be placed in restore mode. This includes setting shared semaphores and setting the database user's permissions. At this point, the target database will reject the backup operation. After both the database backup and restore are complete, the source and target databases must be returned to normal mode, and the database user's normal permissions for the source database must be restored.

8. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the Java-based database backup and restore method according to any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a computer to perform the Java-based database backup and restore method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Multi-database data processing method and device, computer equipment and storage medium

    CN109947789A

  • Database migration method and device, terminal and storage medium

    CN112632038A