Backup MySQL by Time Interval with Bash Script and Crontab

MySQL, 2016-04-04 02:32:00 UTC

1. Create bash script;

b=$(date +"%Y-%m-%d")
c=".sql"
mysqldump -uroot -pSecret123 --opt db_one > /home/myname/backup/db_one-$b$c
mysqldump -uroot -pSecret123 --opt db_two > /home/myname/backup/db_two-$b$c

 

2. Create Crontab;

$ crontab -e

 

In crontab file, add this line;

* 18 * * * /path/to/script.sh >/dev/null 2>&1

 

 Please note, /dev/null 2>&1 is prevent crontab to send an email to root


Share: