时间:2021-07-01 10:21:17 帮助过:4人阅读
1
#!/bin/bash echo "begin" echo `date` BKDIR=/data/sqlback HOST=localhost PASSWORD=linwei USER=root if [ ! -d $BKDIR ];then mkdir -p $BKDIR chown mysql.mysql $BKDIR fi cd $BKDIR BKDBF=$BKDIR"/dblist.txt" mysql -u$USER -h$HOST -p$PASSWORD -e ‘show databases‘ |grep -v Database |grep -v information_schema | grep -v performance_schema > $BKDBF #注意引用外部变量USER HOST PASSWORD 在awk里用单引号括起来. cat $BKDBF | awk ‘{print "if [ ! -d "$1" ];then mkdir "$1";chown mysql.mysql "$1";fi;rm -f "$1"/*;mysqldump -u‘$USER‘ -h‘$HOST‘ -p‘$PASSWORD‘ --tab="$1" "$1" "}‘ > ./bk.sh /bin/sh ./bk.sh cat $BKDBF |awk ‘{print "gzip "$1"/*"}‘ > $BKDIR"/gz.sh" sh ./gz.sh echo "end" echo `date`
脚本运行后
本文出自 “12208412” 博客,请务必保留此出处http://12218412.blog.51cto.com/12208412/1899376
mysqldump --tab 备份
标签:mysqldump