十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
#!/bin/bash
成都创新互联专注于平罗网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供平罗营销型网站建设,平罗网站制作、平罗网页设计、平罗网站官网定制、微信小程序开发服务,打造平罗网络公司原创品牌,更为您提供平罗网站排名全网营销落地服务。#mysql database backup and restore the script
# define config variable
host=localhost
user=root
passwd=xxxxx
#this variable for grant
mainHostIp="127.0.0.1"
base_path=/opt/disk-webData/mysqlBackup
# base_path=/media/sf_website/yii/disk-webData/mysqlBackup
### backup
backupdb() {
bak_path=$base_path/$(date +%Y%m%d)/data
log_path=$base_path/$(date +%Y%m%d)/log
[ ! -d $bak_path ] && mkdir -p $bak_path
[ ! -d $log_path ] && mkdir -p $log_path
dblist=($(mysql -u$user -p$passwd -e "show databases;"|awk -F "|" '{print $1}'|grep -Ev "Database|mysql|information_schema|performance_schema"))
i=1
for dbname in "${dblist[@]}"
do
echo -e "\n$i --> Backup database $dbname ..."
file=$bak_path/"$dbname.sql"
mysqldump -h$host -u$user -p$passwd -B $dbname > $file
if [ -f $file ];then
success="$i --> $dbname backup success!"
echo $success;
echo $success >> $log_path/backupLog.log
echo "GRANT ALL PRIVILEGES ON $dbname.* TO admin@localhost;" >> $log_path/grant.log
echo "GRANT ALL PRIVILEGES ON $dbname.* TO admin@$mainHostIp;" >> $log_path/grant.log
fi
let i++
done
}
#restore
expr 1 + $1 &>/dev/null
if [ $? -eq 0 ];then
bak_path="$base_path"/$1/data
log_path="$base_path"/$1/log
#restore
cd $bak_path
dblist=($(ls))
i=1
for dbname in "${dblist[@]}"
do
echo -e "\n$i --> Restore database $dbname ..."
mysql -h$host -u$user -p$passwd < $dbname
success="$i --> $dbname restore success!"
echo $success
echo $success >> $log_path/restoreLog.log
let i++
done
#grant
# if [ -f $log_path/grant.log ];then
echo "Please ensure that [admin] user exist @[localhost & 127.0.0.1 & mainHostIp]";
sleep 15s
ii=1
cat $log_path/grant.log | while read line
do
echo "$ii --> $line"
mysql -h$host -u$user -p$passwd -e "$line"
let ii++
done
# fi
elif [ "$1" == backup ];then
backupdb
else
cd $base_path
dblist=($(ls))
i=1;
echo "Backup history ..."
for dbname in "${dblist[@]}"
do
echo "$i --> $dbname"
let i++
done
fi
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。