Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified charset to utf-8 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions binlog_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@
# ${db_user} is mysql username
# ${db_password} is mysql password
# ${db_host} is mysql host
# �������������������C
# —————————–
#/root/mysql_backup.sh
# every 30 minute AM execute database backup
# */30 * * * * /root/mysql_backup.sh
#/etc/cron.daily
#��÷��ڴӿ���ȥ���ݣ����Է�ֹ�����ڱ���ʱ������
#最好放在从库中去备份,可以防止主库在备份时的锁表

# the directory for story your backup file. #
backup_dir="/var/log/mysql/binlog/"

# Ҫ�����ı������� #
# 要保留的备份天数 #
backup_day=10

#���ݿⱸ����־�ļ��洢��·��
#数据库备份日志文件存储的路径
logfile="/var/log/binlog_backup.log"

###ssh�˿ں�###
###ssh端口号###
ssh_port=1204
###����ssh auto key���ļ�###
###定义ssh auto key的文件###
id_rsa=/root/auth_key/id_rsa_153.141.rsa
###����ssh auto username###
###定义ssh auto username###
id_rsa_user=rsync
###����Ҫͬ����Զ�̷�������Ŀ¼·���������Ǿ���·����###
###定义要同步的远程服务器的目录路径(必须是绝对路径)###
clientPath="/home/backup/mysqlbinlog"
###����Ҫ����ı����ļ�Ŀ¼·�� Դ�������������Ǿ���·����###
###定义要镜像的本地文件目录路径 源服务器(必须是绝对路径)###
serverPath=${backup_dir}
###��������������ip###
###定义生产环境的ip###
web_ip="192.168.0.2"

# date format for backup file (dd-mm-yyyy) #
Expand All @@ -42,30 +42,28 @@ test ! -d ${backup_dir} && mkdir -p ${backup_dir}
delete_old_backup()
{
echo "delete old binlog file:" >>${logfile}
# ɾ���ɵı��� ���ҳ���ǰĿ¼������ǰ���ɵ��ļ�������֮ɾ��
# 删除旧的备份 查找出当前目录下七天前生成的文件,并将之删除
find ${backup_dir} -type f -mtime +${backup_day} | tee delete_binlog_list.log | xargs rm -rf
cat delete_binlog_list.log >>${logfile}
}

rsync_mysql_binlog()
{
# rsync ͬ��������Server�� #
# rsync 同步到其他Server中 #
for j in ${web_ip}
do
echo "mysql_binlog_rsync to ${j} begin at "$(date +'%Y-%m-%d %T') >>${logfile}
### ͬ�� ###
### 同步 ###
rsync -avz --progress --delete --include="mysql-bin.*" --exclude="*" $serverPath -e "ssh -p "${ssh_port}" -i "${id_rsa} ${id_rsa_user}@${j}:$clientPath >>${logfile} 2>&1
echo "mysql_binlog_rsync to ${j} done at "$(date +'%Y-%m-%d %T') >>${logfile}
done
}

#�������ݿⱸ���ļ�Ŀ¼
#进入数据库备份文件目录
cd ${backup_dir}

#delete_old_backup
rsync_mysql_binlog

echo -e "========================mysql binlog backup && rsync done at "$(date +'%Y-%m-%d %T')"============================\n\n">>${logfile}
cat ${logfile}


cat ${logfile}
42 changes: 21 additions & 21 deletions mysql_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ${db_user} is mysql username
# ${db_password} is mysql password
# ${db_host} is mysql host
# �������������������C
# —————————–
#/root/mysql_backup.sh
# everyday 3:00 AM execute database backup
# 0 3 * * * /root/mysql_backup.sh
Expand All @@ -15,27 +15,27 @@ db_password="8H2QQQBEypp"
db_host="localhost"
# the directory for story your backup file. #
backup_dir="/home/backup/mysql/"
# Ҫ���ݵ����ݿ��� #
# 要备份的数据库名 #
#all_db="$(${mysql} -u ${db_user} -h ${db_host} -p${db_password} -Bse 'show databases')" #
all_db="dbname"

# Ҫ�����ı������� #
# 要保留的备份天数 #
backup_day=10

#���ݿⱸ����־�ļ��洢��·��
#数据库备份日志文件存储的路径
logfile="/var/log/mysql_backup.log"

###ssh�˿ں�###
###ssh端口号###
ssh_port=1204
###����ssh auto key���ļ�###
###定义ssh auto key的文件###
id_rsa=/root/auth_key/id_rsa_153.141.rsa
###����ssh auto username###
###定义ssh auto username###
id_rsa_user=rsync
###����Ҫͬ����Զ�̷�������Ŀ¼·���������Ǿ���·����###
###定义要同步的远程服务器的目录路径(必须是绝对路径)###
clientPath="/home/backup/mysql"
###����Ҫ����ı����ļ�Ŀ¼·�� Դ�������������Ǿ���·����###
###定义要镜像的本地文件目录路径 源服务器(必须是绝对路径)###
serverPath=${backup_dir}
###��������������ip###
###定义生产环境的ip###
web_ip="192.168.0.2"

# date format for backup file (dd-mm-yyyy) #
Expand All @@ -48,25 +48,25 @@ mysqldump="/usr/local/mysql-5.5.33/bin/mysqldump"
# the directory for story the newest backup #
test ! -d ${backup_dir} && mkdir -p ${backup_dir}

#�������ݿ⺯��#
#备份数据库函数#
mysql_backup()
{
# ȡ���е����ݿ��� #
# 取所有的数据库名 #
for db in ${all_db}
do
backname=${db}.${time}
dumpfile=${backup_dir}${backname}

#�����ݵ�ʱ�䡢���ݿ���������־
#将备份的时间、数据库名存入日志
echo "------"$(date +'%Y-%m-%d %T')" Beginning database "${db}" backup--------" >>${logfile}
${mysqldump} -F -u${db_user} -h${db_host} -p${db_password} ${db} > ${dumpfile}.sql 2>>${logfile} 2>&1

#��ʼ��ѹ��������־д��log
#开始将压缩数据日志写入log
echo $(date +'%Y-%m-%d %T')" Beginning zip ${dumpfile}.sql" >>${logfile}
#���������ݿ��ļ���ѹ��ZIP�ļ�����ɾ����ǰ��SQL�ļ�. #
#将备份数据库文件库压成ZIP文件,并删除先前的SQL文件. #
tar -czvf ${backname}.tar.gz ${backname}.sql 2>&1 && rm ${dumpfile}.sql 2>>${logfile} 2>&1

#��ѹ������ļ���������־��
#将压缩后的文件名存入日志。
echo "backup file name:"${dumpfile}".tar.gz" >>${logfile}
echo -e "-------"$(date +'%Y-%m-%d %T')" Ending database "${db}" backup-------\n" >>${logfile}
done
Expand All @@ -75,29 +75,29 @@ mysql_backup()
delete_old_backup()
{
echo "delete backup file:" >>${logfile}
# ɾ���ɵı��� ���ҳ���ǰĿ¼������ǰ���ɵ��ļ�������֮ɾ��
# 删除旧的备份 查找出当前目录下七天前生成的文件,并将之删除
find ${backup_dir} -type f -mtime +${backup_day} | tee delete_list.log | xargs rm -rf
cat delete_list.log >>${logfile}
}

rsync_mysql_backup()
{
# rsync ͬ��������Server�� #
# rsync 同步到其他Server中 #
for j in ${web_ip}
do
echo "mysql_backup_rsync to ${j} begin at "$(date +'%Y-%m-%d %T') >>${logfile}
### ͬ�� ###
### 同步 ###
rsync -avz --progress --delete $serverPath -e "ssh -p "${ssh_port}" -i "${id_rsa} ${id_rsa_user}@${j}:$clientPath >>${logfile} 2>&1
echo "mysql_backup_rsync to ${j} done at "$(date +'%Y-%m-%d %T') >>${logfile}
done
}

#�������ݿⱸ���ļ�Ŀ¼
#进入数据库备份文件目录
cd ${backup_dir}

mysql_backup
delete_old_backup
rsync_mysql_backup

echo -e "========================mysql backup && rsync done at "$(date +'%Y-%m-%d %T')"============================\n\n">>${logfile}
cat ${logfile}
cat ${logfile}