CN111400105A - Database backup method and device - Google Patents

Database backup method and device Download PDF

Info

Publication number
CN111400105A
CN111400105A CN202010230936.9A CN202010230936A CN111400105A CN 111400105 A CN111400105 A CN 111400105A CN 202010230936 A CN202010230936 A CN 202010230936A CN 111400105 A CN111400105 A CN 111400105A
Authority
CN
China
Prior art keywords
backup
file
database
compressed file
server
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
CN202010230936.9A
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.)
Beijing Tuoshi Huanyu Network Technology Co ltd
Original Assignee
Beijing Tuoshi Huanyu Network Technology 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 Beijing Tuoshi Huanyu Network Technology Co ltd filed Critical Beijing Tuoshi Huanyu Network Technology Co ltd
Priority to CN202010230936.9A priority Critical patent/CN111400105A/en
Publication of CN111400105A publication Critical patent/CN111400105A/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/08Error detection or correction by redundancy in data representation, e.g. by using checking codes
    • G06F11/10Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's
    • G06F11/1008Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's in individual solid state devices
    • G06F11/1012Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's in individual solid state devices using codes or arrangements adapted for a specific type of error
    • 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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

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

Abstract

The invention provides a database backup method and a device, wherein the method comprises the following steps: when each database needs to be backed up, generating a backup file corresponding to each database, and acquiring an initial check code in each backup file; distributing a target backup server for each backup file according to a distribution rule; compressing each backup file to obtain a compressed file corresponding to each backup file, and storing each compressed file into a corresponding target backup server; and (4) verifying each compressed file by using each initial verification code, and recording the verified compressed file into a magnetic disk to finish the backup of each database. By applying the method, when the database needs to be backed up, the backup files are automatically generated, the backup server and the magnetic disk are randomly allocated for each backup file, and the backup server and the magnetic disk are used for backing up and storing each backup file, so that a backup script is not required to be configured, the database is automatically backed up, and the efficiency of backing up the database is improved.

Description

Database backup method and device
Technical Field
The present invention relates to the field of database backup technologies, and in particular, to a database backup method and apparatus.
Background
With the expansion of the business scale of a company, the number of company projects is gradually increased, and due to the limited data resources which can be stored in the database, the number of databases in the database cluster is gradually increased with the increase of the projects, so that each database in the database cluster needs to be periodically backed up to ensure that each database can meet the requirement of the business of the company.
In the prior art, in the process of backing up a database, a backup script is usually deployed on each database in a database cluster, and a backup file corresponding to each database is dumped through the backup script. However, when the number of databases in the database cluster is very large, technicians are required to deploy backup scripts for each database one by one, so that the process of backing up the databases is extremely complicated, the workload of the technicians is increased, and the efficiency of backing up the databases is low.
Disclosure of Invention
In view of this, the present invention provides a database backup method, by which an automatic backup of a database can be achieved, and efficiency of the backup of the database can be improved.
The invention also provides a database backup device for ensuring the realization and application of the method in practice.
A database backup method, comprising:
when each database in a database cluster needs to be backed up, generating a backup file corresponding to each database, and acquiring an initial check code set in each backup file;
allocating a target backup server for performing file backup for each backup file according to a preset allocation rule;
compressing each backup file to obtain a compressed file corresponding to each backup file, and storing each compressed file to a corresponding target backup server;
and verifying each compressed file by applying each initial verification code, and recording the verified compressed file into a disk corresponding to the target backup server to complete the backup of each database in the database cluster.
The above method, optionally, further includes:
acquiring database information of a database corresponding to each compressed file and server information of a target backup server corresponding to each compressed file, and determining backup time of each compressed file when the corresponding target backup server stores the compressed file;
and updating the information of each database, the information of each server and the backup time to a preset backup record table so as to realize the query of each backed-up database through the backup record table.
The above method, optionally, further includes:
when a database recovery request sent by a client is received, acquiring database parameters of a database to be recovered, wherein the database parameters are contained in the database recovery request;
determining a current target backup server for storing the database to be restored in the backup record table according to the database parameters;
and acquiring a compressed file corresponding to the database to be restored from the current target backup server, decompressing and restoring the compressed file.
Optionally, the method for allocating a target backup server for performing file backup for each backup file according to a preset allocation rule includes:
determining the item type of each database, classifying the backup files corresponding to each database according to each item type, and obtaining a file cluster corresponding to each item type;
randomly distributing a backup server for each file cluster, and judging whether the residual space of each backup server meets the backup requirement of each corresponding file cluster;
if the residual space of any backup server exists and meets the backup requirements of each corresponding file cluster, determining the backup server as a target backup server;
and if the residual space of any backup server does not meet the backup requirements of the corresponding file clusters, reallocating a new backup server until the currently-allocated backup server meets the backup requirements of the corresponding file clusters, and determining the currently-allocated backup server as the target backup server.
Optionally, in the method, the verifying each compressed file by applying each initial verification value includes:
acquiring a current check code set in each compressed file;
comparing the current check code in each compressed file with the initial check code of the corresponding backup file;
if the current check code in each compressed file is consistent with the initial check code of the corresponding backup file, determining that each compressed file passes the check;
and if the current check code in any compressed file is not consistent with the initial check code of the corresponding backup file, determining that the compressed file does not pass the check.
The above method, optionally, further includes:
when any compressed file fails to pass the verification, determining the compressed file which fails to pass the verification as a target compressed file;
and determining a database corresponding to the target compressed file, performing file additional recording on the database corresponding to the target compressed file according to preset additional recording time, and recording the target compressed file subjected to the file additional recording.
A database backup apparatus comprising:
the generating unit is used for generating a backup file corresponding to each database when each database in the database cluster needs to be backed up, and acquiring an initial check code set in each backup file;
the distribution unit is used for distributing a target backup server for carrying out file backup for each backup file according to a preset distribution rule;
the compression unit is used for compressing each backup file, obtaining a compressed file corresponding to each backup file, and storing each compressed file into a corresponding target backup server;
and the recording unit is used for verifying each compressed file by applying each initial verification code, recording the verified compressed file into a magnetic disk corresponding to the target backup server to complete the backup of each database in the database cluster.
The above apparatus, optionally, further comprises:
the recording unit is used for acquiring database information of a database corresponding to each compressed file and server information of a target backup server corresponding to each compressed file, and determining backup time of each compressed file when the corresponding target backup server stores the compressed file; and updating the information of each database, the information of each server and the backup time to a preset backup record table so as to realize the query of each backed-up database through the backup record table.
The above apparatus, optionally, the distribution unit, includes:
the first determining subunit is configured to determine the item type to which each database belongs, classify each backup file corresponding to each database according to each item type, and obtain a file cluster corresponding to each item type;
the judging subunit is used for randomly allocating a backup server to each file cluster and judging whether the residual space of each backup server meets the backup requirement of each corresponding file cluster;
the second determining subunit is configured to determine, if any remaining space of the backup server exists and the backup requirements of each corresponding file cluster are met, the backup server as a target backup server;
and the allocation subunit is not used for reallocating a new backup server if the residual space of any backup server exists and does not meet the backup requirements of the corresponding file clusters, and determining the currently allocated backup server as the target backup server until the currently allocated backup server meets the backup requirements of the corresponding file clusters.
The above apparatus, optionally, the recording unit includes:
the acquisition subunit is used for acquiring the current check code set in each compressed file;
the comparison subunit is used for comparing the current check code in each compressed file with the initial check code of the corresponding backup file;
a third determining subunit, configured to determine that each compressed file passes verification if a current verification code in each compressed file is consistent with an initial verification code of a corresponding backup file;
and the fourth determining subunit is configured to determine that the compressed file fails to be verified if the current check code in any compressed file is inconsistent with the initial check code of the corresponding backup file.
A storage medium comprises stored instructions, wherein when the instructions are executed, the storage medium is controlled to be located in a device to execute the database backup method.
An electronic device comprising a memory, and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by the one or more processors to perform the database backup method described above.
Compared with the prior art, the invention has the following advantages:
the invention provides a database backup method, which comprises the following steps: when each database in a database cluster needs to be backed up, generating a backup file corresponding to each database, and acquiring an initial check code set in each backup file; allocating a target backup server for performing file backup for each backup file according to a preset allocation rule; compressing each backup file to obtain a compressed file corresponding to each backup file, and storing each compressed file to a corresponding target backup server; and verifying each compressed file by applying each initial verification code, and recording the verified compressed file into a disk corresponding to the target backup server to complete the backup of each database in the database cluster. By applying the method provided by the invention, when each database in the database cluster needs to be backed up, the backup files can be automatically generated, the backup server and the magnetic disk are randomly distributed for each backup file, the backup server and the magnetic disk are used for backing up and storing each backup file, a backup script does not need to be configured for each database, the database can be automatically backed up, and the efficiency of backing up the database is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a flowchart of a method for database backup according to an embodiment of the present invention;
fig. 2 is a flowchart of another method of a database backup method according to an embodiment of the present invention;
fig. 3 is a flowchart of another method of a database backup method according to an embodiment of the present invention;
fig. 4 is a device structure diagram of a database backup device according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In this application, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions, and the terms "comprises", "comprising", or any other variation thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The invention is operational with numerous general purpose or special purpose computing device environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet-type devices, multi-processor apparatus, distributed computing environments that include any of the above devices or equipment, and the like.
The embodiment of the invention provides a database backup method, which can be applied to a plurality of system platforms, wherein an execution main body of the method can be a computer terminal or a processor of various mobile devices, and a flow chart of the method is shown in fig. 1 and specifically comprises the following steps:
s101: when each database in a database cluster needs to be backed up, generating a backup file corresponding to each database, and acquiring an initial check code set in each backup file;
in the embodiment of the present invention, the database cluster includes a plurality of databases, and each database may be used to store item data corresponding to different items, and may also be used to store item data corresponding to the same item. When any database exists in the database cluster, the stored data of the database cluster reaches the upper limit, or the set time of the database cluster reaches a certain period, determining that each database in the database cluster needs to be backed up. In the process of backing up the databases, backup files corresponding to each database are generated, and the databases are backed up in the form of the backup files.
When the backup file corresponding to each database is generated, each backup file has a corresponding initial check code set therein, and the initial check code is used as the unique verification password of the corresponding backup file, and may specifically be a message digest algorithm MD5 value.
S102: allocating a target backup server for performing file backup for each backup file according to a preset allocation rule;
in the embodiment of the invention, a plurality of backup servers are preset in a system for backing up the database. After each backup file is generated, a target backup server needs to be allocated for each backup file.
Specifically, the backup is performed according to a preset allocation rule, and in the process of allocating the target backup server to each backup file, a plurality of backup files may be simultaneously allocated to the same target backup server, or each backup file may be respectively allocated to different target backup servers.
S103: compressing each backup file to obtain a compressed file corresponding to each backup file, and storing each compressed file to a corresponding target backup server;
in the embodiment of the invention, after each backup file is distributed to the corresponding target backup server, the backup files are compressed to reduce the storage space occupied by each backup file, the compressed file corresponding to each backup file is obtained, and each compressed file is stored in the corresponding target backup server.
S104: and verifying each compressed file by applying each initial verification code, and recording the verified compressed file into a disk corresponding to the target backup server to complete the backup of each database in the database cluster.
In the embodiment of the present invention, after each backup file is backed up, each compressed file needs to be verified in order to prevent the compressed backup file from being damaged or part of data from being lost. And verifying each compressed file according to the pre-obtained initial verification code. If the current compressed file passes the verification, the compressed file can be recorded into a magnetic disk corresponding to the target backup server to which the compressed file belongs, and the compressed file is permanently stored through the magnetic disk.
Where a disk is a storage device external to the computer, such as a magnetic tape.
Optionally, after each compressed file is recorded to the corresponding magnetic disk, the magnetic disk may be marked, and the recorded compressed file in the magnetic disk is recorded. The compressed file recorded into the disk can be permanently stored. If any one database needs to be recovered, the compressed file corresponding to the database in the disk is read by the computer to recover the database.
In the database backup method provided by the embodiment of the invention, when each database in the database cluster needs to be backed up, backup files corresponding to each database are generated, and all data of the corresponding database are stored in each backup file. And acquiring the initial check code of each backup file for storage. After distributing target backup servers for each backup file according to distribution rules, compressing each backup file, storing the obtained compressed file into the corresponding target backup server, verifying each compressed file by using each initial check code, recording the verified compressed file into a disk for permanent storage, and completing the backup process of each database.
It should be noted that, in the method provided by the present invention, the compressed file is stored in the corresponding target backup server, and then the compressed file is recorded in the disk. In other words, in order to ensure the server space margin of each target backup server, the compressed files stored in each target backup server delete part of the compressed files in the target backup server after a certain time. After each compressed file is recorded to the disk, the compressed file recorded to the disk is not deleted and is permanently stored.
By applying the method provided by the embodiment of the invention, when the database needs to be backed up, the backup file is automatically generated, the backup server and the magnetic disk are allocated for each backup file, and each backup file is backed up and stored by the backup server and the magnetic disk without configuring a backup script, so that the database is automatically backed up, and the efficiency of backing up the database is improved.
In the method provided by the embodiment of the present invention, because the number of databases in the database cluster is large, after each database is backed up, the specific position backed up by each database needs to be recorded, so as to provide related information when the database is subsequently restored, and the specific recording process includes:
acquiring database information of a database corresponding to each compressed file and server information of a target backup server corresponding to each compressed file, and determining backup time of each compressed file when the corresponding target backup server stores the compressed file;
and updating the information of each database, the information of each server and the backup time to a preset backup record table so as to realize the query of each backed-up database through the backup record table.
In the database backup method provided by the embodiment of the invention, the database information of each database and the server information of each target backup server are acquired, and the backup time of each compressed file stored in each target backup server is determined. And updating the information of each database, the information of the server and the backup time into a backup record table, and recording the backup position and the backup time of each backed-up database backup by the backup record table.
The database information includes a corresponding database name, a database number, a project type to which the database belongs, and the like. The server information includes a server name, a server model, and the like of the backup server corresponding thereto. The backup record table is used for recording the backup server in which each database is respectively allocated, and when the database is restored or inquired in the follow-up process, the related information and the position can be traced back through the backup record table.
Optionally, when updating each database information, server information, and backup time into the backup record table, the disk information of the disk currently recorded by each compressed file may be obtained, and each disk information, the database information, the server information, and the backup time are updated into the backup record table at the same time.
Based on the method provided in the foregoing embodiment, after backing up each database, and updating each server information, database information, and backup time into the backup record table, when the database needs to be restored, the backed up database may be restored according to the content recorded in the backup record table, where a restoration process of the database is shown in fig. 2, and specifically may include:
s201: when a database recovery request sent by a client is received, acquiring database parameters of a database to be recovered, wherein the database parameters are contained in the database recovery request;
in the embodiment of the invention, when each backed-up database needs to be restored, a user sends a database restoration request through a client. The client may be a PaaS platform, and the database parameter may be a database name or a database number.
S202: determining a current target backup server for storing the database to be restored in the backup record table according to the database parameters;
in the embodiment of the present invention, since the database information of each backed-up database is recorded in the backup record table, the database information corresponding to the database to be restored can be searched according to the database parameters, and the current target backup server storing the compressed file corresponding to the database to be restored is determined according to the database information.
S203: and acquiring a compressed file corresponding to the database to be restored from the current target backup server, decompressing and restoring the compressed file.
In the embodiment of the invention, after a target backup server storing the compressed file corresponding to the database to be restored is determined, the compressed file corresponding to the database to be restored is obtained from the current target backup server, the compressed file is decompressed to obtain the corresponding backup file, and the backup file is restored to the corresponding database, so that the restoration process of the database is completed.
In the method provided by the embodiment of the invention, the database can be recovered after the database is backed up. When a database recovery request sent by a client is received, determining a database to be recovered corresponding to the database recovery request, and acquiring database parameters of the database to be recovered. And determining a current target backup server for storing the compressed file corresponding to the database to be restored according to the database parameters, and restoring the database after the compressed file is decompressed by the current target backup server.
It can be understood that, if each database which has been backed up needs to be restored within a short time, the compressed file corresponding to the database can be directly restored from the target backup server; if the recovery is needed after a long time, but the target backup server deletes the compressed file corresponding to the database, the database can be recovered through the compressed file in the disk.
By applying the method provided by the embodiment of the invention, the backed-up database can be recovered after the database is backed up, so that a user can conveniently inquire historical data through each backed-up database, and the user experience is improved.
In the method provided in the embodiment of the present invention, based on the content in step S102, in the process of performing database backup, a target backup server needs to be allocated to the backup file corresponding to each database, and specifically, the process of allocating according to an allocation rule may specifically include:
determining the item type of each database, classifying the backup files corresponding to each database according to each item type, and obtaining a file cluster corresponding to each item type;
randomly distributing a backup server for each file cluster, and judging whether the residual space of each backup server meets the backup requirement of each corresponding file cluster;
if the residual space of any backup server exists and meets the backup requirements of each corresponding file cluster, determining the backup server as a target backup server;
and if the residual space of any backup server does not meet the backup requirements of the corresponding file clusters, reallocating a new backup server until the currently-allocated backup server meets the backup requirements of the corresponding file clusters, and determining the currently-allocated backup server as the target backup server.
In the database backup method provided by the embodiment of the invention, a plurality of databases exist in the same database cluster, each database stores project data of different project types, and when backup servers need to be allocated to backup files, the databases belonging to the same project type need to be allocated to the same backup server, so that a user can restore the databases of the same project from the backup servers and search related data from the databases when the user needs to inquire related data of a certain project in the subsequent process.
Specifically, after determining the project types to which the databases belong, classifying the databases of the same project type to form a file cluster. That is, databases corresponding to backup files in a file cluster belong to the same project type. Randomly distributing a backup server for each file cluster, and judging whether the residual space of the corresponding backup server can store the file cluster according to the space occupied by each file cluster; if the residual space of the backup server can store the file cluster, determining the backup server to a target backup server of the file cluster; and if the residual space of the backup server can not store the file cluster, reallocating the backup server for the file cluster until the residual space of the currently-allocated backup server can store the file cluster, and determining the current backup server as the target backup server.
By applying the method provided by the embodiment of the invention, after the backup files are classified according to the item types to obtain the file clusters, the backup servers meeting the backup requirements of the file clusters are distributed for the file clusters, so that the backup files in the file clusters are backed up through the backup servers.
Optionally, in the method provided in the embodiment of the present invention, after classifying each backup file according to the item type and allocating the backup server, each backup file needs to be compressed to obtain a compressed file corresponding to each backup file, when each backup file is compressed, each backup file belonging to the same file cluster may be stored in the same file directory, and a preset compression tool is invoked to compress each file directory to obtain a compression package corresponding to each file directory, where each compression package includes a compressed file corresponding to each backup file in the corresponding file directory. When each compressed file is subsequently recorded to a corresponding disk, the recording process of each compressed file can be realized in a mode of recording each compressed packet.
It can be understood that, if each compressed file is recorded into the corresponding disk in the form of a compressed packet, each database corresponding to the compressed packet stored in one disk belongs to the same item type, which can facilitate a subsequent technician to search for certain item data.
Further, in the recording process of the magnetic disk, the compressed packets of different item types may be recorded into different magnetic disks respectively, or the compressed packets of different item types may be recorded into the same magnetic disk, and the specific recording manner is determined according to the actual service conditions, and this is not limited here.
In the method provided in the embodiment of the present invention, based on the content in step S104, before recording each compressed file, a process of verifying each compressed file by applying each obtained initial verification value is shown in fig. 3, and may specifically include:
s301: acquiring a current check code set in each compressed file;
in the embodiment of the invention, when the backup files corresponding to the databases are generated, an initial check code is set in each backup file, each backup file is compressed to obtain a corresponding compressed file, and a current check code set in each file is obtained.
It should be noted that, in the process of compressing each backup file, there may be a case of data loss, and if the data loss occurs in the compression process of the backup file, the initial check code corresponding to the backup file will also be changed.
S302: comparing the current check code in each compressed file with the initial check code of the corresponding backup file;
in the embodiment of the invention, each current check code is compared with the corresponding initial check code to determine whether the data loss exists in each backup file in the compression process.
S303: if the current check code in each compressed file is consistent with the initial check code of the corresponding backup file, determining that each compressed file passes the check;
in the embodiment of the present invention, if the current check code in each compressed file is consistent with the initial check code of the corresponding backup file, each compressed file passes the check, that is, the backup file corresponding to each compressed file does not lose data during the compression process.
S304: and if the current check code in any compressed file is not consistent with the initial check code of the corresponding backup file, determining that the compressed file does not pass the check.
In the embodiment of the present invention, if the current check code in any compressed file is inconsistent with the initial check code of the backup file corresponding to the current check code, it may be determined that data is lost when the backup file corresponding to the compressed file is compressed.
In the database backup method provided by the embodiment of the invention, after the backup file is compressed and stored in the corresponding target backup server, the compressed file needs to be recorded in the disk again, and since the compressed file backed up in the disk is permanently stored, whether the compressed file recorded in the disk has data loss or not needs to be determined. When a backup file corresponding to a database is to be generated, an initial check code of the backup file is firstly acquired, wherein the initial check code can be an MD5 value, and after the backup file is compressed to obtain a compressed file, a current check code which is set in the compressed file is acquired; and comparing the current check code with the initial check code, and if the current check code is consistent with the initial check code, determining that the compressed file has no data loss. If the two are not consistent, there may be data loss in the compressed file. And comparing the initial check code with the current check code to ensure that the compressed file of the client of the disk is a compressed file corresponding to the complete database.
Based on the content of step S304 in the foregoing embodiment, when the current check code in any compressed file is inconsistent with the initial check code of the backup file corresponding to the current check code, the method may further include:
when any compressed file fails to pass the verification, determining the compressed file which fails to pass the verification as a target compressed file;
and determining a database corresponding to the target compressed file, performing file additional recording on the database corresponding to the target compressed file according to preset additional recording time, and recording the target compressed file subjected to the file additional recording.
In the method provided by the embodiment of the invention, if the compressed file does not pass the verification, it can be determined that the current backup process of backing up the database corresponding to the compressed file fails, and the database needs to be subjected to additional recording so as to realize the backup of the database. The additional recording time is the additional recording days for additionally recording the database based on the current backup time, for example, if the additional recording days are five days, the data of the database of the previous five days are additionally recorded based on the current backup time, the additionally recorded data are compressed into the corresponding compressed file, and then the compressed file is recorded. And determining the integrity of each data in the database when the database is backed up in a supplementary recording mode.
The specific implementation procedures and derivatives thereof of the above embodiments are within the scope of the present invention.
Corresponding to the method described in fig. 1, an embodiment of the present invention further provides a database backup apparatus, which is used for implementing the method in fig. 1 specifically, and the database backup apparatus provided in the embodiment of the present invention may be applied to a computer terminal or various mobile devices, and a schematic structural diagram of the database backup apparatus is shown in fig. 4, and specifically includes:
a generating unit 401, configured to generate a backup file corresponding to each database when each database in the database cluster needs to be backed up, and acquire an initial check code that has been set in each backup file;
an allocating unit 402, configured to allocate, according to a preset allocation rule, a target backup server for performing file backup for each backup file;
a compressing unit 403, configured to compress each backup file, obtain a compressed file corresponding to each backup file, and store each compressed file in a corresponding target backup server;
a burning unit 404, configured to verify each compressed file by using each initial verification code, and burn the verified compressed file into a disk corresponding to the target backup server to which the compressed file belongs, so as to complete backup of each database in the database cluster.
In the database backup device provided in the embodiment of the present invention, when backups of databases are needed, the generation unit generates backup files corresponding to the databases, acquires an initial check code of each backup file, and the allocation unit allocates a target backup server to each backup file, so as to backup each backup file through the backup server, and specifically, after compressing each backup file through the compression unit, each target backup server backs up the compressed file. After each compressed file is verified, each compressed file is recorded into a corresponding disk by the recording unit, and the permanent backup database is realized.
By applying the device provided by the embodiment of the invention, the backup server and the disk are used for backup storage of each backup file, a backup script is not required to be configured, the database is automatically backed up, and the efficiency of backing up the database is improved.
The device provided by the embodiment of the invention further comprises:
the recording unit is used for acquiring database information of a database corresponding to each compressed file and server information of a target backup server corresponding to each compressed file, and determining backup time of each compressed file when the corresponding target backup server stores the compressed file; and updating the information of each database, the information of each server and the backup time to a preset backup record table so as to realize the query of each backed-up database through the backup record table.
The device provided by the embodiment of the invention further comprises:
the recovery unit is used for acquiring database parameters of a database to be recovered, which are contained in a database recovery request, when the database recovery request sent by a client is received; determining a current target backup server for storing the database to be restored in the backup record table according to the database parameters; and acquiring a compressed file corresponding to the database to be restored from the current target backup server, decompressing and restoring the compressed file.
In the apparatus provided in the embodiment of the present invention, the allocating unit 402 includes:
the first determining subunit is configured to determine the item type to which each database belongs, classify each backup file corresponding to each database according to each item type, and obtain a file cluster corresponding to each item type;
the judging subunit is used for randomly allocating a backup server to each file cluster and judging whether the residual space of each backup server meets the backup requirement of each corresponding file cluster;
the second determining subunit is configured to determine, if any remaining space of the backup server exists and the backup requirements of each corresponding file cluster are met, the backup server as a target backup server;
and the allocation subunit is not used for reallocating a new backup server if the residual space of any backup server exists and does not meet the backup requirements of the corresponding file clusters, and determining the currently allocated backup server as the target backup server until the currently allocated backup server meets the backup requirements of the corresponding file clusters.
In the apparatus provided in the embodiment of the present invention, the recording unit 404 includes:
the acquisition subunit is used for acquiring the current check code set in each compressed file;
the comparison subunit is used for comparing the current check code in each compressed file with the initial check code of the corresponding backup file;
a third determining subunit, configured to determine that each compressed file passes verification if a current verification code in each compressed file is consistent with an initial verification code of a corresponding backup file;
and the fourth determining subunit is configured to determine that the compressed file fails to be verified if the current check code in any compressed file is inconsistent with the initial check code of the corresponding backup file.
The device provided by the embodiment of the invention further comprises:
the supplementary recording unit is used for determining the compressed file which does not pass the verification as a target compressed file when any compressed file does not pass the verification; and determining a database corresponding to the target compressed file, performing file additional recording on the database corresponding to the target compressed file according to preset additional recording time, and recording the target compressed file subjected to the file additional recording.
The specific working processes of each unit and sub-unit in the database backup device disclosed in the above embodiment of the present invention may refer to corresponding contents in the database backup method disclosed in the above embodiment of the present invention, and are not described herein again.
The embodiment of the invention also provides a storage medium, which comprises a stored instruction, wherein when the instruction runs, the device where the storage medium is located is controlled to execute the database backup method.
An electronic device is provided in an embodiment of the present invention, and the structural diagram of the electronic device is shown in fig. 5, which specifically includes a memory 501 and one or more instructions 502, where the one or more instructions 502 are stored in the memory 501, and are configured to be executed by one or more processors 503 to perform the following operations according to the one or more instructions 502:
when each database in a database cluster needs to be backed up, generating a backup file corresponding to each database, and acquiring an initial check code set in each backup file;
allocating a target backup server for performing file backup for each backup file according to a preset allocation rule;
compressing each backup file to obtain a compressed file corresponding to each backup file, and storing each compressed file to a corresponding target backup server;
and verifying each compressed file by applying each initial verification code, and recording the verified compressed file into a disk corresponding to the target backup server to complete the backup of each database in the database cluster.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, the system or system embodiments are substantially similar to the method embodiments and therefore are described in a relatively simple manner, and reference may be made to some of the descriptions of the method embodiments for related points. The above-described system and system embodiments are only illustrative, wherein the units described as separate parts may or may not be physically separate, and the parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both.
To clearly illustrate this interchangeability of hardware and software, various illustrative components and steps have been described above generally in terms of their functionality. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A method for database backup, comprising:
when each database in a database cluster needs to be backed up, generating a backup file corresponding to each database, and acquiring an initial check code set in each backup file;
allocating a target backup server for performing file backup for each backup file according to a preset allocation rule;
compressing each backup file to obtain a compressed file corresponding to each backup file, and storing each compressed file to a corresponding target backup server;
and verifying each compressed file by applying each initial verification code, and recording the verified compressed file into a disk corresponding to the target backup server to complete the backup of each database in the database cluster.
2. The method of claim 1, further comprising:
acquiring database information of a database corresponding to each compressed file and server information of a target backup server corresponding to each compressed file, and determining backup time of each compressed file when the corresponding target backup server stores the compressed file;
and updating the information of each database, the information of each server and the backup time to a preset backup record table so as to realize the query of each backed-up database through the backup record table.
3. The method of claim 2, further comprising:
when a database recovery request sent by a client is received, acquiring database parameters of a database to be recovered, wherein the database parameters are contained in the database recovery request;
determining a current target backup server for storing the database to be restored in the backup record table according to the database parameters;
and acquiring a compressed file corresponding to the database to be restored from the current target backup server, decompressing and restoring the compressed file.
4. The method according to claim 1, wherein the allocating, according to a preset allocation rule, a target backup server for performing file backup for each backup file comprises:
determining the item type of each database, classifying the backup files corresponding to each database according to each item type, and obtaining a file cluster corresponding to each item type;
randomly distributing a backup server for each file cluster, and judging whether the residual space of each backup server meets the backup requirement of each corresponding file cluster;
if the residual space of any backup server exists and meets the backup requirements of each corresponding file cluster, determining the backup server as a target backup server;
and if the residual space of any backup server does not meet the backup requirements of the corresponding file clusters, reallocating a new backup server until the currently-allocated backup server meets the backup requirements of the corresponding file clusters, and determining the currently-allocated backup server as the target backup server.
5. The method of claim 1, wherein said applying each of the initial check values to check each of the compressed files comprises:
acquiring a current check code set in each compressed file;
comparing the current check code in each compressed file with the initial check code of the corresponding backup file;
if the current check code in each compressed file is consistent with the initial check code of the corresponding backup file, determining that each compressed file passes the check;
and if the current check code in any compressed file is not consistent with the initial check code of the corresponding backup file, determining that the compressed file does not pass the check.
6. The method of claim 5, further comprising:
when any compressed file fails to pass the verification, determining the compressed file which fails to pass the verification as a target compressed file;
and determining a database corresponding to the target compressed file, performing file additional recording on the database corresponding to the target compressed file according to preset additional recording time, and recording the target compressed file subjected to the file additional recording.
7. A database backup apparatus, comprising:
the generating unit is used for generating a backup file corresponding to each database when each database in the database cluster needs to be backed up, and acquiring an initial check code set in each backup file;
the distribution unit is used for distributing a target backup server for carrying out file backup for each backup file according to a preset distribution rule;
the compression unit is used for compressing each backup file, obtaining a compressed file corresponding to each backup file, and storing each compressed file into a corresponding target backup server;
and the recording unit is used for verifying each compressed file by applying each initial verification code, recording the verified compressed file into a magnetic disk corresponding to the target backup server to complete the backup of each database in the database cluster.
8. The apparatus of claim 7, further comprising:
the recording unit is used for acquiring database information of a database corresponding to each compressed file and server information of a target backup server corresponding to each compressed file, and determining backup time of each compressed file when the corresponding target backup server stores the compressed file; and updating the information of each database, the information of each server and the backup time to a preset backup record table so as to realize the query of each backed-up database through the backup record table.
9. The apparatus of claim 7, wherein the allocation unit comprises:
the first determining subunit is configured to determine the item type to which each database belongs, classify each backup file corresponding to each database according to each item type, and obtain a file cluster corresponding to each item type;
the judging subunit is used for randomly allocating a backup server to each file cluster and judging whether the residual space of each backup server meets the backup requirement of each corresponding file cluster;
the second determining subunit is configured to determine, if any remaining space of the backup server exists and the backup requirements of each corresponding file cluster are met, the backup server as a target backup server;
and the allocation subunit is not used for reallocating a new backup server if the residual space of any backup server exists and does not meet the backup requirements of the corresponding file clusters, and determining the currently allocated backup server as the target backup server until the currently allocated backup server meets the backup requirements of the corresponding file clusters.
10. The apparatus of claim 7, wherein the recording unit comprises:
the acquisition subunit is used for acquiring the current check code set in each compressed file;
the comparison subunit is used for comparing the current check code in each compressed file with the initial check code of the corresponding backup file;
a third determining subunit, configured to determine that each compressed file passes verification if a current verification code in each compressed file is consistent with an initial verification code of a corresponding backup file;
and the fourth determining subunit is configured to determine that the compressed file fails to be verified if the current check code in any compressed file is inconsistent with the initial check code of the corresponding backup file.
CN202010230936.9A 2020-03-27 2020-03-27 Database backup method and device Pending CN111400105A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010230936.9A CN111400105A (en) 2020-03-27 2020-03-27 Database backup method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010230936.9A CN111400105A (en) 2020-03-27 2020-03-27 Database backup method and device

Publications (1)

Publication Number Publication Date
CN111400105A true CN111400105A (en) 2020-07-10

Family

ID=71433123

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010230936.9A Pending CN111400105A (en) 2020-03-27 2020-03-27 Database backup method and device

Country Status (1)

Country Link
CN (1) CN111400105A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111880740A (en) * 2020-07-29 2020-11-03 平安科技(深圳)有限公司 Data processing method, device, computer system and readable storage medium
CN112667607A (en) * 2021-01-18 2021-04-16 中国民航信息网络股份有限公司 Historical data management method and related equipment
CN112861188A (en) * 2021-02-01 2021-05-28 青岛易来智能科技股份有限公司 Data aggregation system and method for multiple clusters
CN116185718A (en) * 2023-03-10 2023-05-30 上海翔麟马大数据科技有限公司 Data backup management system based on cloud storage

Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101694637A (en) * 2009-11-06 2010-04-14 金蝶软件(中国)有限公司 Method and system for restoring database
CN101714107A (en) * 2009-10-23 2010-05-26 金蝶软件(中国)有限公司 Database backup and recovery method and device in ERP system
CN103902735A (en) * 2014-04-18 2014-07-02 中国人民解放军理工大学 Application perception data routing method oriented to large-scale cluster deduplication and system
CN104516794A (en) * 2014-12-12 2015-04-15 国家电网公司 Database document backup method, device and system
CN105095300A (en) * 2014-05-16 2015-11-25 阿里巴巴集团控股有限公司 Method and system for database backup
CN105302671A (en) * 2015-11-11 2016-02-03 中国建设银行股份有限公司 Automatic backup and rollback method and device
CN105607964A (en) * 2015-10-30 2016-05-25 浪潮(北京)电子信息产业有限公司 FTP server backup method and apparatus
CN107122262A (en) * 2017-04-21 2017-09-01 杭州狮说教育科技有限公司 Database intelligent backup system based on agent
CN107797889A (en) * 2017-11-14 2018-03-13 北京思特奇信息技术股份有限公司 A kind of method and apparatus of checking system file backup integrity
CN107957920A (en) * 2017-10-31 2018-04-24 清远恒成智道信息科技有限公司 Database backup system
CN108628706A (en) * 2018-05-02 2018-10-09 北京新桥信通科技股份有限公司 Method, apparatus, system and the storage medium of data backup
CN109597722A (en) * 2018-12-29 2019-04-09 北京车和家信息技术有限公司 Database backup file restoration methods, device and electronic equipment
CN109634774A (en) * 2017-10-09 2019-04-16 北京国双科技有限公司 Data backup, restoration methods and device

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101714107A (en) * 2009-10-23 2010-05-26 金蝶软件(中国)有限公司 Database backup and recovery method and device in ERP system
CN101694637A (en) * 2009-11-06 2010-04-14 金蝶软件(中国)有限公司 Method and system for restoring database
CN103902735A (en) * 2014-04-18 2014-07-02 中国人民解放军理工大学 Application perception data routing method oriented to large-scale cluster deduplication and system
CN105095300A (en) * 2014-05-16 2015-11-25 阿里巴巴集团控股有限公司 Method and system for database backup
CN104516794A (en) * 2014-12-12 2015-04-15 国家电网公司 Database document backup method, device and system
CN105607964A (en) * 2015-10-30 2016-05-25 浪潮(北京)电子信息产业有限公司 FTP server backup method and apparatus
CN105302671A (en) * 2015-11-11 2016-02-03 中国建设银行股份有限公司 Automatic backup and rollback method and device
CN107122262A (en) * 2017-04-21 2017-09-01 杭州狮说教育科技有限公司 Database intelligent backup system based on agent
CN109634774A (en) * 2017-10-09 2019-04-16 北京国双科技有限公司 Data backup, restoration methods and device
CN107957920A (en) * 2017-10-31 2018-04-24 清远恒成智道信息科技有限公司 Database backup system
CN107797889A (en) * 2017-11-14 2018-03-13 北京思特奇信息技术股份有限公司 A kind of method and apparatus of checking system file backup integrity
CN108628706A (en) * 2018-05-02 2018-10-09 北京新桥信通科技股份有限公司 Method, apparatus, system and the storage medium of data backup
CN109597722A (en) * 2018-12-29 2019-04-09 北京车和家信息技术有限公司 Database backup file restoration methods, device and electronic equipment

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111880740A (en) * 2020-07-29 2020-11-03 平安科技(深圳)有限公司 Data processing method, device, computer system and readable storage medium
CN111880740B (en) * 2020-07-29 2024-05-24 平安科技(深圳)有限公司 Data processing method, device, computer system and readable storage medium
CN112667607A (en) * 2021-01-18 2021-04-16 中国民航信息网络股份有限公司 Historical data management method and related equipment
CN112667607B (en) * 2021-01-18 2024-02-27 中国民航信息网络股份有限公司 Historical data management method and related equipment
CN112861188A (en) * 2021-02-01 2021-05-28 青岛易来智能科技股份有限公司 Data aggregation system and method for multiple clusters
CN116185718A (en) * 2023-03-10 2023-05-30 上海翔麟马大数据科技有限公司 Data backup management system based on cloud storage
CN116185718B (en) * 2023-03-10 2023-12-15 上海翔麟马大数据科技有限公司 Data backup management system based on cloud storage

Similar Documents

Publication Publication Date Title
US11327799B2 (en) Dynamic allocation of worker nodes for distributed replication
CN111400105A (en) Database backup method and device
US20200348852A1 (en) Distributed object replication architecture
US20200159611A1 (en) Tracking status and restarting distributed replication
US11349915B2 (en) Distributed replication and deduplication of an object from a source site to a destination site
CN103197990B (en) Automated priority restores and relevant apparatus and method
US20190227710A1 (en) Incremental data restoration method and apparatus
CN111984465A (en) Database remote backup method, device, medium and electronic equipment
CN112181720A (en) Virtual data center backup method and device based on cloud management platform
CN111930716A (en) Database capacity expansion method, device and system
CN105867962A (en) System upgrading method and device
CN114138549A (en) Data backup and recovery method based on kubernets system
CN112579550B (en) Metadata information synchronization method and system of distributed file system
US8312237B2 (en) Automated relocation of in-use multi-site protected data storage
CN116700884A (en) Snapshot rollback data consistency test method, device, equipment and medium
CN111625396A (en) Backup data verification method, server and storage medium
CN109525649B (en) Data processing method and device for zookeeper client
CN108848136B (en) Shared storage method of cloud service cluster
CN104809033A (en) Backup method and system
US11687416B2 (en) Data backup optimization
CN116909816B (en) Database recovery method and device, storage medium and electronic equipment
CN116501552B (en) Data backup method, device, system and storage medium
CN117459401B (en) Method, device, equipment and storage medium for generating network target range environment snapshot
CN112596948B (en) Database cluster data backup method, device, equipment and storage medium
CN110661729B (en) Method and device for creating project resources based on Openstack system

Legal Events

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