51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

CentOS创建mysql数据库定时备份压缩删除

一个CentOS下的数据库备份脚本,自动压缩,删除7天前的内容
#!/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

|-------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 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备份到哪里

赞(0)
未经允许不得转载:工具盒子 » CentOS创建mysql数据库定时备份压缩删除