官网网址:http://mysqlbackup.zmanda.com/
说明:本次是在一台mysql完成
一 依赖包安装
yum -y install perl-XML-Parser yum -y install xinetd cpanperl -MCPAN -e 'install DBI' && perl -MCPAN -e 'install XML::Parser'
二 软件下载
安装mysql-zrm需要的包完毕现在安装软件
cd /softwget http://www.zmanda.com/downloads/community/ZRM-MySQL/2.2/RPM/MySQL-zrm-2.2.0-1.noarch.rpmwget http://www.zmanda.com/downloads/community/ZRM-MySQL/2.2/RPM/MySQL-zrm-client-2.2.0-1.noarch.rpm[root@localhost mysql]# rpm -ivh MySQL-zrm-*.rpmPreparing... ########################################### [100%] 1:MySQL-zrm ########################################### [ 50%]Checking and Migrating old ZRM data 2:MySQL-zrm-client ########################################### [100%]
三 创建一个mysql用户,备份专用。
mysql> grantallprivilegeson *.* to"bakuser"@"%" identified by'123456';mysql> flush privileges;
四 检查Mysql-ZRM安装情况
配置文件在/etc/mysql-zrm里面-rwxr-x---. 1 root root 11932 Apr 8 18:21 mysql-zrm.conf-rwxrwx---. 1 mysql mysql 48 Feb 4 2010 mysql-zrm-release-rwxrwx---. 1 mysql mysql 3215 Feb 4 2010 mysql-zrm-reporter.conf启动文件[root@localhost mysql-zrm]# ll /usr/bin/mysql-zrm*-rwxr-x---. 1 mysql mysql 3529 Feb 4 2010 /usr/bin/mysql-zrm-rwxr-x---. 1 mysql mysql 1807 Feb 4 2010 /usr/bin/mysql-zrm-abort-backup-rwxr-x---. 1 mysql mysql 71004 Feb 4 2010 /usr/bin/mysql-zrm-backup-rwxr-x---. 1 mysql mysql 1579 Feb 4 2010 /usr/bin/mysql-zrm-check-rwxr-x---. 1 mysql mysql 2925 Feb 4 2010 /usr/bin/mysql-zrm-extract-backup-rwxr-x---. 1 mysql mysql 1796 Feb 4 2010 /usr/bin/mysql-zrm-getconf-rwxr-x---. 1 mysql mysql 4454 Feb 4 2010 /usr/bin/mysql-zrm-list-rwxr-x---. 1 mysql mysql 12184 Feb 4 2010 /usr/bin/mysql-zrm-manage-backup-rwxr-x---. 1 mysql mysql 2683 Feb 4 2010 /usr/bin/mysql-zrm-migrate-file-ownership-rwxr-x---. 1 mysql mysql 12584 Feb 4 2010 /usr/bin/mysql-zrm-parse-binlogs-rwxr-x---. 1 mysql mysql 4983 Feb 4 2010 /usr/bin/mysql-zrm-purge-rwxr-x---. 1 mysql mysql 29113 Feb 4 2010 /usr/bin/mysql-zrm-reporter-rwxr-x---. 1 mysql mysql 30789 Feb 4 2010 /usr/bin/mysql-zrm-restore-rwxr-x---. 1 mysql mysql 12920 Feb 4 2010 /usr/bin/mysql-zrm-scheduler-rwxr-x---. 1 mysql mysql 8238 Feb 4 2010 /usr/bin/mysql-zrm-verify-backup日志默认路径:/var/log/mysql-zrm/备份文件默认路径:/var/lib/mysql-zrm/
五 配置文件修改 vim mysql-zrm.conf
[root@localhost mysql-zrm]# grep -v '^#' mysql-zrm.conf |sed '/^$/d'##下面这些参数默认都是注释的,需要去掉#号backup-level=0 ##全备份的级别为0backup-mode=logical ##备份方式为逻辑备份retention-policy=10d ##保存为10天compress=1 ##使用压缩备份database=mysql ##这个需要备份数据库名称。如果要全部备份,请开始这个参数上面的all-databases=1即可全部数据库备份user="bakuser" ##备份账号password="123456" ##账号密码verbose=1 ##备份日志信息mailto="[email protected] ##这个是备份完毕之后报告的邮箱
六 测试一个全局备份
新建一个目录 拷贝一份配置文件[root@localhost mysql-zrm]#mkdir allback[root@localhost mysql-zrm]#cp mysql-zrm.conf allback/mysql-zrm.conf[root@localhost mysql-zrm]#cd allback 使用root来测试[root@localhost mysql-zrm]# mysql-zrm-scheduler --now --backup-set allbackschedule:INFO: ZRM for MySQL Community Edition - version 2.2.0Logging to /var/log/mysql-zrm/mysql-zrm-scheduler.logbackup:INFO: ZRM for MySQL Community Edition - version 2.2.0allback:backup:INFO: START OF BACKUPallback:backup:INFO: PHASE START: Initializationallback:backup:INFO: The quick backup-type is supported onlyfor snapshot backups. Setting backup-type to'regular'allback:backup:INFO: Mail address: [email protected] is okallback:backup:INFO: ZRM Temporary configuration file = /etc/mysql-zrm/allback/tmp0WVzB.confallback:backup:INFO: {allback:backup:INFO: quiet=0allback:backup:INFO: verbose=1allback:backup:INFO: retention-policy=10dallback:backup:INFO: backup-level=0allback:backup:INFO: [email protected]:backup:INFO: databases=mysqlallback:backup:INFO: mail-policy=alwaysallback:backup:INFO: database=mysqlallback:backup:INFO: backup-mode=logicalallback:backup:INFO: password=******allback:backup:INFO: backup-type=regularallback:backup:INFO: compress=allback:backup:INFO: user=bakuserallback:backup:INFO: }allback:backup:INFO: Getting mysql variablesallback:backup:INFO: mysqladmin --user="bakuser" --password="*****" variablesallback:backup:INFO: datadir is /var/lib/mysql/allback:backup:INFO: mysql_version is 5.1.67allback:backup:WARNING: Binary logging isoff.allback:backup:INFO: InnoDB data file are /var/lib/mysql/ibdata1allback:backup:INFO: InnoDB log dir is /var/lib/mysql/.allback:backup:INFO: backup set being used is allbackallback:backup:INFO: backup-set=allbackallback:backup:INFO: backup-date=20130409114623allback:backup:INFO: mysql-server-os=Linux/Unixallback:backup:INFO: backup-type=regularallback:backup:INFO: host=localhostallback:backup:INFO: backup-date-epoch=1365479183allback:backup:INFO: retention-policy=10dallback:backup:INFO: mysql-zrm-version=ZRM for MySQL Community Edition - version 2.2.0allback:backup:INFO: mysql-version=5.1.67allback:backup:INFO: backup-directory=/var/lib/mysql-zrm/allback/20130409114623allback:backup:INFO: backup-level=0allback:backup:INFO: backup-mode=logicalallback:backup:INFO: PHASE END: Initializationallback:backup:INFO: PHASE START: Running pre backup pluginallback:backup:INFO: Executing pre-backup-pluginallback:backup:INFO: PHASE END: Running pre backup pluginallback:backup:INFO: PHASE START: Flushing logsallback:backup:INFO: Flushing the logs allback:backup:INFO: mysqladmin --user="bakuser" --password="*****" flush-logsallback:backup:INFO: Getting master logname using command mysql --user="bakuser" --password="*****" -e "show master status"allback:backup:INFO: PHASE END: Flushing logsallback:backup:INFO: PHASE START: Creating logical backupallback:backup:INFO: Command used for logical backup is mysqldump --opt --extended-insert --create-options --default-character-set=utf8 --single-transaction --user="bakuser" --password="*****" --databases mysql > "/var/lib/mysql-zrm/allback/20130409114623/backup.sql"allback:backup:INFO: Logical backup done for the following database(s) mysqlallback:backup:INFO: logical-databases=mysqlallback:backup:INFO: PHASE END: Creating logical backupallback:backup:INFO: PHASE START: Calculating backup size & checksums allback:backup:INFO: last-backup=/var/lib/mysql-zrm/allback/20130409114504allback:backup:INFO: backup-size=0.49 MBallback:backup:INFO: PHASE END: Calculating backup size & checksums allback:backup:INFO: PHASE START: Compression/Encryptionallback:backup:INFO: Compressing backupallback:backup:INFO: Command used is'tar --same-owner -cpsC "/var/lib/mysql-zrm/allback/20130409114623" --exclude=backup-data --exclude=index --exclude=zrm_checksum --exclude=backup-sql . 2>/tmp/d0eGQFOkxK | gzip 2>/tmp/_1ZpeCz2Zb > "/var/lib/mysql-zrm/allback/20130409114623/backup-data" 2>/tmp/xlHpCvh85c'allback:backup:INFO: compress=allback:backup:INFO: backup-size-compressed=0.13 MBallback:backup:INFO: Removing allof the uncompressed/unencrypted dataallback:backup:INFO: PHASE END: Compression/Encryptionallback:backup:INFO: read-locks-time=00:00:00allback:backup:INFO: flush-logs-time=00:00:00allback:backup:INFO: compress-encrypt-time=00:00:00allback:backup:INFO: backup-time=00:00:00allback:backup:INFO: backup-status=Backup succeededallback:backup:INFO: Backup succeededallback:backup:INFO: PHASE START: Running post backup pluginallback:backup:INFO: Executing post-backup-pluginallback:backup:INFO: PHASE END: Running post backup pluginallback:backup:INFO: PHASE START: Mailing backup reportallback:backup:INFO: mailing file /tmp/Mku7oEFC3Ballback:backup:INFO: mail command is cat "/tmp/Mku7oEFC3B"|mail -s "[ZRM for MySQL Report] backup-set allback" [email protected]:backup:INFO: PHASE END: Mailing backup reportallback:backup:INFO: PHASE START: Cleanupallback:backup:INFO: PHASE END: Cleanupallback:backup:INFO: ENDOF BACKUP
检查备份情况:
邮件信息:
[root@localhost mysql-zrm]# mailBackup set=allbackrunBackup date=Tue Apr 9 11:41:51 2013Backup level=0Logical Databases=mysqlBackup size=0.49 MBBackup time=00:00:01Backup status=Backup succeeded
备份信息:
[root@localhost mysql-zrm]# mysql-zrm-reporter --where backup-set=allback --show backup-status-inforeporter:WARNING: Backup root directory not specified, Assigning default value as /var/lib/mysql-zrm REPORT TYPE : backup-status-info backup_set backup_date backup_level backup_status backup_type comment----------------------------------------------------------------------------------------------------------------------------- allback Tue 09 Apr 2013 11:46:23 0 Backup succeeded regular ---- AM CST allback Tue 09 Apr 2013 11:45:04 0 Backup succeeded regular ---- AM CST
备份参数结果:
[root@localhost mysql-zrm]# mysql-zrm-reporter --where backup-set=allback --show backup-performance-inforeporter:WARNING: Backup root directory not specified, Assigning default value as /var/lib/mysql-zrm REPORT TYPE : backup-performance-info backup_set backup_date backup_level backup_size backup_size_compressed backup_time backup_type compress_encrypt_time---------------------------------------------------------------------------------------------------------------------------------------------------------------- allback Tue 09 Apr 2013 11:46:23 0 0.49 MB 0.13 MB 00:00:00 regular 00:00:00 AM CST allback Tue 09 Apr 2013 11:45:04 0 0.49 MB 0.13 MB 00:00:00 regular 00:00:00 AM CST
最后我们去默认的备份路径/var/lib/mysql-zrm/allback/里面看下备份信息。/var/log/mysql-zrm/下面有日志
####注意备份文件夹是按照备份的时间命名的。
[root@localhost allback]# lltotal 12drwx------ 2 root root 4096 Apr 9 15:41 20130409154138drwx------ 2 root root 4096 Apr 9 15:42 20130409154252drwx------ 2 root root 4096 Apr 9 15:49 20130409154830[root@localhost allback]# ll 20130409154138 total 144-rw-r--r-- 1 root root 138338 Apr 9 15:41 backup-data-rw-r--r-- 1 root root 537 Apr 9 15:41 index-rw-r--r-- 1 root root 146 Apr 9 15:41 zrm_checksum## 注意: 每个备份的目录的下面有三个文件
七 测试一个增量备份:
首先需要开启mysql的binlog日志 在my.cnf增加:log-bin=binlog 重启数据库
[root@localhost mysql-zrm]# mysql-zrm --action backup --backup-set zengliang_back --backup-level 1####中间输出省略,只要并出现error基本成功,不保险的话就查看下备份文件即可[root@localhost mysql-zrm]# lltotal 16drwx------ 5 root root 4096 Apr 9 15:48 allbackdrwx------ 4 root root 4096 Apr 9 15:33 mysqldrwx------ 3 root root 4096 Apr 9 15:45 ytt_inc2drwx------ 3 root root 4096 Apr 9 16:11 zengliang_back[root@localhost mysql-zrm]# ll zengliang_back/total 4drwx------ 2 root root 4096 Apr 9 16:11 20130409161118[root@localhost mysql-zrm]# ll zengliang_back/20130409161118/total 12-rw-r--r-- 1 root root 445 Apr 9 16:11 backup-data-rw-r--r-- 1 root root 583 Apr 9 16:11 index-rw-r--r-- 1 root root 160 Apr 9 16:11 zrm_checksum
八 这就完成了全局和增量备份的操作了,大家可以测试下恢复在原有的数据库mysql上做一个全局备份,然后新建一个表t_table,做一个增量备份。然后把mysql删除。最后先全局---增量做恢复
全局恢复:mysql-zrm --action restore --backup-set mysql --source-directory /var/lib/mysql-zrm/allback/20130409150029/增量恢复:mysql-zrm --action restore --backup-set zengliang_back --source-directory /var/lib/mysql-zrm/zengliang_back/20130409161629/