CentOS database scheduled backup

Automatic database backup under centos7

crontab command

Create a new shell script file dbbackup.sh and add the following:

#!/bin/bash
/home/mysql/bin/mysqldump -uUSER -pPWD DBNAME | gzip > /home/backup/DBNAME$(date +%Y%m%d_%H%M%S).sql.gz
#end

in:

/home/mysql is the database installation path,

mysqldump is the mysql command, under the bin folder of the mysql installation path, ie /home/mysql/bin/,

USER is changed to the database account username,

Change PWD to database account password,

To change DBNAME to the name of the database you want to back up, you need to change two places.

/home/backup is the backup file storage path, and the backup folder must be created in advance.

After the script is created, create a scheduled task.

crontab -e

It is equivalent to open the editor and enter (start backup at 23:00 every night):

00 23 * * * /home/backup/dbbackup.sh

:wq to save.

crond basic command:

1. Check the status: service crond status



2. Start: service crond start


3. Shut down: service crond stop


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325161938&siteId=291194637