首页 > 代码库 > 批量备份mysql数据库(shell编程)
批量备份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编程)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。