mysql数据库分库备份脚本开发使用
mysql数据库分库备份脚本开发使用
- #!/bin/bash
- #*****************************************************
- # Author: suixiaofeng
- # blog:https://blog.cool360.org
- # Email: 258818040@qq.com
- # Last modified: 2017-07-06 13:52
- # Filename: 20170706.sh
- # Description:
- #****************************************************
- PATH="/usr/local/mysql/bin:$PATH"
- DBPATH=/back
- MYUSER=root
- MYPASS=test
- SOCKET=/db/mysql.sock
- MYCMD="mysql -u$MYUSER -p$MYPASS -S $SOCKET"
- MYSUMP="mysqldump -u$MYUSER -p$MYPASS -S $SOCKET"
- mkdir $DBPATH/$(date +%F)
- [ ! -d "$DBPATH" ] && mkdir $DBPATH
- for dbname in `$MYCMD -e "show databases;" | sed '1,2d'| egrep -v "mysql|schema"`
- do
- $MYSUMP $dbname | gzip >$DBPATH/$(date +%F)/${dbname}_$(date +%F).sql.gz
- # $MYSUMP $dbname > $DBPATH/${dbname}_$(date +%F).sql
- done
备注:
mysqldump -u$MYUSER -p$MYPASS -S /db/mysql.sock dbname |gzip > dbname.sql.gz 备份压缩
mysql数据库分库分表备份脚本开发使用。
#!/bin/bash #***************************************************** # Author: suixiaofeng # blog:https://bk.devopstack.cn # Email: 258818040@qq.com # Last modified: 2017-07-06 13:52 # Filename: 20170706.sh # Description: #**************************************************** PATH="/usr/local/mysql/bin:$PATH" DBPATH=/u02/back MYUSER=root MYPASS=test SOCKET=/tmp/mysql.sock MYCMD="mysql -u$MYUSER -p$MYPASS -S $SOCKET" MYSUMP="mysqldump -u$MYUSER -p$MYPASS -S $SOCKET" [ ! -d "$DBPATH" ] && mkdir $DBPATH for dbname in `$MYCMD -e "show databases;" | sed '1,2d'| egrep -v "mysql|schema"` do mkdir $DBPATH/$(date +%F)/${dbname} -p for table in `$MYCMD -e "show tables from $dbname;"|sed '1d'` do $MYSUM $dbname $table |gzip >$DBPATH/$(date +%F)/${dbname}/${dbname}_${table}.sql.gz done done
嗨、骚年、快来消灭0回复。