Linux系统下的定时任务主要是用crontab来做。

  1. cd /home
  2. mkdir backup
  3. cd backup
  1. vi DatabaseName.sh
  1. #!/bin/bash
  2. /usr/local/mysql/bin/mysqldump -uusername -ppassword DatabaseName > /home/backup/DatabaseName_$(date +%Y%m%d_%H%M%S).sql
  3. #!/bin/bash
  4. /usr/local/mysql/bin/mysqldump -uusername -ppassword DatabaseName | gzip > /home/backup/DatabaseName_$(date +%Y%m%d_%H%M%S).sql.gz

赋权限

  1. chmod u+x DatabaseName.sh

创建定时任务

  1. crontab -e
  1. 01 3 * * * root/home/backup/DatabaseName.sh
  2. ## 表示每天 3 点钟执行备份

参考

https://ken.io/note/mysql-full-backup-linux-mysqldump-crontab