CN112596958A - Database backup method, device, equipment and storage medium - Google Patents

Database backup method, device, equipment and storage medium Download PDF

Info

Publication number
CN112596958A
CN112596958A CN202011611605.6A CN202011611605A CN112596958A CN 112596958 A CN112596958 A CN 112596958A CN 202011611605 A CN202011611605 A CN 202011611605A CN 112596958 A CN112596958 A CN 112596958A
Authority
CN
China
Prior art keywords
backup
database
data
backed
local 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
CN202011611605.6A
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.)
Inspur Electronic Information Industry Co Ltd
Original Assignee
Inspur Electronic Information Industry 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 Inspur Electronic Information Industry Co Ltd filed Critical Inspur Electronic Information Industry Co Ltd
Priority to CN202011611605.6A priority Critical patent/CN112596958A/en
Publication of CN112596958A publication Critical patent/CN112596958A/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

Landscapes

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

Abstract

The invention discloses a database backup method, a database backup device, database backup equipment and a storage medium. The method disclosed by the invention comprises the following steps: selecting and exporting a database which needs to be backed up by a local server; leading the exported database into a backup catalog of the local server; synchronizing the data to be backed up in the backup catalog to a remote server at regular time; and after the synchronization is finished, restarting the local server, and cleaning the backup data before the preset time node. The device disclosed by the invention comprises a leading-out module, a leading-in module, a synchronization module and a cleaning module. The invention realizes the automatic and timed completion of database backup and ensures the safe and stable operation of the system.

Description

Database backup method, device, equipment and storage medium
Technical Field
The invention relates to the field of data backup, in particular to a database backup method, a database backup device, database backup equipment and a storage medium.
Background
A database is a warehouse that organizes, stores, and manages data according to a data structure, which is an organized, sharable, and uniformly managed collection of large amounts of data that is stored in computers for a long period of time. The storage space is large, and millions, millions and hundreds of millions of data can be stored.
The database of the server is a big thing that concerns the business in some way. However, the database may face some accidents during use, such as: the server tests hardware faults, artificial error operation and the like in the research and development.
Therefore, the database files of the server which is being used in the daily research, development, test, operation and maintenance are required to be backed up, the data backup of the server side is generally important data of an enterprise, and if the database data cannot be backed up in time, the working efficiency is reduced, and the labor cost and the financial cost are increased.
Disclosure of Invention
In order to solve the technical problems, the invention provides a database backup method, a database backup device, database backup equipment and a storage medium, so that the database backup can be automatically completed at regular time, and the safe and stable operation of a system is guaranteed.
In order to achieve the purpose, the invention adopts the following technical scheme:
a database backup method, comprising:
selecting and exporting a database which needs to be backed up by a local server;
leading the exported database into a backup catalog of the local server;
synchronizing the data to be backed up in the backup catalog to a remote server at regular time;
and after the synchronization is finished, restarting the local server, and cleaning the backup data before the preset time node.
Further, the method further comprises:
when the database of the local server is restored, the files in the remote server directory are synchronized to the local server directory.
Further, the regularly synchronizing the data to be backed up in the backup catalog to the remote server specifically includes:
and (3) regularly using a Linux synchronization file tool rsync + inotify to synchronize the data to be backed up to the remote server.
Further, the timing synchronizes the data to be backed up in the backup catalog to the remote server to be executed at a fixed time every day.
Further, the clearing of the backup data before the preset time node specifically includes: cleaning up the backup data 7 days ago.
Further, the method is realized through Shell scripts.
The invention also provides a database backup device, which comprises:
the export module is used for selecting and exporting the database which needs to be backed up by the local server;
the import module is used for importing the exported database into a backup catalog;
the synchronization module is used for synchronizing the data to be backed up in the backup catalog to the remote server at regular time;
and the cleaning module is used for restarting the local server and cleaning the backup data before the preset time node.
Further, the apparatus further comprises:
and the recovery module is used for synchronizing the files in the remote server directory to the local server directory.
The invention also provides a database backup device, which comprises:
a memory for storing a computer program;
a processor for implementing the steps of the database backup method as described above when executing the computer program.
The invention also proposes a storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the database backup method as described above.
The invention has the beneficial effects that:
the invention provides a database backup method, a device, equipment and a storage medium, which realize the backup of data at regular time and can recover the data at any time, thereby helping research and development personnel to debug problems or retest verification in time. In the event of an accident, the required data may be restored from the backup machine.
The invention is used as a strong guarantee for system operation, and operation and maintenance can timely recover data after enterprise-level data collapse, thereby reducing the influence caused by hardware problems to the maximum extent, improving the working efficiency and reducing the cost of manpower and financial resources.
Drawings
Fig. 1 is a schematic flow chart of a database backup method according to an embodiment of the present invention.
Fig. 2 is a schematic structural diagram of a database backup device according to an embodiment of the present invention.
Fig. 3 is a schematic structural diagram of a database backup device according to an embodiment of the present invention.
Detailed Description
In order to clearly explain the technical features of the present invention, the following detailed description of the present invention is provided with reference to the accompanying drawings. The following disclosure provides many different embodiments, or examples, for implementing different features of the invention. To simplify the disclosure of the present invention, the components and arrangements of specific examples are described below. Furthermore, the present invention may repeat reference numerals and/or letters in the various examples. This repetition is for the purpose of simplicity and clarity and does not in itself dictate a relationship between the various embodiments and/or configurations discussed. It should be noted that the components illustrated in the figures are not necessarily drawn to scale. Descriptions of well-known components and processing techniques and procedures are omitted so as to not unnecessarily limit the invention.
As shown in fig. 1, an embodiment of the present invention discloses a database backup method, including:
selecting and exporting a database which needs to be backed up by a local server;
leading the exported database into a backup catalog of the local server;
synchronizing the data to be backed up in the backup catalog to a remote server at regular time;
and after the synchronization is finished, restarting the local server, and cleaning the backup data before the preset time node.
Specifically, the embodiment of the invention is realized based on Linux, and the database data backup work is automatically realized through Shell scripts. The selection and export of the database to be backed up by the local server are realized by the following commands:
/usr/bin/mysqldump-u root-ppwd database>database2081218.sql
where pwd, the password for root, is not spaced from-p before.
The backup catalog is created by the following commands:
root user creates backup catalog:
mkdir-p/bak/mysqlbak
cd/bak/mysqlbak
the importing of the exported database into the backup directory of the local server is realized by the following commands:
/mysql-u root-p database<database20181218.sql
writing a backup script:
vim/usr/sbin/bakmysql.sh
the script code is as follows:
#!/bin/bash
#Name:backmysql.sh
#This is a shell script for auto DB backup and delete old backup
backupdir=/bak/mysqlbak
time=`date+%Y%m%d%H`
mysql_bin_dir/mysqldump-u root-ppwd database|gzip>$backupdir/database$time.sql.gz
the format requirement is as follows: -command space to be executed by exec { } space \;
find$backupdir-name"databasename_*.sql.gz"-type f-mtime+7-exec rm{}\;>/dev/null 2>&1
adding an execution permission for the sh script:
chmod+x/usr/sbin/backmysql.sh
the timed backup step is realized by/etc/crontab, a timed task is added at the/etc/crontab, and the timed backup step is executed at a fixed time every day:
vim/etc/crontab
003***root/user/sbin/backmysql.sh
the above command indicates that the backup is performed 3 point 00/day.
The synchronization of the files is performed by using the Linux synchronization file tool rsync + inotify. rsync is a data mirror backup tool under the unix-like system-Remote Sync. Remote Sync is a fast incremental backup tool, and Remote Sync supports local copy or Sync with other SSH, rsync hosts. The synchronization command is specifically as follows:
synchronizing local/bak/mysql/files to the remote server/bak/mysql/bak directory through the ssh port, excluding the mysql/index directory:
rsync-vzacu/bak/mysqlbak/username@IP.IP.IP.IP:/bak/mysqlbak--exclude"mysqlbak/index"-e"ssh-p 22"
after the synchronization is completed, the local server is restarted, backup data before a preset time node is cleared, and the restart crontab is as follows:
/etc/rc.d/init.d/crond restart
the regular backup can be completed and the backup data before 7 days can be cleaned.
When the database of the local server is restored, the files under the remote server directory/bak/mysqlbak are synchronized to the local server/bak/mysqlbak/directory:
rsync-vzrtopg--progress--delete username@IP.IP.IP.IP:/bak/mysqlbak/bak。
as shown in fig. 2, an embodiment of the present invention further discloses a database backup apparatus, including:
the export module is used for selecting and exporting the database which needs to be backed up by the local server;
the import module is used for importing the exported database into a backup catalog;
the synchronization module is used for synchronizing the data to be backed up in the backup catalog to the remote server at regular time;
and the cleaning module is used for restarting the local server and cleaning the backup data before the preset time node.
The device further comprises:
and the recovery module is used for synchronizing the files in the remote server directory to the local server directory.
As shown in fig. 3, an embodiment of the present invention further discloses a database backup device, including:
a memory for storing a computer program;
a processor for implementing the steps of the database backup method as described above when executing the computer program.
The embodiment of the invention also discloses a storage medium, wherein a computer program is stored on the storage medium, and the steps of the database backup method are realized when the computer program is executed by a processor.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
Although the embodiments of the present invention have been described with reference to the accompanying drawings, the scope of the present invention is not limited thereto. Various modifications and alterations will occur to those skilled in the art based on the foregoing description. And are neither required nor exhaustive of all embodiments. On the basis of the technical scheme of the invention, various modifications or changes which can be made by a person skilled in the art without creative efforts are still within the protection scope of the invention.

Claims (10)

1. A method for database backup, comprising:
selecting and exporting a database which needs to be backed up by a local server;
leading the exported database into a backup catalog of the local server;
synchronizing the data to be backed up in the backup catalog to a remote server at regular time;
and after the synchronization is finished, restarting the local server, and cleaning the backup data before the preset time node.
2. The database backup method of claim 1, wherein the method further comprises:
when the database of the local server is restored, the files in the remote server directory are synchronized to the local server directory.
3. The database backup method according to claim 1, wherein the synchronizing the data to be backed up in the backup directory to the remote server at regular time specifically comprises:
and (3) regularly using a Linux synchronization file tool rsync + inotify to synchronize the data to be backed up to the remote server.
4. The database backup method according to claim 1, wherein the timing of synchronizing the data to be backed up in the backup catalog to the remote server is performed starting at a fixed time of day.
5. The database backup method according to claim 1, wherein the cleaning of the backup data before the preset time node specifically includes: cleaning up the backup data 7 days ago.
6. The database backup method according to claim 1, wherein the method is implemented by Shell script.
7. A database backup apparatus, comprising:
the export module is used for selecting and exporting the database which needs to be backed up by the local server;
the import module is used for importing the exported database into a backup catalog;
the synchronization module is used for synchronizing the data to be backed up in the backup catalog to the remote server at regular time;
and the cleaning module is used for restarting the local server and cleaning the backup data before the preset time node.
8. The database backup apparatus of claim 7, wherein the apparatus further comprises:
and the recovery module is used for synchronizing the files in the remote server directory to the local server directory.
9. An apparatus for database backup, comprising:
a memory for storing a computer program;
processor for implementing the steps of the database backup method according to any of claims 1 to 6 when executing said computer program.
10. A storage medium having stored thereon a computer program for implementing the steps of the database backup method according to any one of claims 1 to 6 when executed by a processor.
CN202011611605.6A 2020-12-30 2020-12-30 Database backup method, device, equipment and storage medium Pending CN112596958A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011611605.6A CN112596958A (en) 2020-12-30 2020-12-30 Database backup method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011611605.6A CN112596958A (en) 2020-12-30 2020-12-30 Database backup method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112596958A true CN112596958A (en) 2021-04-02

Family

ID=75206547

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011611605.6A Pending CN112596958A (en) 2020-12-30 2020-12-30 Database backup method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112596958A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140038650A1 (en) * 2012-08-01 2014-02-06 Tencent Technology (Shenzhen) Company Limited Short message backup method, mobile terminal, and server
CN105204960A (en) * 2015-09-18 2015-12-30 浪潮集团有限公司 Method for regularly and remotely duplicating database by utilizing linux time pool
CN106790446A (en) * 2016-12-02 2017-05-31 深圳市小满科技有限公司 Data backup system and method
CN110659156A (en) * 2019-08-22 2020-01-07 苏州浪潮智能科技有限公司 Data processing method and device of web server and storage medium
CN110673982A (en) * 2019-08-26 2020-01-10 广东睿江云计算股份有限公司 Shared mysql database backup and recovery method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140038650A1 (en) * 2012-08-01 2014-02-06 Tencent Technology (Shenzhen) Company Limited Short message backup method, mobile terminal, and server
CN105204960A (en) * 2015-09-18 2015-12-30 浪潮集团有限公司 Method for regularly and remotely duplicating database by utilizing linux time pool
CN106790446A (en) * 2016-12-02 2017-05-31 深圳市小满科技有限公司 Data backup system and method
CN110659156A (en) * 2019-08-22 2020-01-07 苏州浪潮智能科技有限公司 Data processing method and device of web server and storage medium
CN110673982A (en) * 2019-08-26 2020-01-10 广东睿江云计算股份有限公司 Shared mysql database backup and recovery method and device

Similar Documents

Publication Publication Date Title
CN107256182B (en) Method and device for restoring database
JP4638905B2 (en) Database data recovery system and method
US7386752B1 (en) Using asset dependencies to identify the recovery set and optionally automate and/or optimize the recovery
CA2885059C (en) Retrieving point-in-time copies of a source database for creating virtual databases
CN105843702B (en) A kind of method and device for data backup
CN110704242B (en) Continuous data protection system and method
US10146633B2 (en) Data recovery from multiple data backup technologies
WO2008092912A1 (en) System and method of error recovery for backup applications
CN110263095B (en) Data backup and recovery method and device, computer equipment and storage medium
CN103914359A (en) Data recovery method and device
CN113360322B (en) Method and equipment for recovering data based on backup system
EP2542976B1 (en) Method and apparatus of backing-up subversion repository
WO2015043155A1 (en) Method and device for network element backup and recovery based on command set
US9483485B1 (en) Restore database from backup system where full and incremental backups are performed simultaneously
CN106445746A (en) Method and device for disaster recovery backup facing emergency replacement
US8595271B1 (en) Systems and methods for performing file system checks
CN112286730A (en) Method for performing remote full backup and recovery on HDFS file
WO2017067397A1 (en) Data recovery method and device
CN112596958A (en) Database backup method, device, equipment and storage medium
CN115658391A (en) Backup recovery method of WAL mechanism based on QianBase MPP database
CN114880167A (en) Data backup and recovery method, server, distributed system and storage medium
CN112685230B (en) Method for realizing backup and restoration of assigned time point by distributed database
CN110673985A (en) Method for automatically backing up version library, storage medium and server
CN104809033A (en) Backup method and system
US20170300387A1 (en) Always Current backup and recovery method on large databases with minimum resource utilization.

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20210402