Mysql脚本——备份客户自建数据库
#!/bin/bash DATE=$(date +%F_%H-%M-%S) HOST=127.0.0.1 USER=root PASS=Linux@123 PORT=3306 BACKUP_DIR=./db_backup # 删选客户自建数据库(排除系统库) DB_LIST=$(mysql -u$USER -p$PASS -h$HOST -P$PORT -s -e "show databases;" 2>/dev/null| egrep -v "Database|information_schema|mysql|performance_schema|sys") # echo "mysql -u$USER -p$PASS -h$HOST -P$PORT -s -e \"show databases;\" 2>/dev/null| egrep -v \"Database|information_schema|mysql|performance_schema|sys\"" # 循环获取客户自建数据库,生成每个自建库的sql文件 for DB in $DB_LIST ; do BACKUP_NAME=$BACKUP_DIR/${DB}_${DATE}.sql if ! mysqldump -u$USER -p$PASS -h$HOST -P$PORT -B $DB > $BACKUP_NAME 2>/dev/null;then echo "$BACKUP_NAME 备份失败!" fi done
稳步前行,只争朝夕。