#!/bin/bash ############################# # time:20191210 # fage trainning ############################# 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 {}