一个CentOS下的数据库备份脚本,自动压缩,删除7天前的内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#!/bin/sh # Database info DB_NAME="whsir" DB_USER="root" DB_PASS="123456" # Others vars # whereis mysqldump BIN_DIR="/usr/local/mysql/bin" BCK_DIR="/opt/dbbak/whsir" DATE=`date +%Y%m%d` NEED_DELETE=$BCK_DIR/$DB_NAME.dump_$(date -d "7 days ago" "+%Y%m%d").sql.gz; # TODO DATABASE BAK AND DELETE 7 DAYS AGO BAKFILES mkdir -p $BCK_DIR $BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS $DB_NAME | gzip > $BCK_DIR/$DB_NAME.dump_$DATE.sql.gz rm -rf $NEED_DELETE |
DB_NAME需要备份的数据库名称
DB_USER数据库帐号
DB_PASS数据库密码
BIN_DIR路径mysqldump
BCK_DIR备份到哪里
原文链接:CentOS创建mysql数据库定时备份压缩删除,转载请注明来源!