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`
脚本运行后
时间: 2024-12-17 16:40:00