[Linux] crontab和shell每天定时备份数据库

在这个目录下建立shell文件

/home/ubuntu/shell_script/backup_db_gofly.sh

#!/bin/base
#定义备份文件路径
backupFilePath="/home/ubuntu/database/";
#定义备份文件名称
currentDate=`date +%F`;
backupFileName="${backupFilePath}backup_db_gofly_${currentDate}.sql";
mysqldump -h127.0.0.1 -P3306 -uxxxxx -pxxxxx 数据库名 > $backupFileName
#删掉10天以前的文件
find $backupFilePath -mtime +10 -exec rm {} ;  

增加cron规则 , 每天0点0分执行

0 0 */1 * *  root sh /home/ubuntu/shell_script/backup_db_gofly.sh
原文地址:https://www.cnblogs.com/taoshihan/p/13725900.html