免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2032 | 回复: 0
打印 上一主题 下一主题

【原创】MySQL增量备份脚本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-16 07:55 |只看该作者 |倒序浏览

                               
原理同样是利用MySQL的二进制日志,我写了很详细的注释。
有什么问题或者建议的可以给我EMAIL.
#!/bin/sh## Created by david yeung at 2008-09-16## File name:backup_increment## Backup mysql's increment data after daily backup.## Usage:# If you database name is t_girl and you want to backup from 2008-09-16 08:13:26.# ./backup_increment t_girl 20080916081326## You can simple put this file into crontab in order to work automatically.## Put your own database name here.
DBNAME=$1
# You own specific datatime.# For example,2008-09-16 08:13:26 should be replaced with 20080916081326 here.#
USERDATETIME=$2
# You own backup directory.
BACKUPDIR=/home/david_yeung/backup_db
# You own backup user.# He must have lock tables,select,super privileges.# Also replication client privileges if your mysqld was set up as Master/Slave.
USERNAME=backup_user
PASSWD=123456
# Socket path.
SOCKET=/tmp/mysql_3306.sock
# All the binary logs.
LOG=/usr/local/mysql/data/ytt-bin.[0-9]*
# Backup file name.
TARNAME="$BACKUPDIR"/incrementbackup"$1""$2"
# Copy all the binary logs here to prevent failed backup.
cp -rf `echo $LOG` /home/david_yeung/logs
# Change the current directory.# If you have aready put mysql into your environment variable named path,you can comment this line and use simple mysql instead of /bin/mysql.#
cd /usr/local/mysql
bin/mysql -u$USERNAME -p"$PASSWD" -S$SOCKET -e "purge master logs before ${USERDATETIME}"
bin/mysqlbinlog -u$USERNAME -p"$PASSWD" -S$SOCKET -d$DBNAME `echo $LOG` --start-datetime="$USERDATETIME"> "$TARNAME"
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/29134/showart_1194259.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP