# feedback/comment/suggestions:http://www.real-blog.com/
# ----------------------------------------------------------------------
# your MySQL login information
# Db_user is MySQL username
# db_passwd is MySQL password
# db_host is MySQL host
# -----------------------------
Db_user= "Root"
Db_passwd= "123456"
db_host= "localhost"
# The directory for story your backup file.
Backup_dir= "/tmp/mybackup"
# Date format for backup file (dd-mm-yyyy)
Time= ' date + '%d-%m-%y '
# MySQL, mysqldump and some other bin ' s path
Mysql= "/usr/sbin/mysql"
mysqldump= "/usr/sbin/mysqldump"
Mkdir= "/bin/mkdir"
Rm= "/bin/rm"
mv= "/BIN/MV"
gzip= "/bin/gzip"
# Check the directory for store backup is writeable
Test! -W $backup _dir && echo "Error: $backup _dir is un-writeable." && exit 0
# The directory for stories the newest backup
Test! -D "$backup _dir/backup.0/" && $MKDIR "$backup _dir/backup.0/"
# Get all databases
all_db= ' $MYSQL-u $db _user-h $db _host-p$db_passwd-bse ' show databases ' | Grep-v grep | Grep-v schema '
For DB in $all _db
Do
$MYSQLDUMP-u $db _user-h $db _host-p$db_passwd $db | $GZIP-9 > "$backup _dir/backup.0/$time. $db. Gz"
Done
# Delete the oldest backup
test-d "$backup _dir/backup.5/" && $RM-rf "$backup _dir/backup.5"
# Rotate Backup Directory
for int in 4 3 2 1 0
Do
if (test-d "$backup _dir"/backup. " $int ")
Then
Next_int= ' expr $int + 1 '
$MV "$backup _dir"/backup. $int "" $backup _dir "/backup." $next _int "
Fi
Done
Exit 0
Mysqldump Backup and Recovery scripts