vi mysql-backup.sh #!/bin/bash PATH=/usr/local/sbin:/usr/bin:/bin BACKDIR=/backup/mysql ROOTPASS=xxxxxxxx rm -p $BACKDIR mkdir -p $BACKDIR DBLIST=`ls -p /home/mysql | grep / | tr -d /` for dbname in $DBLIST do table_count=`mysql -u root -p$ROOTPASS -B -e "show tables" $dbname|wc -l` [ $table_count -ne 0 ] && mysqlhotcopy $dbname -u root -p $ROOTPASS $BACKDIR | logger -t mysqlhotcopy done chmod 700 mysql-backup.sh ./mysql-backup.sh cp -Rf /backup/mysql/test/ /home/mysql/ chown -R mysql:mysql /home/mysql/test/ chmod 700 /home/mysql/test/ chmod 660 /home/mysql/test/*