#!/bin/bash
#数据库配置信息
#db_user = root
#db_password = Wdmima
#db_host = localhost
#备份目录
Backup_dir =/root/database/
#获取当前时间
Timestr = ' Date +%y%m%d '
#mysql command
#MYSQL = "/usr/local/mysql/bin/mysql"
#MYSQLDUMP = "/usr/local/mysql/bin/mysqldump"
#测试备份目录是否可写不可写则报错
Test! -W $backup _dir && echo "Error: $backup _dir in un-writeable." && exit 0
#测试备份目录中的最新备份文件夹是否存在, if it does not exist, create
Test! -D "/root/database/backup.0" && mkdir "/root/database/backup.0"
Echo $time
#制定要备份的数据库
For DB in www.mesuca.com vip.mesuca.com
Do
/usr/local/mysql/bin/mysqldump-u Root-pwdmima $db > "/root/database/backup.0/$db. ' Date +%y%m%d '. sql '
Done
#检测最旧的备份数据库是否存在, if you delete the
Test-d "/ROOT/DATABASE/BACKUP.7" && rm-rf "/ROOT/DATABASE/BACKUP.7"
#循环修改备份目录编号, record the old and new levels
for int in 6 5 4 3 2 1 0
Do
if (test-d "/root/database/backup. $int")
Then
# nint = ' expr $int + 1 '
#echo "$backup _dir/backup. $int"
#echo "$backup _dir/backup. $next _int"
MV "/root/database/backup. $int" "/root/database/backup. ' Expr $int + 1 '"
Fi
Done
Exit 0
This article is from the "Jinghong" blog, please be sure to keep this source http://haocaige.blog.51cto.com/1319521/1611507
MySQL Auto Backup shell