MySQLDump 备份 Shell 脚本
#!/bin/sh - echo "************************************" echo "----Enterprise Cloud Data Center----" echo "--------By SERVEN-------------------" echo "************************************" db_user="databack" db_passwd="D9934393B04j" db_host="localhost" backup_dir="/home/backup/mysql" time="$(date +"%y%m%d%H%M%S")" MYSQL="/usr/bin/mysql" MYSQLDUMP="/usr/bin/mysqldump" MKDIR="/bin/mkdir" RM="/bin/rm" MV="/bin/mv" GZIP="/bin/gzip" test ! -w $backup_dir && echo "Error: $backup_dir is un-writeable." && exit 0 test ! -d "$backup_dir/$time/" && $MKDIR "$backup_dir/$time" all_db="$($MYSQL -u $db_user -h $db_host -p$db_passwd -Bse 'show databases')" for db in $all_db do $MYSQLDUMP -u $db_user -h $db_host -p$db_passwd --skip-lock-tables $db | $GZIP -9 > "$backup_dir/$time/$db.tar.gz" done test -d "$backup_dir/backup.5/" && $RM -rf "$backup_dir/backup.5" for int in 4 3 2 1 0 do if(test -d "$backup_dir"/backup."$int") then next_int='expr $int + 1' fi done echo "The backup is complete" find /home/backup/mysql/* -mtime +1|xargs rm -rf find /home/backup/mysql -type d -empty -exec rmdir {} \; >/dev/null 2>&1 exit 0;