MySQL数据备份脚本

#!/bin/bash
#############################
# time:20191210
# fage
#############################

BACK_DIR=/application/mysqlbakdb
DB_LST=/tmp/db.lst
DATE=`date +%Y-%m-%d` 
mysql -u root -p'S1yxYRrE33TZPn1o' -e 'show databases' > $DB_LST

[ ! -d $BACK_DIR ] && mkdir -p $BACK_DIR
for i in $(grep -vE "Database|information_schema|test" $DB_LST)
do
    mysqldump --user='root' --password='S1yxYRrE33TZPn1o' --default-character-set=utf8 --add-locks --lock-all-tables $i > $BACK_DIR/$i-$DATE.sql
    [ "$PWD" != "$BACK_DIR" ] && cd $BACK_DIR 
    gzip  -f $BACK_DIR/$i-$DATE.sql
done

find $BACK_DIR -mtime +7 | xargs -i rm -rf {}
posted @ 2020-10-07 23:49  缺个好听的昵称  阅读(97)  评论(0编辑  收藏  举报