Home  >  Article  >  Database  >  Configuring automatic backup of mysql database under centos

Configuring automatic backup of mysql database under centos

王林
王林forward
2020-01-22 20:08:482113browse

Configuring automatic backup of mysql database under centos

1. Check the disk space

Execute df -h Select the directory with the largest remaining space (start with / directory For example)

2. Create a backup directory

cd /    
mkdir backup
cd backup

(Related video tutorial sharing: mysql video tutorial)

3. Create a backup Shell script

vim monarch-bak.sh #monarch是数据库名
mysqldump -uroot -p980225 monarch> /backup/monarch_$(date +%Y-%m-%d_%H:%M:%S).sql
#对备份进行压缩:mysqldump -uusername -ppassword DatabaseName | gzip > /home/backup/DatabaseName_$(date +%Y%m%d_%H%M%S).sql.gz

4. Add executable permissions:

chmod u+x monarch-bak.sh

After adding executable permissions, first Execute it to see if there are any errors in the script and whether it can be used normally: ./bkDatabaseName.sh

5. Add a scheduled backup task

Confirm whether crontab is installed.

crontab -e

Add:

22 11 * * * source /backup/monarch-bak.sh #解释 每天11:22执行/backup/monarch-bak.sh脚本

Restart crontab:

service crond restart

Recommended related articles and tutorials: mysql tutorial

The above is the detailed content of Configuring automatic backup of mysql database under centos. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete