[原创]MYSQL周期备份shell脚本

Posted wsjhk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[原创]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脚本的主要内容,如果未能解决你的问题,请参考以下文章

Linux学习日记—Shell脚本与计划任务

shell脚本----周期压缩备份日志文件

MySql DUMP 自动备份数据库 Shell 脚本

MySql DUMP 自动备份数据库 Shell 脚本

MySql DUMP 自动备份数据库 Shell 脚本

Linux系统shell脚本之mysql备份