Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4159229
  • 博文数量: 240
  • 博客积分: 11504
  • 博客等级: 上将
  • 技术积分: 4277
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-28 14:24
文章分类

全部博文(240)

分类: Mysql/postgreSQL

2008-09-16 07:55:19


原理同样是利用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"

阅读(7458) | 评论(8) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-05-06 18:10:32

purge master 能不能去掉啊

chinaunix网友2009-04-14 17:55:28

有个疑问:增量备份是基于完全备份的。如果mysqldump的时候是2008-09-16 08:13:26 ,我增量的备份指定时间是哪个?是2008-09-16 08:13:25还是2008-09-16 08:13:26?

cyszys 2008-11-01 00:23:46

应该是不会漏掉的 谢谢楼主分享

yueliangdao06082008-10-23 12:52:09

我觉得不会漏掉,LS的你有例子证明这样会漏掉吗?

chinaunix网友2008-10-23 11:27:49

用时间来增量备份会不会漏数据阿。因为可能在同一秒里有很多的数据更新阿,正常情况是不是应该记录偏移量来导出数据,就像mysql主从同步那样!