首页 > 代码库 > [原创]MYSQL周期备份shell脚本
[原创]MYSQL周期备份shell脚本
这个脚本是实现阿里云mysql数据库全量周期备份的shell脚本,实现备份数据按一周星期几分开存放。一下是脚本内容:
#!/bin/bash
echo `date`
echo "backup begin!!!"
DATE1=`date +%Y%m%d%H%M%S`
DATE2=`date +%w`
BACKUPDIR="/data/backup/backupdir/"
BACKUPPATH="/data/backup"
BACKUPNAME="/data/backup/backup_${DATE1}.tar.gz"
NAME=`mysql -hrdsabcdefghijklmnopqrstuvwxyz.mysql.rds.aliyuncs.com -uusername -ppassword <<EOF
show databases;
exit
EOF`
for dbname in $NAME;do
if [ "$dbname" = "Database" ];then
echo "The ‘Database‘ is not a database."
else
mysqldump -hrdsabcdefghijklmnopqrstuvwxyz.mysql.rds.aliyuncs.com -uusername -ppassword $dbname > $BACKUPDIR${dbname}.sql
fi
done
cd $BACKUPDIR
tar zcf $BACKUPNAME *
echo `date`
echo "backup over!!!"
case $DATE2 in
1) mv $BACKUPNAME $BACKUPPATH/1;;
2) mv $BACKUPNAME $BACKUPPATH/2;;
3) mv $BACKUPNAME $BACKUPPATH/3;;
4) mv $BACKUPNAME $BACKUPPATH/4;;
5) mv $BACKUPNAME $BACKUPPATH/5;;
6) mv $BACKUPNAME $BACKUPPATH/6;;
0) mv $BACKUPNAME $BACKUPPATH/7;;
*) echo $DATE2;;
esac
cd $BACKUPDIR
rm -rf *
echo `date`
echo "Over!!!"
[原创]MYSQL周期备份shell脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。