#!/bin/bash USER=root #用户 PASSWORD=123456 #密码 MYSQL_PATH=127.0.0.1 #地址 MYSQL_BIN=/bin/mysql MYSQL_DUMP_BIN=/bin/mysqldump MYSQL_CMD="${MYSQL_BIN} -u${USER} -p${PASSWORD} -h${MYSQL_PATH}" DATABASE=($(${MYSQL_CMD} -e "show databases;"|egrep -v "Database|mysql|test|information_schema")) BACKUP_DIR=/data/mysql_backup/$(date +%Y-%y-%d) #备份目录 [ -d ${BACKUP_DIR} ]||mkdir -p ${BACKUP_DIR} for database in ${DATABASE[@]};do echo $database BACKUP_DATABASE_DIR=${BACKUP_DIR}/${database} [ -d ${BACKUP_DATABASE_DIR} ]||mkdir -p ${BACKUP_DATABASE_DIR} for table in `${MYSQL_CMD} -e "use ${database};show tables;"`;do ${MYSQL_DUMP_BIN} -u${USER} -p${PASSWORD} -h${MYSQL_PATH} ${database} ${table} >${BACKUP_DATABASE_DIR}/${table}.sql done done
原文地址:https://www.cnblogs.com/zhangb8042/p/10148393.html
时间: 2024-10-29 19:11:42