【原创】用MySQL-zrm来备份和恢复MySQL数据库
时间:2008-12-10 来源:yueliangdao0608
MySQL ZRM 工具是用PERL写的可以全部和增量备份MySQL数据库的一个强大工具。
还可以做快照,不过我现在没有条件做。等以后有可以做了再补上。
其实具体要说的也没啥,我只是做了点测试。
这里测试的环境是MySQL5.0.x.
系统是单核2G内存.32位的机器.
官方地址:
http://mysqlbackup.zmanda.com/
必须先安装PERL所需组件。
http://mysqlbackup.zmanda.com/index.php/Perl_Installation_Notes
1.先建立备份用户。
mysql> grant lock tables, select, file, reload, super, show view on *.* to backup_user@'localhost' identified by 'backup_user';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
恢复用户我一般直接用ROOT。我觉得这样保险。
如果要增量备份,就开启binlog.
2.安装:
[root@localhost david_yeung]# rpm -ivh MySQL-zrm-2.0-1.noarch.rpm MySQL-zrm-client-2.0-1.noarch.rpm
3.以下是备份过程。
1).用MySQL-zrm来备份。(没有压缩的)(也是利用mysqldump来备份)
[root@localhost mysql-zrm]# time mysql-zrm-backup --backup-set ytt3
...
ytt3:backup:INFO: END OF BACKUP
real 4m9.712s
user 1m51.067s
sys 0m10.563s
2).用mysqldump 来备份。
我来给my.cnf加几个参数:
[mysqldump]
quick
max_allowed_packet = 32M
net_buffer_length=32M
user=backup_user
password=backup_user
socket=/tmp/mysql3307.sock
完了重启MySQLD。
[root@localhost mysql5130]# time mysqldump --defaults-file=/usr/local/mysql5130/my.cnf --databases test t_girl > /home/david_yeung/t.sql
real 4m40.554s
user 2m9.586s
sys 0m10.646s
4.来看看恢复。
先干掉数据库 t_girl 和 test.
[root@localhost mysql5130]# mysql --defaults-file=/usr/local/mysql5130/my.cnf
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 108
Server version: 5.1.30-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| pbxt |
| t_boy |
| t_girl |
| test |
| var |
+--------------------+
7 rows in set (0.03 sec)
mysql> drop database t_girl;
Query OK, 6 rows affected (6.13 sec)
mysql> drop database test;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
1).用mysql-zrm 恢复
[root@localhost 20081209150257]# time mysql-zrm-restore -user=root --password=123456 --backup-set ytt3 --source-directory=/home/david_yeung/mysql-zrm/ytt3/20081209150257/
ytt3:restore:INFO: Restored database(s) from logical backup: test t_girl
ytt3:restore:INFO: Restore done in 1962 seconds.
real 32m42.285s
user 1m30.814s
sys 0m13.755s
2).用自己的mysqldump 来恢复。
先设置set @@global.max_allowed_packet = 34*1024*1024;
[root@localhost david_yeung]# time mysql --defaults-file=/usr/local/mysql5130/my.cnf < /home/david_yeung/t.sql
real 29m8.793s
user 1m8.150s
sys 0m5.224s
5.看看增量备份.
因为之前backup-set 已经全备份过了,所以我们再加一个backup-set来增量备份。
[root@localhost ytt_inc1]# mysql-zrm --action backup --backup-set ytt_inc2 --backup-level 1
如果备份成功,你会收到EMAIL如下:
Backup set=ytt_inc2
Backup date=Wed Dec 10 13:57:58 2008
Backup level=1
Backup size=4.56 GB
Backup time=00:03:29
Backup status=Backup succeeded
用增量备份来恢复的方法跟mysqlbinlog ... | mysql 是一样的。
附加资源:
主要路径简介。
http://mysqlbackup.zmanda.com/index.php/File_Locations
详细的配置参数说明。
http://mysqlbackup.zmanda.com/index.php/Backup_Set_Parameters
关于性能的测试。
http://mysqlbackup.zmanda.com/index.php/Optimizations
关于备份报告。
http://mysqlbackup.zmanda.com/index.php/Pre-defined_Reports
配置文件内容就不用贴了,照着文档的修改就可以了,很简单。
还可以做快照,不过我现在没有条件做。等以后有可以做了再补上。
其实具体要说的也没啥,我只是做了点测试。
这里测试的环境是MySQL5.0.x.
系统是单核2G内存.32位的机器.
官方地址:
http://mysqlbackup.zmanda.com/
必须先安装PERL所需组件。
http://mysqlbackup.zmanda.com/index.php/Perl_Installation_Notes
1.先建立备份用户。
mysql> grant lock tables, select, file, reload, super, show view on *.* to backup_user@'localhost' identified by 'backup_user';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
恢复用户我一般直接用ROOT。我觉得这样保险。
如果要增量备份,就开启binlog.
2.安装:
[root@localhost david_yeung]# rpm -ivh MySQL-zrm-2.0-1.noarch.rpm MySQL-zrm-client-2.0-1.noarch.rpm
3.以下是备份过程。
1).用MySQL-zrm来备份。(没有压缩的)(也是利用mysqldump来备份)
[root@localhost mysql-zrm]# time mysql-zrm-backup --backup-set ytt3
...
ytt3:backup:INFO: END OF BACKUP
real 4m9.712s
user 1m51.067s
sys 0m10.563s
2).用mysqldump 来备份。
我来给my.cnf加几个参数:
[mysqldump]
quick
max_allowed_packet = 32M
net_buffer_length=32M
user=backup_user
password=backup_user
socket=/tmp/mysql3307.sock
完了重启MySQLD。
[root@localhost mysql5130]# time mysqldump --defaults-file=/usr/local/mysql5130/my.cnf --databases test t_girl > /home/david_yeung/t.sql
real 4m40.554s
user 2m9.586s
sys 0m10.646s
4.来看看恢复。
先干掉数据库 t_girl 和 test.
[root@localhost mysql5130]# mysql --defaults-file=/usr/local/mysql5130/my.cnf
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 108
Server version: 5.1.30-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| pbxt |
| t_boy |
| t_girl |
| test |
| var |
+--------------------+
7 rows in set (0.03 sec)
mysql> drop database t_girl;
Query OK, 6 rows affected (6.13 sec)
mysql> drop database test;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
1).用mysql-zrm 恢复
[root@localhost 20081209150257]# time mysql-zrm-restore -user=root --password=123456 --backup-set ytt3 --source-directory=/home/david_yeung/mysql-zrm/ytt3/20081209150257/
ytt3:restore:INFO: Restored database(s) from logical backup: test t_girl
ytt3:restore:INFO: Restore done in 1962 seconds.
real 32m42.285s
user 1m30.814s
sys 0m13.755s
2).用自己的mysqldump 来恢复。
先设置set @@global.max_allowed_packet = 34*1024*1024;
[root@localhost david_yeung]# time mysql --defaults-file=/usr/local/mysql5130/my.cnf < /home/david_yeung/t.sql
real 29m8.793s
user 1m8.150s
sys 0m5.224s
5.看看增量备份.
因为之前backup-set 已经全备份过了,所以我们再加一个backup-set来增量备份。
[root@localhost ytt_inc1]# mysql-zrm --action backup --backup-set ytt_inc2 --backup-level 1
如果备份成功,你会收到EMAIL如下:
Backup set=ytt_inc2
Backup date=Wed Dec 10 13:57:58 2008
Backup level=1
Backup size=4.56 GB
Backup time=00:03:29
Backup status=Backup succeeded
用增量备份来恢复的方法跟mysqlbinlog ... | mysql 是一样的。
附加资源:
主要路径简介。
http://mysqlbackup.zmanda.com/index.php/File_Locations
详细的配置参数说明。
http://mysqlbackup.zmanda.com/index.php/Backup_Set_Parameters
关于性能的测试。
http://mysqlbackup.zmanda.com/index.php/Optimizations
关于备份报告。
http://mysqlbackup.zmanda.com/index.php/Pre-defined_Reports
配置文件内容就不用贴了,照着文档的修改就可以了,很简单。
相关阅读 更多 +