#! /bin/bash DBPATH=/server/backup MYUSER=root MYPASS=root MYCMD="mysql -u$MYUSER -p$MYPASS" MYDUMP="mysqldump -u$MYUSER -p$MYPASS" [ -d "$DBPATH" ] && mkdir $DBPATH for dbname in $MYCMD -e "show databases;"| sed '1,2d'|egrep -v "mysql|schema";do mkdir $DBPATH/${dbname}$(date +%F) -p for table in $MYCMD -e "show tables from $dbname";do $MYDUMP $dbname $table|gzip >$DBPATH/$(dbname)$(date +%F)/${dbname}_${table}.sql.gz done done