Home > Database > Mysql Tutorial > Configuring automatic backup of mysql database under centos

Configuring automatic backup of mysql database under centos

王林
Release: 2020-01-22 20:08:48
forward
2228 people have browsed it

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
Copy after login

(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
Copy after login

4. Add executable permissions:

chmod u+x monarch-bak.sh
Copy after login

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
Copy after login

Add:

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

Restart crontab:

service crond restart
Copy after login

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!

source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template