mysqldump daily scheduled backup

First write the script:

date_cur=$(date "+%Y-%m-%d")#注意空格
mkdir /usr/local/mysql_backup/data/$date_cur
mysqldump -udo_backup -p123456 --databases om_business > /usr/local/mysql_backup/data/$date_cur/om_business.sql

 

Then view the current user's scheduled tasks

>crontab  -l

Then edit the current user's timed task

>crontab  -e

i key edit mode, add a line

0 3 * * * /usr/local/mysql_backup/mysqldump_backup.sh

Esc to exit edit mode

:wq! save and exit

 

Restart the crond timing service

>service crond restart

Look at the status of the scheduled task again

>systemctl -l status crond.service

 

Finish

 

Import the backup sql file

mysql -uroot -p < om_business.sql

 

Notice:

1. Modifying /etc/crontab directly to add timed tasks is invalid, why?

2. Pay attention to empower the script file chmod 777 mysqldump_backup.sh

Guess you like

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