日期:2014-05-16 浏览次数:20731 次
公司项目用到了Mysql的备份与恢复操作
?
现把脚本程序做下笔记
?
Mysql备份与恢复
#!/bin/sh dir=/home/atj/data/tmp echo -------DB_Publish-------` if [ ! -e $dir ]; then mkdir -p $dir fi backup() { aip=$1 user=$2 pass=$3 db=$4 name=$5 file=$dir/$name.sql if [ ! -f $file ];then touch $file fi mysqldump -h$aip -u$user -p$pass $db > $file #数据库备份命令 if [ $? != 0 ]; then echo "ERROR:Database $db backup fail!!!" exit 0 else echo "SUCCESS:Database $db backup success! " fi } backup $1 $2 $3 db_atj source_backup backup $4 $5 $6 db_atj target_backup mysql -h$4 -u$5 -p$6 db_atj1 < $dir/source_backup.sql #数据库恢复操作 if [ $? != 0 ]; then echo "ERROR:Database publish error !!!" exit 0 else echo "SUCCESS:Database publish success !!!" fi exit 0
?