CN116302688A - Database processing method and device, electronic equipment and storage medium - Google Patents

Database processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN116302688A
CN116302688A CN202310146372.4A CN202310146372A CN116302688A CN 116302688 A CN116302688 A CN 116302688A CN 202310146372 A CN202310146372 A CN 202310146372A CN 116302688 A CN116302688 A CN 116302688A
Authority
CN
China
Prior art keywords
database
backup
processed
command
file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310146372.4A
Other languages
Chinese (zh)
Inventor
骆振源
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Qianxin Technology Group Co Ltd
Secworld Information Technology Beijing Co Ltd
Original Assignee
Qianxin Technology Group Co Ltd
Secworld Information Technology Beijing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Qianxin Technology Group Co Ltd, Secworld Information Technology Beijing Co Ltd filed Critical Qianxin Technology Group Co Ltd
Priority to CN202310146372.4A priority Critical patent/CN116302688A/en
Publication of CN116302688A publication Critical patent/CN116302688A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1458Management of the backup or restore process
    • G06F11/1469Backup restoration techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2379Updates performed during online database operations; commit processing
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

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

Abstract

The invention provides a database processing method, a device, electronic equipment and a storage medium, which are applied to a server, wherein the server comprises a database to be processed, and the method comprises the following steps: acquiring a database to be processed; creating a file backup script corresponding to the database to be processed under the condition that the system service of the server is running, and carrying out backup operation on the database to be processed based on the file backup script to obtain a backup file; and under the condition that the data of the database to be processed is lost, creating a database recovery script corresponding to the backup file based on the backup file, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server is recovered to obtain the recovery database under the condition that the system service is operated. On the premise of not suspending the operation of the server, the database can be backed up and restored, so that the experience and satisfaction of the user in the use process can be improved.

Description

Database processing method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of data processing technologies, and in particular, to a database processing method, a database processing device, an electronic device, and a storage medium.
Background
With the popularization and development of computer technology, the production efficiency of various industries is greatly improved by means of computers, wherein a database is used for storing data.
As known in the related art, in the process of backing up and restoring the database, the operation of the server needs to be suspended, which affects the experience of the user in the use process. The backup and recovery operation of the database can be performed on the premise of not suspending the operation of the server, so that the database becomes a research hotspot.
Disclosure of Invention
The invention provides a database processing method, a database processing device, electronic equipment and a storage medium, which can realize backup and recovery operations on a database on the premise of not suspending operation of a server.
The invention provides a database processing method which is applied to a server, wherein the server comprises a database to be processed, and the database processing method comprises the following steps: acquiring the database to be processed; creating a file backup script corresponding to the database to be processed under the condition that the system service of the server is running, and carrying out backup operation on the database to be processed based on the file backup script to obtain a backup file; and under the condition that the data of the database to be processed is lost, creating a database recovery script corresponding to the backup file based on the backup file, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server recovers to obtain the recovery database under the condition that the system service is in operation.
According to the method for processing a database provided by the invention, the backup operation is performed on the database to be processed based on the file backup script to obtain a backup file, which specifically comprises the following steps: determining a backup command corresponding to the database to be processed based on the file backup script; and carrying out backup operation on the database to be processed based on the backup command to obtain a backup file.
According to the method for processing a database provided by the invention, the backup operation is performed on the database to be processed based on the backup command to obtain a backup file, which specifically comprises the following steps: based on the backup command, carrying out backup operation on the database to be processed to obtain backup files at different backup moments; and taking the backup file with the backup time being the latest backup time as the backup file for constructing the recovery database.
According to the method for processing a database provided by the invention, after the backup operation is performed on the database to be processed based on the backup command to obtain the backup file, the method further comprises: determining a compression command corresponding to the backup file based on the file backup script; based on the compression command, compressing the backup file to obtain a compressed backup file; before the database restoration script corresponding to the backup file is created based on the backup file, the method further comprises: and decompressing the compressed backup file to obtain the backup file.
According to the database processing method provided by the invention, the restoring database corresponding to the database to be processed is constructed based on the database restoring script and the backup file, and the method specifically comprises the following steps: determining a first command based on the database recovery script, wherein the first command is a command for closing the access authority of a user to the database to be processed; under the condition that the access right of a user to the database to be processed is successfully closed based on the first command, determining a second command based on the database recovery script, wherein the second command is a command for renaming the database to be processed; under the condition that the renaming operation is successfully carried out on the database to be processed based on the second command, determining a third command based on the database recovery script, wherein the third command is a command for creating a blank database, and the blank database is used for accepting the backup file; determining a fourth command based on the database recovery script under the condition that the blank database is successfully created based on the third command, wherein the fourth command is a command for importing the backup file into the blank database; and under the condition that the backup file is successfully imported into the blank database based on the fourth command, obtaining the blank database containing the backup file, and taking the blank database containing the backup file as the recovery database.
According to the database processing method provided by the invention, after the blank database containing the backup file is obtained, the method further comprises: determining a fifth command based on the database recovery script, wherein the fifth command is a command for deleting the database to be processed and/or the backup file; and deleting the database to be processed and/or the backup file based on the fifth command.
According to the database processing method provided by the invention, after the second command is determined based on the database recovery script, the method further comprises: and under the condition that the renaming operation is not successfully performed on the database to be processed based on the second command, restarting the access right of the user to the database to be processed, and stopping the operation of determining a third command.
According to the database processing method provided by the invention, after the third command is determined based on the database recovery script, the method further comprises: and under the condition that the blank database is not successfully created based on the third command, changing the name of the database to be processed to the original name, restarting the access authority of the user to the database to be processed, and stopping the operation of determining the fourth command.
According to the database processing method provided by the invention, after the fourth command is determined based on the database recovery script, the method further comprises: under the condition that the backup file is not successfully imported into the blank database based on the fourth command, changing the name of the database to be processed to the original name, restarting the access authority of the user to the database to be processed, and deleting the blank database.
According to the database processing method provided by the invention, the database to be processed is a database in a cluster mode.
According to the database processing method provided by the invention, the system service of the server is provided by a single application or by a micro service.
The invention also provides a database processing device which is applied to a server, wherein the server comprises a database to be processed, and the database processing device comprises: the first module is used for acquiring the database to be processed; the second module is used for creating a file backup script corresponding to the database to be processed under the condition that the system service of the server is running, and carrying out backup operation on the database to be processed based on the file backup script to obtain a backup file; and the third module is used for creating a database recovery script corresponding to the backup file based on the backup file when the database to be processed is in data loss, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server recovers to obtain the recovery database when the system service is in operation.
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing a database processing method as described in any one of the above when executing the program.
The invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a database processing method as described in any of the above.
The invention also provides a computer program product comprising a computer program which, when executed by a processor, implements a database processing method as described in any of the above.
According to the database processing method, the device, the electronic equipment and the storage medium, the file backup script corresponding to the database to be processed is created under the condition that the system service of the server is running, and the backup operation is carried out on the database to be processed based on the file backup script so as to obtain the backup file; and under the condition that the data of the database to be processed is lost, creating a database recovery script corresponding to the backup file, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server can recover to obtain the recovery database under the condition of not suspending the system service. On the premise of not suspending the operation of the server, the database can be backed up and restored, so that the experience and satisfaction of the user in the use process can be improved.
Drawings
In order to more clearly illustrate the invention or the technical solutions of the prior art, the following description will briefly explain the drawings used in the embodiments or the description of the prior art, and it is obvious that the drawings in the following description are some embodiments of the invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of a database processing method according to the present invention;
FIG. 2 is a schematic flow chart of a backup operation of a database to be processed based on a file backup script to obtain a backup file;
FIG. 3 is a schematic flow chart of constructing a recovery database corresponding to a database to be processed based on a database recovery script and a backup file provided by the invention;
FIG. 4 is a second flowchart of a database processing method according to the present invention;
FIG. 5 is a schematic diagram of a database processing device according to the present invention;
fig. 6 is a schematic structural diagram of an electronic device provided by the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present invention more apparent, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In the current process of backing up and restoring the database, the operation of the server is often required to be suspended, and the backup and restoring operation of the server for the database in the cluster mode is not supported, so that the experience of the user in the use process is affected.
The database processing method can support the backup and recovery operation of the database under the condition that the server normally operates, and the system service of the server is provided by a single application or a micro-service. Wherein, the monomer application refers to an architecture mode that all functions and modules in the system are coupled in one application. I.e., project organization in which all code and functions are contained in one WAR packet. The system consists of a plurality of modules (all resources) which are arranged into a war package and run on a server, namely a process is run. Micro-services are applications that split a large application into multiple small applications that are relatively independent, each small application has its own container and its own running process, and these small applications communicate with each other via the internet protocol (HTTP Rest), and all applications work together to complete the business of the whole project. It will be appreciated that a system service may be provided by a single application or by a plurality of micro services.
Fig. 1 is a schematic flow chart of a database processing method provided by the invention.
To further describe the database processing method provided by the present invention, the following description will be made with reference to fig. 1.
In an exemplary embodiment of the present invention, the database processing method may be applied to a server, and in an example, a system service of the server is provided by a single application or by a micro service. In the application process, the server may also correspond to a database to be processed. As can be seen in fig. 1, the database processing method may include steps 110 to 130, and each step will be described below.
In step 110, a database to be processed is obtained.
In one embodiment, the database to be processed may be considered a database that requires data backup and recovery. Wherein the database to be processed may include a plurality of data.
In yet another embodiment, information for each database may be obtained, such as database service address, database port number, database user name, etc. Furthermore, the database to be processed which needs to be backed up and restored can be automatically found based on the information of the database.
In an example, the database to be processed may be a clustered database. In the application process, when the server is a server corresponding to the micro service, the server may be a clustered server, where each server in the clustered server may respectively correspond to each database in the clustered mode.
In step 120, in the case that the system service of the server is running, a file backup script corresponding to the database to be processed is created, and a backup operation is performed on the database to be processed based on the file backup script, so as to obtain a backup file.
In one embodiment, in the case that the system service of the server is running, a file backup script corresponding to the database to be processed may be created, and further, a backup operation may be performed on the database to be processed by executing the file backup script, so as to obtain a backup file.
It should be noted that, the backup operation may be performed without discarding the data in the database to be processed, so as to obtain a complete backup file of the data.
The file backup script is used for executing database backup operation and compressing the backed-up database files. The database processing method provided by the invention will be described based on the action of the file backup script.
In an exemplary embodiment of the present invention, as can be seen in fig. 2, performing a backup operation on a database to be processed based on a file backup script, obtaining a backup file may include step 210 and step 220, and each step will be described below.
In step 210, a backup command corresponding to the database to be processed is determined based on the file backup script;
in step 220, based on the backup command, a backup operation is performed on the database to be processed to obtain a backup file.
In one embodiment, a backup command corresponding to a database to be processed may be determined based on a file backup script. Wherein, the backup commands corresponding to different databases to be processed are different. Further, the backup operation can be performed on the database to be processed based on the backup command, so as to obtain the backup file. In the implementation, the backup file can be automatically obtained based on the file backup script under the condition that the operation of the server is not affected, and a foundation is laid for restoring operation of the database to be processed.
In another exemplary embodiment of the present invention, based on the backup command, the backup operation is performed on the database to be processed, and the obtaining of the backup file may be further implemented in the following manner:
based on the backup command, carrying out backup operation on the database to be processed to obtain backup files at different backup moments;
and taking the backup file with the backup time being the latest backup time as the backup file for constructing the recovery database.
In one embodiment, the backup operation may be performed on the database to be processed multiple times at preset time intervals based on the backup command. Since the data contained in the pending databases at different backup times may be different over time, it is understood that the data contained in the pending databases at the latest backup time may be considered the most comprehensive. Therefore, in the application process, backup operation can be carried out on the database to be processed based on the backup command, and backup files at different backup moments are obtained; and taking the backup file with the backup time as the latest backup time as the backup file for constructing the recovery database. By the embodiment, the backup file can be ensured to be the latest and most comprehensive data contained in the database to be processed, thereby laying a foundation for accurately recovering the database to be processed.
In yet another embodiment, it may be further determined whether the version of the backup file is the same as the version corresponding to the data in the database to be processed, and if the version of the backup file is the same as the version corresponding to the data in the database to be processed, a recovery database corresponding to the database to be processed is constructed based on the backup file.
In still another exemplary embodiment of the present invention, continuing to take the embodiment illustrated in fig. 2 as an example, after performing a backup operation on a database to be processed based on a backup command to obtain a backup file (corresponding to step 220), the database processing method may further include the following steps:
determining a compression command corresponding to the backup file based on the file backup script;
based on the compression command, compressing the backup file to obtain a compressed backup file;
before constructing the recovery database corresponding to the database to be processed based on the backup file, the database processing method may further include the steps of:
and decompressing the compressed backup file to obtain the backup file.
In one embodiment, a compression command corresponding to a backup file may be determined based on a file backup script, and the backup file may be compressed based on the compression command to obtain a compressed backup file. In this embodiment, the storage space may be saved in the storage process by performing compression processing on the backup file corresponding to the database to be processed to obtain the compressed backup file.
Further, when the data loss of the database to be processed is monitored, that is, the database to be processed needs to be recovered, the stored compressed backup file can be decompressed to obtain the backup file, and then the recovery database corresponding to the database to be processed is constructed based on the backup file obtained by decompression. By the method and the device, on the premise of ensuring effective recovery of the database to be processed, the storage space of the backup file can be saved.
In step 130, when the database to be processed is lost, a database recovery script corresponding to the backup file is created based on the backup file, and a recovery database corresponding to the database to be processed is constructed based on the database recovery script and the backup file, so that the server is recovered to obtain the recovery database when the system service is running.
It should be noted that, the backup operation performed on the to-be-processed database to obtain the backup file may be performed in a case where no data loss occurs in the to-be-processed database. In the application process, when the data loss of the database to be processed is monitored, namely, when the recovery operation is needed to be carried out on the database to be processed, under the scene, the recovery database corresponding to the database to be processed can be constructed based on the backup file. Wherein, the data contained in the recovery database is a backup file. By the method and the device, recovery operation of the database to be processed can be achieved on the premise that operation of the server is not affected.
In still another exemplary embodiment of the present invention, a database restoration script corresponding to the backup file may be created, and a restoration database corresponding to the database to be processed may be constructed based on the database restoration script and the backup file.
In one embodiment, the compressed database backup file (corresponding to the compressed backup file) may be obtained and decompressed to obtain a backup file capable of restoring the database construction.
Further, a database recovery script corresponding to the backup file is created, and the database recovery script is executed, so that a recovery database corresponding to the database to be processed can be constructed. The main functions of the database recovery script include closing the access authority of a user to the to-be-processed database, renaming the to-be-processed database, creating a blank database, recovering the to-be-processed database based on the blank database to obtain a recovery database, deleting the to-be-processed database and the backup file, and the like.
According to the database processing method provided by the invention, under the condition that the system service of the server is running, a file backup script corresponding to the database to be processed is created, and backup operation is carried out on the database to be processed based on the file backup script so as to obtain a backup file; and under the condition that the data of the database to be processed is lost, creating a database recovery script corresponding to the backup file, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server can recover to obtain the recovery database under the condition of not suspending the system service. On the premise of not suspending the operation of the server, the database can be backed up and restored, so that the experience and satisfaction of the user in the use process can be improved.
The present invention will be described with reference to the following embodiments for executing a database recovery script.
FIG. 3 is a schematic flow chart of constructing a recovery database corresponding to a database to be processed based on a database recovery script and a backup file provided by the invention.
In an exemplary embodiment of the present invention, as can be seen in connection with fig. 3, constructing a recovery database corresponding to a database to be processed based on a database recovery script and a backup file may include steps 310 to 350, and each step will be described separately.
In step 310, a first command is determined based on the database recovery script, wherein the first command is a command to close access rights of a user to a database to be processed.
In step 320, in the case that the access right of the user to the database to be processed is successfully closed based on the first command, a second command is determined based on the database recovery script, wherein the second command is a command for renaming the database to be processed.
In one embodiment, the first command may be determined from a database recovery script, where the first command is a command to close access rights of a user to a database to be processed. In the application process, the access authority of the user to the database to be processed is successfully closed through the first command, so that the user can be ensured to be unable to access the database to be processed temporarily, and a foundation is laid for recovering the database to be processed successfully.
Further, in the case that the access authority of the user to the database to be processed is successfully closed based on the first command, a second command may be determined based on the database recovery script, where the second command is a command for performing a renaming operation on the database to be processed. It will be appreciated that successful renaming of the database to be processed is also the basis for implementing the recovery of the database to be processed.
In step 330, in the case that the renaming operation is successfully performed on the database to be processed based on the second command, a third command is determined based on the database recovery script, where the third command is a command to create a blank database, and the blank database is used to accept the backup file.
In step 340, in the event that the blank database is successfully created based on the third command, a fourth command is determined based on the database recovery script, wherein the fourth command is a command to import the backup file into the blank database.
In step 350, in the case that the backup file is successfully imported into the blank database based on the fourth command, the blank database containing the backup file is obtained, and the blank database containing the backup file is used as the recovery database.
In one embodiment, in the case that the renaming operation is successfully performed on the database to be processed based on the second command, a third command may be determined based on the database recovery script, where the third command is a command to create a blank database, and the blank database is used to accept the backup file.
In the application process, on the premise of successfully carrying out renaming operation on the database to be processed, a blank database can be newly established, wherein the blank database does not temporarily contain any data but is used for receiving the backup file, and it can be understood that the blank database containing the backup file can be used as a recovery database.
Further, in the case that the blank database is successfully created based on the third command, a fourth command may be determined based on the database restoration script, where the fourth command is a command to import the backup file into the blank database. In the application process, the operation of recovering the database can be performed, the backup file is imported into the blank database to obtain the blank database containing the backup file, and the blank database containing the backup file is used as the recovery database. According to the embodiment, the recovery database corresponding to the database to be processed can be obtained, wherein the recovery database contains the backup files.
In still another exemplary embodiment of the present invention, continuing with the embodiment illustrated in fig. 3, after obtaining a blank database containing backup files (corresponding to step 350), the database processing method may further include the steps of:
determining a fifth command based on the database recovery script, wherein the fifth command is a command for deleting the database to be processed and/or the backup file;
based on the fifth command, the database to be processed and/or the backup file are deleted.
In one embodiment, to save storage space of the server system, after the database to be processed is successfully restored, a fifth command may also be determined based on the database restoration script, and based on the fifth command, the database to be processed and/or the backup file may be deleted. The fifth command is a command for deleting the database to be processed and/or the backup file.
In yet another exemplary embodiment of the present invention, after determining the second command (corresponding to step 320) based on the database recovery script, the database processing method may further include the steps of:
and under the condition that the renaming operation is not successfully performed on the database to be processed based on the second command, restarting the access authority of the user on the database to be processed, and stopping the operation of determining the third command.
In one embodiment, when the renaming operation is not successfully performed on the database to be processed, the access authority of the user to the database to be processed needs to be restarted, so that the situation that the user cannot access the database and the experience of the user is prevented from being influenced is avoided. Further, since the renaming operation of the database to be processed is a primary condition for recovering the database to be processed, when the renaming operation of the database to be processed is not successfully performed, the operation of the subsequent steps, such as stopping the operation of determining the third command, is not performed.
In still another exemplary embodiment of the present invention, after determining the third command (corresponding to step 330) based on the database recovery script, the database processing method may further include the steps of:
and under the condition that the blank database is not successfully created based on the third command, changing the name of the database to be processed to the original name, restarting the access authority of the user to the database to be processed, and stopping the operation of determining the fourth command.
In one embodiment, when the blank database is not successfully created, the name of the database to be processed needs to be changed to the original name, and the access authority of the user to the database to be processed is restarted, so that the situation that the user cannot access the database and the experience of the user is influenced is avoided. Further, since successful creation of the blank database is a necessary condition for restoration of the database to be processed, when the blank database is not successfully created, operations of subsequent steps, such as stopping the operation of determining the fourth command, are not performed.
In still another exemplary embodiment of the present invention, after determining the fourth command (corresponding to step 340) based on the database recovery script, the database processing method may further include the steps of:
under the condition that the backup file is not successfully imported into the blank database based on the fourth command, changing the name of the database to be processed to the original name, restarting the access authority of the user to the database to be processed, and deleting the blank database.
In one embodiment, when the backup file is not successfully imported into the blank database, the name of the database to be processed needs to be changed to the original name, the access authority of the user to the database to be processed is restarted, and the blank database is deleted, so that the situation that the user cannot access the database and the experience of the user is prevented from being influenced is avoided.
FIG. 4 is a second flowchart of a database processing method according to the present invention.
To further describe the database processing method provided by the present invention, the following description will be made with reference to fig. 4.
In an exemplary embodiment of the present invention, as can be seen in conjunction with fig. 4, the database processing method may include steps 401 to 417, each of which will be described separately below.
In step 401, a database backup file is obtained.
In one embodiment, a file backup script corresponding to the database to be processed may be created, and a backup operation may be performed on the database to be processed based on the file backup script, to obtain a backup file (corresponding to the database backup file). Furthermore, the database backup file can be compressed to obtain the compressed backup file, so that the storage space can be saved in the storage process.
In step 402, the database backup file is decompressed.
In step 403, database backup information is obtained.
In step 404, a resume script is executed.
In one embodiment, when the recovery operation needs to be performed on the database to be processed, that is, when the condition that the database to be processed is in data missing is monitored, decompression processing may be performed on the compressed backup file, so as to obtain the database backup file. Further, the database backup information, such as the backup time and version of the database backup file, may be obtained, and in the case that the backup time of the database backup file is the latest time and the version corresponds to the database to be processed, the recovery script operation may be executed. The function of the number recovery script mainly comprises closing the access authority of a user to a database (corresponding to a database to be processed), renaming an existing database (corresponding to the database to be processed), creating a recovery database (corresponding to a blank database), carrying out the recovery database, deleting the backup (corresponding to a backup file) of the existing database, and the like.
In step 405, the user's access rights to the database are closed.
In one embodiment, the user's access rights to the database may be closed such that other users are temporarily unable to access the database. Thus, the smooth operation of recovering the database to be processed can be ensured.
In step 406, the existing database is renamed in the event that the user's access rights to the database are successfully closed.
In step 407, the user's access rights to the database are opened without successfully closing the user's access rights to the database.
In one embodiment, an existing database (corresponding to the database to be processed) is renamed to prevent database recovery failures. If the renaming operation fails, the access authority of the user to the database is restarted, and the recovery operation is finished, so that the user can not be influenced to access the database, and the experience and satisfaction of the user in the using process are improved.
In step 408, a recovery database is created in the event that an existing database rename operation is successfully performed.
In step 409, the database name is changed back in the event that the existing database renaming operation was not successfully performed.
In step 410, the user's access rights to the database are opened.
In one embodiment, if the renaming operation is successful, a restore database (corresponding to a blank database) is created for receiving the data of the backup database file. If the newly built recovery database (blank database) fails, the database name is changed back, the access authority of the user to the database is restarted, and the recovery operation is finished.
In step 411, in the event that the recovery database is successfully created, a recovery database operation is performed.
In step 412, in the event that the recovery database was not successfully created, the created recovery database is deleted.
In step 413, the database name is changed back.
In step 414, the user's access rights to the database are opened.
In one embodiment, if the new database (corresponding to the blank database) is successfully restored, the database restoration operation is performed, and the data of the backup database file is imported into the new database (corresponding to the blank database). If the operation of recovering the database fails, deleting the created recovering database (corresponding to the blank database), changing the name of the database back, and restarting the access authority of the user to the database.
In step 415, in the event that a restore database operation is successful, the existing database backup is deleted.
In step 416, the process ends without successfully deleting the existing database backup.
In step 417, in the event that an existing database backup is successfully deleted, the process ends.
In one embodiment, if the data recovery operation is successful, the backup of the existing database (corresponding to the database to be processed) is deleted, and the residual database backup file (corresponding to the backup file) is removed. If the deletion of the existing database backup fails, the deletion of the existing database backup operation is tried again, whether the operation fails or not is finished, and the information of failure of the deletion of the existing database backup operation is returned. If the deleting of the existing database backup is successful, returning the information of successful deleting of the existing database backup operation, and ending the operation.
According to the database processing method provided by the invention, under the condition that the system service of the server is running, a file backup script corresponding to the database to be processed is created, and backup operation is performed on the database to be processed based on the file backup script so as to obtain a backup file; and under the condition that the data of the database to be processed is lost, creating a database recovery script corresponding to the backup file, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server can recover to obtain the recovery database under the condition of not suspending the system service. On the premise of not suspending the operation of the server, the database can be backed up and restored, so that the experience and satisfaction of the user in the use process can be improved.
Based on the same conception, the invention also provides a database processing device.
The database processing apparatus provided by the present invention will be described below, and the database processing apparatus described below and the database processing method described above may be referred to correspondingly to each other.
Fig. 5 is a schematic structural diagram of a database processing device provided by the present invention.
In an exemplary embodiment of the invention, the database processing device is applied to a server comprising a database to be processed. As can be seen in conjunction with fig. 5, the database processing apparatus may include a first module 510, a second module 520, and a third module 530, each of which will be described separately below.
A first module 510, which may be configured to obtain a database to be processed;
the second module 520 may be configured to create a file backup script corresponding to the database to be processed when the system service of the server is running, and perform a backup operation on the database to be processed based on the file backup script, so as to obtain a backup file;
the third module 530 may be configured to create, in a case where the database to be processed is lost in data, a database recovery script corresponding to the backup file based on the backup file, and construct, based on the database recovery script and the backup file, a recovery database corresponding to the database to be processed, so that the server recovers the recovery database in a case where the system service is running.
In an exemplary embodiment of the present invention, the second module 520 may implement a backup operation on the database to be processed based on the file backup script to obtain a backup file in the following manner:
determining a backup command corresponding to the database to be processed based on the file backup script;
and based on the backup command, carrying out backup operation on the database to be processed to obtain a backup file.
In an exemplary embodiment of the present invention, the second module 520 may implement a backup operation on the database to be processed based on the backup command in the following manner, to obtain a backup file:
based on the backup command, carrying out backup operation on the database to be processed to obtain backup files at different backup moments;
and taking the backup file with the backup time being the latest backup time as the backup file for constructing the recovery database.
In an exemplary embodiment of the invention, the second module 520 may be further configured to:
determining a compression command corresponding to the backup file based on the file backup script;
based on the compression command, compressing the backup file to obtain a compressed backup file;
and decompressing the compressed backup file to obtain the backup file.
In an exemplary embodiment of the present invention, the third module 530 may implement constructing a recovery database corresponding to the database to be processed based on the backup file in the following manner:
And creating a database recovery script corresponding to the backup file, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file.
In an exemplary embodiment of the present invention, the third module 530 may implement constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file in the following manner:
determining a first command based on a database recovery script, wherein the first command is a command for closing access rights of a user to a database to be processed;
under the condition that the access authority of a user to a database to be processed is closed successfully based on the first command, determining a second command based on a database recovery script, wherein the second command is a command for renaming the database to be processed;
under the condition that renaming operation is successfully carried out on the database to be processed based on the second command, determining a third command based on a database recovery script, wherein the third command is a command for creating a blank database, and the blank database is used for accepting backup files;
under the condition that the blank database is successfully created based on the third command, determining a fourth command based on a database recovery script, wherein the fourth command is a command for importing the backup file into the blank database;
And under the condition that the backup file is successfully imported into the blank database based on the fourth command, obtaining the blank database containing the backup file, and taking the blank database containing the backup file as a recovery database.
In an exemplary embodiment of the invention, the third module 530 may be further configured to:
determining a fifth command based on the database recovery script, wherein the fifth command is a command for deleting the database to be processed and/or the backup file;
based on the fifth command, the database to be processed and/or the backup file are deleted.
In an exemplary embodiment of the invention, the third module 530 may be further configured to:
and under the condition that the renaming operation is not successfully performed on the database to be processed based on the second command, restarting the access authority of the user on the database to be processed, and stopping the operation of determining the third command.
In an exemplary embodiment of the invention, the third module 530 may be further configured to:
and under the condition that the blank database is not successfully created based on the third command, changing the name of the database to be processed to the original name, restarting the access authority of the user to the database to be processed, and stopping the operation of determining the fourth command.
In an exemplary embodiment of the invention, the third module 530 may be further configured to:
under the condition that the backup file is not successfully imported into the blank database based on the fourth command, changing the name of the database to be processed to the original name, restarting the access authority of the user to the database to be processed, and deleting the blank database.
In an exemplary embodiment of the invention, the database to be processed is a clustered database.
In an exemplary embodiment of the invention, the system services of the server are provided by a single application or by a micro-service.
Fig. 6 illustrates a physical schematic diagram of an electronic device, as shown in fig. 6, which may include: processor 610, communication interface (Communications Interface) 620, memory 630, and communication bus 640, wherein processor 610, communication interface 620, and memory 630 communicate with each other via communication bus 640. The processor 610 may invoke logic instructions in the memory 630 to perform a database processing method that applies to a server that includes a database to be processed, the method comprising: acquiring the database to be processed; creating a file backup script corresponding to the database to be processed under the condition that the system service of the server is running, and carrying out backup operation on the database to be processed based on the file backup script to obtain a backup file; and under the condition that the data of the database to be processed is lost, creating a database recovery script corresponding to the backup file based on the backup file, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server recovers to obtain the recovery database under the condition that the system service is in operation.
Further, the logic instructions in the memory 630 may be implemented in the form of software functional units and stored in a computer-readable storage medium when sold or used as a stand-alone product. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In another aspect, the present invention also provides a computer program product, the computer program product comprising a computer program, the computer program being storable on a non-transitory computer readable storage medium, the computer program, when executed by a processor, being capable of executing a database processing method provided by the methods described above, the database processing method being applied to a server, the server comprising a database to be processed, the method comprising: acquiring the database to be processed; creating a file backup script corresponding to the database to be processed under the condition that the system service of the server is running, and carrying out backup operation on the database to be processed based on the file backup script to obtain a backup file; and under the condition that the data of the database to be processed is lost, creating a database recovery script corresponding to the backup file based on the backup file, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server recovers to obtain the recovery database under the condition that the system service is in operation.
In yet another aspect, the present invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, is implemented to perform a database processing method provided by the methods above, the database processing method being applied to a server, the server including a database to be processed, the method comprising: acquiring the database to be processed; creating a file backup script corresponding to the database to be processed under the condition that the system service of the server is running, and carrying out backup operation on the database to be processed based on the file backup script to obtain a backup file; and under the condition that the data of the database to be processed is lost, creating a database recovery script corresponding to the backup file based on the backup file, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server recovers to obtain the recovery database under the condition that the system service is in operation.
The apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in the respective embodiments or some parts of the embodiments.
It will further be appreciated that although operations are depicted in the drawings in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order, or that all illustrated operations be performed, to achieve desirable results. In certain circumstances, multitasking and parallel processing may be advantageous.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (14)

1. A database processing method, characterized by being applied to a server, the server including a database to be processed, the method comprising:
acquiring the database to be processed;
creating a file backup script corresponding to the database to be processed under the condition that the system service of the server is running, and carrying out backup operation on the database to be processed based on the file backup script to obtain a backup file;
and under the condition that the data of the database to be processed is lost, creating a database recovery script corresponding to the backup file based on the backup file, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server recovers to obtain the recovery database under the condition that the system service is in operation.
2. The method for processing a database according to claim 1, wherein the backup operation is performed on the database to be processed based on the file backup script to obtain a backup file, specifically comprising:
determining a backup command corresponding to the database to be processed based on the file backup script;
And carrying out backup operation on the database to be processed based on the backup command to obtain a backup file.
3. The method for processing a database according to claim 2, wherein the performing a backup operation on the database to be processed based on the backup command to obtain a backup file specifically includes:
based on the backup command, carrying out backup operation on the database to be processed to obtain backup files at different backup moments;
and taking the backup file with the backup time being the latest backup time as the backup file for constructing the recovery database.
4. A database processing method according to claim 2 or 3, wherein after said backup operation is performed on said database to be processed based on said backup command to obtain a backup file, said method further comprises:
determining a compression command corresponding to the backup file based on the file backup script;
based on the compression command, compressing the backup file to obtain a compressed backup file;
before the database restoration script corresponding to the backup file is created based on the backup file, the method further comprises:
And decompressing the compressed backup file to obtain the backup file.
5. The database processing method according to claim 1, wherein the constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file specifically includes:
determining a first command based on the database recovery script, wherein the first command is a command for closing the access authority of a user to the database to be processed;
under the condition that the access right of a user to the database to be processed is successfully closed based on the first command, determining a second command based on the database recovery script, wherein the second command is a command for renaming the database to be processed;
under the condition that the renaming operation is successfully carried out on the database to be processed based on the second command, determining a third command based on the database recovery script, wherein the third command is a command for creating a blank database, and the blank database is used for accepting the backup file;
determining a fourth command based on the database recovery script under the condition that the blank database is successfully created based on the third command, wherein the fourth command is a command for importing the backup file into the blank database;
And under the condition that the backup file is successfully imported into the blank database based on the fourth command, obtaining the blank database containing the backup file, and taking the blank database containing the backup file as the recovery database.
6. The database processing method according to claim 5, wherein after said obtaining the blank database containing the backup file, the method further comprises:
determining a fifth command based on the database recovery script, wherein the fifth command is a command for deleting the database to be processed and/or the backup file;
and deleting the database to be processed and/or the backup file based on the fifth command.
7. The database processing method according to claim 5, wherein after the determining of the second command based on the database recovery script, the method further comprises:
and under the condition that the renaming operation is not successfully performed on the database to be processed based on the second command, restarting the access right of the user to the database to be processed, and stopping the operation of determining a third command.
8. The database processing method according to claim 5, wherein after the determination of a third command based on the database recovery script, the method further comprises:
and under the condition that the blank database is not successfully created based on the third command, changing the name of the database to be processed to the original name, restarting the access authority of the user to the database to be processed, and stopping the operation of determining the fourth command.
9. The database processing method according to claim 5, wherein after the fourth command is determined based on the database recovery script, the method further comprises:
under the condition that the backup file is not successfully imported into the blank database based on the fourth command, changing the name of the database to be processed to the original name, restarting the access authority of the user to the database to be processed, and deleting the blank database.
10. The database processing method according to claim 1, wherein the database to be processed is a cluster-mode database.
11. The database processing method according to claim 1, wherein the system service of the server is provided by a single application or by a micro service.
12. A database processing apparatus for application to a server, the server including a database to be processed, the apparatus comprising:
the first module is used for acquiring the database to be processed;
the second module is used for creating a file backup script corresponding to the database to be processed under the condition that the system service of the server is running, and carrying out backup operation on the database to be processed based on the file backup script to obtain a backup file;
and the third module is used for creating a database recovery script corresponding to the backup file based on the backup file when the database to be processed is in data loss, and constructing a recovery database corresponding to the database to be processed based on the database recovery script and the backup file, so that the server recovers to obtain the recovery database when the system service is in operation.
13. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the database processing method of any of claims 1 to 11 when the program is executed by the processor.
14. A non-transitory computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when executed by a processor, implements the database processing method according to any one of claims 1 to 11.
CN202310146372.4A 2023-02-08 2023-02-08 Database processing method and device, electronic equipment and storage medium Pending CN116302688A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310146372.4A CN116302688A (en) 2023-02-08 2023-02-08 Database processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310146372.4A CN116302688A (en) 2023-02-08 2023-02-08 Database processing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116302688A true CN116302688A (en) 2023-06-23

Family

ID=86789859

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310146372.4A Pending CN116302688A (en) 2023-02-08 2023-02-08 Database processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116302688A (en)

Similar Documents

Publication Publication Date Title
US10423585B2 (en) Method and device for making differential upgrade package, and method and device for system differential upgrading
CN107220142B (en) Method and device for executing data recovery operation
US11741046B2 (en) Method and apparatus for creating system disk snapshot of virtual machine
CN107832406B (en) Method, device, equipment and storage medium for removing duplicate entries of mass log data
US8055937B2 (en) High availability and disaster recovery using virtualization
US9367301B1 (en) Dynamic update of a distributed message processing system
JP2020518926A (en) Backup and restore framework for distributed computing systems
US20160253245A1 (en) System, method and program product for backing up data
US8612799B2 (en) Method and apparatus of backing up subversion repository
CN112596951A (en) NAS data disaster tolerance method, device, equipment and storage medium
CN111400105A (en) Database backup method and device
US10318385B2 (en) Service recovery using snapshots and interservice messages
CN102833273A (en) Data restoring method when meeting temporary fault and distributed caching system
CN108664255B (en) Software upgrading method and device
CN113297007A (en) Data processing method and device
CN110620798A (en) Control method, system, equipment and storage medium for FTP connection
CN116302688A (en) Database processing method and device, electronic equipment and storage medium
CN109587202B (en) Method, device and system for coprocessing between file verification and data processing
CN115174596A (en) Equipment remote copying method, device and medium
CN115687019A (en) Database cluster fault processing method, intelligent monitoring platform, equipment and medium
CN112015520B (en) Data uploading system and method
CN105765908A (en) Method, client and system for multi-site automatic update
CN105740095A (en) Method and apparatus for restoring factory settings
CN104809033A (en) Backup method and system
CN112783832B (en) Method and device for storing snapshot file

Legal Events

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