批量备份mysql数据库(shell编程)
Posted Linux基础丶运维个人理解
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量备份mysql数据库(shell编程)相关的知识,希望对你有一定的参考价值。
#!/bin/bash DBPATH=/mysqlbak MYUSER=root MYPASS=7960224654321 SOCKET=/var/lib/mysql/mysql.sock MYCMD="mysql -u$MYUSER -p$MYPASS -S $SOCKET" MYDUMP="mysqldump -u$MYUSER -p$MYPASS -S $SOCKET" [ ! -d "$DBPATH" ] && mkdir $DBPATH for dbname in `$MYCMD -e "show databases;" | sed ‘1d‘| egrep -v "mysql|schema|accesslog"` do mkdir -p $DBPATH/${dbname}_$(date +%F) if [ `$MYCMD -e "show tables from $dbname;" | wc -l` -gt 0 ] then for table in `$MYCMD -e "show tables from $dbname;" | sed ‘1d‘` do $MYDUMP $dbname $table | gzip > $DBPATH/${dbname}_$(date +%F)/${dbname}_${table}.sql.gz done else echo " $dbname is null! no DBbak " fi done
以上是关于批量备份mysql数据库(shell编程)的主要内容,如果未能解决你的问题,请参考以下文章