MySQL数据库进行分库备份shell脚本

来源:转载

[[email protected] scripts]# vi fenbiao_backup.sh #!/bin/bashMysqlUser=rootPassWord=backup123Port=3306Socket="/data/$Port/mysql.sock"MysqlCmd="mysql -u$MysqlUser -p$PassWord -S $Socket"Database=`$MysqlCmd -e "show databases;"|egrep -v "Database|_schema|mysql"`MysqlDump="mysqldump -u$MysqlUser -p$PassWord -S $Socket"IP=`ifconfig eth0|awk -F "[ :]+" 'NR==2 {print $4}'`BackupDir=/backup/$IP[ -d $BackupDir ] || mkdir -p $BackupDirfor dbname in $Database do [ ! -d /$BackupDir/$dbname ] && mkdir -p /$BackupDir/$dbname TABLE=`$MysqlCmd -e "show tables from $dbname;"|sed '1d'` for table in $TABLE do $MysqlDump $dbname $table|gzip >/$BackupDir/$dbname/${dbname}_${table}_$(date +%F).sql.gz donedone


分享给朋友:
您可能感兴趣的文章:
随机阅读: