Using ZRM备份mysql数据库

   ZRM是Zmanda Recovery Manager的缩写,这是一款备份mysql的开源软件。其官方网站是:http://www.zmanda.com。以下是如何安装、配置ZRM for mysql以及如何备份恢复mysql的.

1、获取ZRM:

最后的稳定版本是2.2如图所示:

image

这里使用的rpm包,下载客户端和服务器端软件包。在mysql数据库服务器端安装以上两个软件包:

image

检验ZRM的安装:

image

image

2、ZRM for mysql的配置:

这里mysql的服务器端和客户端以及ZRM的服务器端和客户端都在同一台机器上面。

(1)使用之前创建一个用于备份的用户:

创建一个用于备份mysql的用户并设置密码,这里备份mysql的用户是bakuser,密码是redhat.

image

查看bakuser有那些权限:

image

(2)、配置zrm for msyql:

这里直接使用mysql自带的数据库mysql。

image

image

以root用户登录系统,配置一个每天进行全备份的日程,/etc/mysql-zrm下创建一个备份集(dailyrun),存放每天全备份的配置文件,作如下修改:image

去掉backup-level=0前面的注释符号。意思为进行全备份挥着级别为0的备份。

image

备份方式使用逻辑备份。

image

保留策略是10天。

image

备份时使用压缩备份。

image

如果要备份所有的数据库,则使用all-databases-1选项,如果要备份某一个数据库,则使用databases=参数指定要备份的数据库。这里只备份mysql数据库。

image

指定备份用户的用户名以及密码。

image

备份的日志使用详细信息。

image

备份完成后将结果发送至指定邮箱。

image 

3、执行备份测试:

以root身份执行以下命令:

image

以下是备份的输出信息:

schedule:INFO: ZRM for MySQL Community Edition - version 2.2.0
Logging to /var/log/mysql-zrm/mysql-zrm-scheduler.log
backup:INFO: ZRM for MySQL Community Edition - version 2.2.0
dailyrun:backup:INFO: START OF BACKUP
dailyrun:backup:INFO: PHASE START: Initialization
dailyrun:backup:INFO: The quick backup-type is supported only for snapshot backups. Setting backup-type to 'regular'
dailyrun:backup:INFO: Mail address: [email protected] is ok
dailyrun:backup:INFO: ZRM Temporary configuration file = /etc/mysql-zrm/dailyrun/tmpYxvi8.conf
dailyrun:backup:INFO: {
dailyrun:backup:INFO:   quiet=0
dailyrun:backup:INFO:   verbose=1
dailyrun:backup:INFO:   retention-policy=10D
dailyrun:backup:INFO:   backup-level=0
dailyrun:backup:INFO:   [email protected]
dailyrun:backup:INFO:   databases=mysql
dailyrun:backup:INFO:   mail-policy=always
dailyrun:backup:INFO:   backup-mode=logical
dailyrun:backup:INFO:   password=******
dailyrun:backup:INFO:   backup-type=regular
dailyrun:backup:INFO:   compress=
dailyrun:backup:INFO:   user=bakuser
dailyrun:backup:INFO: }
dailyrun:backup:INFO: Getting mysql variables
dailyrun:backup:INFO: mysqladmin --user="bakuser" --password="*****" variables
dailyrun:backup:INFO: datadir is /var/lib/mysql/
dailyrun:backup:INFO: mysql_version is 5.1.48
dailyrun:backup:WARNING: Binary logging is off.
dailyrun:backup:INFO: InnoDB data file are /var/lib/mysql/ibdata1
dailyrun:backup:INFO: InnoDB log dir is /var/lib/mysql/.
dailyrun:backup:INFO: backup set being used is dailyrun
dailyrun:backup:INFO: backup-set=dailyrun
dailyrun:backup:INFO: backup-date=20101010135809
dailyrun:backup:INFO: mysql-server-os=Linux/Unix
dailyrun:backup:INFO: backup-type=regular
dailyrun:backup:INFO: host=localhost
dailyrun:backup:INFO: backup-date-epoch=1286690289
dailyrun:backup:INFO: retention-policy=10D
dailyrun:backup:INFO: mysql-zrm-version=ZRM for MySQL Community Edition - version 2.2.0
dailyrun:backup:INFO: mysql-version=5.1.48
dailyrun:backup:INFO: backup-directory=/var/lib/mysql-zrm/dailyrun/20101010135809
dailyrun:backup:INFO: backup-level=0
dailyrun:backup:INFO: backup-mode=logical
dailyrun:backup:INFO: PHASE END: Initialization
dailyrun:backup:INFO: PHASE START: Running pre backup plugin
dailyrun:backup:INFO: Executing pre-backup-plugin
dailyrun:backup:INFO: PHASE END: Running pre backup plugin
dailyrun:backup:INFO: PHASE START: Flushing logs
dailyrun:backup:INFO: Flushing the logs
dailyrun:backup:INFO: mysqladmin --user="bakuser" --password="*****" flush-logs
dailyrun:backup:INFO: Getting master logname using command mysql --user="bakuser" --password="*****" -e "show master status"
dailyrun:backup:INFO: PHASE END: Flushing logs
dailyrun:backup:INFO: PHASE START: Creating logical backup
dailyrun: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/dailyrun/20101010135809/backup.sql"
dailyrun:backup:INFO: Logical backup done for the following database(s)
        mysql
dailyrun:backup:INFO: logical-databases=mysql
dailyrun:backup:INFO: PHASE END: Creating logical backup
dailyrun:backup:INFO: PHASE START: Calculating backup size & checksums
dailyrun:backup:INFO: backup-size=0.47 MB
dailyrun:backup:INFO: PHASE END: Calculating backup size & checksums
dailyrun:backup:INFO: PHASE START: Compression/Encryption
dailyrun:backup:INFO: Compressing  backup
dailyrun:backup:INFO: Command used is 'tar  --same-owner -cpsC  "/var/lib/mysql-zrm/dailyrun/20101010135809"  --exclude=backup-data  --ex
clude=index  --exclude=zrm_checksum  --exclude=backup-sql . 2>/tmp/slrsrptlAY  | gzip 2>/tmp/diPexWcHTB > "/var/lib/mysql-zrm/dailyrun/20
101010135809/backup-data" 2>/tmp/xwFUB6zbuC'
dailyrun:backup:INFO: compress=
dailyrun:backup:INFO: backup-size-compressed=0.13 MB
dailyrun:backup:INFO: Removing all of the uncompressed/unencrypted data
dailyrun:backup:INFO: PHASE END: Compression/Encryption
dailyrun:backup:INFO: read-locks-time=00:00:00
dailyrun:backup:INFO: flush-logs-time=00:00:00
dailyrun:backup:INFO: compress-encrypt-time=00:00:00
dailyrun:backup:INFO: backup-time=00:00:01
dailyrun:backup:INFO: backup-status=Backup succeeded
dailyrun:backup:INFO: Backup succeeded
dailyrun:backup:INFO: PHASE START: Running post backup plugin
dailyrun:backup:INFO: Executing post-backup-plugin
dailyrun:backup:INFO: PHASE END: Running post backup plugin
dailyrun:backup:INFO: PHASE START: Mailing backup report
dailyrun:backup:INFO: mailing file /tmp/gGcntWwZSq
dailyrun:backup:INFO: mail command is cat "/tmp/gGcntWwZSq"|mail -s "[ZRM for MySQL Report] backup-set dailyrun" [email protected]
dailyrun:backup:INFO: PHASE END: Mailing backup report
dailyrun:backup:INFO: PHASE START: Cleanup
dailyrun:backup:INFO: PHASE END: Cleanup
dailyrun:backup:INFO: END OF BACKUP
/usr/bin/mysql-zrm started successfully

完了之后,会发邮件到指定的邮箱,邮件内容如下所示:

image 

指定每日备份的开始时间:

image

检验备份日程:

image

查看备份状态信息:

image

备份的默认保存目录是/var/lib/mysql-zrm,也可以在配置文件修改默认的保存目录。

查看备份结果信息:

image

检验备份的结果:

image

4、进行恢复测试:

将mysql数据库删除掉,然后进行恢复测试:

image

以成功删除了mysql数据库。

(1)、确定要从哪一个备份恢复:

 

 

(2)、从最后一个全备份恢复:

恢复完成后,检查时候恢复成功:

image

OK,恢复成功哦!!!

本文出自 “candon123” 博客,谢绝转载!

你可能感兴趣的:(数据库,mysql,using,休闲,ZRM)