参考文档 

 http://blog.chinaunix.net/uid-20639775-id-1617795.html


 http://xxtianxiaxing.iteye.com/blog/563063


 http://dev.mysql.com/doc/refman/5.0/en/mysql-cluster-single-user-mode.html


 http://www.mysqlab.net/knowledge/kb/detail/topic/backup/id/8309

 http://blog.csdn.net/mchdba/article/details/10544585 的第八小节里面进行扩展测试

8.1 sql节点上面录入数据:

 建立测试的数据库和表

CREATE DATABASE bg;

CREATE TABLE bgt1 (id INT,`name` VARCHAR(20),PRIMARY KEY(`id`))ENGINE=NDBCLUSTER;

INSERT INTO bgt1 VALUES(1,'zhang1'),(2,'zhang2'),(3,'zhang3'),(4,'zhang4');

 8.2 管理节点上面,开始备份

ndb_mgm> start backup


Waiting for completed, this may take several minutes


Node 4: Backup 1 started from node 1


Node 4: Backup 1 started from node 1 completed


StartGCP: 184725 StopGCP: 184772


#Records: 722078 #LogRecords: 0


Data: 287345616 bytes Log: 0 bytes


ndb_mgm>


 8.3 再次插入几条数据(为了保持和正式环境尽可能接近,在插入数据中间穿插了flush logs操作!)

INSERT INTO bgt1 VALUES(5,'zhang5'),(6,'zhang6'); 


flush logs;


INSERT INTO bgt1 VALUES(7,'zhang7'),(8,'zhang8');

     


8.4 删掉SQL节点的数据。

mysql> drop database bg;

Query OK, 2 rows affected (6.16 sec)

8.5 关闭MYSQLD服务器。

[root@banggo data]# /etc/rc.d/init.d/mysqld stop


Shutting down MySQL......120718 18:58:11 mysqld_safe mysqld from pid file /usr/local/mysql/data/banggo.local.pid ended


  [确定]


[1]+  Done                    /usr/local/mysql/bin/mysqld_safe


[root@banggo data]# 


[root@banggo data]# /etc/rc.d/init.d/mysqld stop


Shutting down MySQL....                                    [确定]


[root@banggo data]#

8.6 重新启动节点

ndb_mgm> shutdown


Node 4: Cluster shutdown initiated


Node 4: Node shutdown completed.


2 NDB Cluster node(s) have shutdown.


Disconnecting to allow management server to shutdown.


ndb_mgm> exit


[root@banggo mysql-cluster]# ndb_mgmd -f /usr/local/mysql/cluster-conf/config.ini --reload


MySQL Cluster Management Server mysql-5.5.19 ndb-7.2.4

8.7 重新启动数据节点

ndbd --initial

8.8 在数据节点上面进行恢复。

/home/mysql-cluster-gpl-7.2.4-linux2.6-x86_64/bin/ndb_restore -e  -c 10.100.200.36 -n 4 -b 1 -m --backup_path=/var/lib/mysql-cluster/BACKUP/BACKUP-1/

其中backup_path 在默认的数据节点的根目录下面(找了很久,一开始以为在配置文件里面)

第一步骤 -m操作
   [root@test-db-20053 BACKUP-1]# /home/mysql-cluster-gpl-7.2.4-linux2.6-x86_64/bin/ndb_restore -e  -c 10.100.200.36 -n 4 -b 1 -m --backup_path=/var/lib/mysql-cluster/BACKUP/BACKUP-1/


Nodeid = 4


Backup Id = 1


backup path = /var/lib/mysql-cluster/BACKUP/BACKUP-1/


Opening file '/var/lib/mysql-cluster/BACKUP/BACKUP-1/BACKUP-1.4.ctl'


File size 61160 bytes


Backup version in files: ndb-6.3.11 ndb version: mysql-5.5.19 ndb-7.2.4


Stop GCP of Backup: 184771


Connected to ndb!!


Successfully restored table `test/def/t2`


Successfully restored table event REPL$test/t2


Successfully restored table `bg/def/#sql-303d_2`


Successfully restored table event REPL$bg/#sql-303d_2


Successfully restored table `bg/def/#sql-51f0_3`


Successfully restored table event REPL$bg/#sql-51f0_3


Successfully restored table `test/def/t11`


Successfully restored table event REPL$test/t11


Successfully restored table `ndb/def/ndborder_goods`


Successfully restored table event REPL$ndb/ndborder_goods


Successfully restored table `bg/def/bgt1`


Successfully restored table event REPL$bg/bgt1


Successfully restored table `test/def/ndborder_info_history`


Successfully restored table event REPL$test/ndborder_info_history


Successfully restored table `mysql/def/ndb_schema`


Successfully restored table event REPL$mysql/ndb_schema


Successfully restored table `mysql/def/ndb_apply_status`


Successfully restored table event REPL$mysql/ndb_apply_status


Successfully restored table `ndb/def/ndbtest`


Successfully restored table event REPL$ndb/ndbtest


Successfully created index `PRIMARY` on `ndborder_info_history`


Successfully created index `uniq_order_os` on `ndborder_goods`


Successfully created index `is_update` on `ndborder_info_history`


Successfully created index `PRIMARY` on `#sql-51f0_3`


Successfully created index `sku_sn` on `ndborder_goods`


Successfully created index `PRIMARY` on `bgt1`


Successfully created index `exchange_from` on `ndborder_goods`


Successfully created index `addtime` on `ndborder_info_history`


Successfully created index `relating_return_sn` on `ndborder_info_history`


Successfully created index `PRIMARY` on `ndborder_goods`


Successfully created index `order_from` on `ndborder_info_history`


Successfully created index `order_out_sn` on `ndborder_info_history`


Successfully created index `PRIMARY` on `#sql-303d_2`


Successfully created index `order_status` on `ndborder_info_history`


Successfully created index `user_id` on `ndborder_info_history`


Successfully created index `uniq_order_os$unique` on `ndborder_goods`


Successfully created index `order_sn` on `ndborder_goods`

NDBT_ProgramExit: 0 - OK

[root@test-db-20053 BACKUP-1]# 


8.9 第二步骤 -r操作(如果有N个node,则需要执行N次)

[root@test-db-20053 BACKUP-1]# /home/mysql-cluster-gpl-7.2.4-linux2.6-x86_64/bin/ndb_restore -e  -c 10.100.200.36 -n 4 -b 1 -r --backup_path=/var/lib/mysql-cluster/BACKUP/BACKUP-1/


Nodeid = 4


Backup Id = 1


backup path = /var/lib/mysql-cluster/BACKUP/BACKUP-1/


Opening file '/var/lib/mysql-cluster/BACKUP/BACKUP-1/BACKUP-1.4.ctl'


File size 61160 bytes


Backup version in files: ndb-6.3.11 ndb version: mysql-5.5.19 ndb-7.2.4


Stop GCP of Backup: 184771


Connected to ndb!!


Opening file '/var/lib/mysql-cluster/BACKUP/BACKUP-1/BACKUP-1-0.4.Data'


File size 287834112 bytes


_____________________________________________________


Processing data in table: test/def/t2(20) fragment 0


_____________________________________________________


Processing data in table: bg/def/#sql-303d_2(34) fragment 0


_____________________________________________________


Processing data in table: bg/def/#sql-51f0_3(32) fragment 0


_____________________________________________________


Processing data in table: mysql/def/NDB$BLOB_7_3(8) fragment 0


_____________________________________________________


Processing data in table: test/def/t11(11) fragment 0


_____________________________________________________


Processing data in table: ndb/def/ndborder_goods(12) fragment 0


_____________________________________________________


Processing data in table: ndb/def/NDB$BLOB_12_13(13) fragment 0


_____________________________________________________


Processing data in table: mysql/def/ndb_index_stat_head(4) fragment 0


_____________________________________________________


Processing data in table: sys/def/NDB$EVENTS_0(3) fragment 0


_____________________________________________________


Processing data in table: sys/def/SYSTAB_0(2) fragment 0


_____________________________________________________


Processing data in table: mysql/def/ndb_index_stat_sample(5) fragment 0


_____________________________________________________


Processing data in table: bg/def/bgt1(36) fragment 0


_____________________________________________________


Processing data in table: test/def/ndborder_info_history(21) fragment 0


Temporary error: 1220: REDO log files overloaded (increase FragmentLogFileSize)


Temporary error: 1220: REDO log files overloaded (increase FragmentLogFileSize)


Temporary error: 1220: REDO log files overloaded (increase FragmentLogFileSize)


Temporary error: 1220: REDO log files overloaded (increase FragmentLogFileSize)


Temporary error: 1220: REDO log files overloaded (increase FragmentLogFileSize)


Temporary error: 1220: REDO log files overloaded (increase FragmentLogFileSize)


Temporary error: 1220: REDO log files overloaded (increase FragmentLogFileSize)


Temporary error: 1220: REDO log files overloaded (increase FragmentLogFileSize)


Temporary error: 1220: REDO log files overloaded (increase FragmentLogFileSize)


Temporary error: 1220: REDO log files overloaded (increase FragmentLogFileSize)


在执行 -r操作的时候 报错

【ok】飞鸿大哥说是由于REDO log 文件太小了要加大,不影响恢复效果。参考了http://bugs.mysql.com/bug.php?id=19651 这上面的人也这么讲。

mysql> show databases;


+--------------------+


| Database           |


+--------------------+


| information_schema |


| mysql              |


| ndb                |


| ndbinfo            |


| performance_schema |


| test               |


+--------------------+


6 rows in set (0.00 sec)


-- 没有库?看来要重建了

mysql> create database bg; -- 重建


Query OK, 1 row affected (0.06 sec)

mysql> use bg


Database changed


mysql> show tables; -- ok,看下表


+--------------+


| Tables_in_bg |


+--------------+


| bgt1         |


+--------------+


1 row in set (0.00 sec)

mysql> select * from bgt1; --数据恢复过来了


+----+--------+


| id | name   |


+----+--------+


|  3 | zhang3 |


|  1 | zhang1 |


|  2 | zhang2 |


|  4 | zhang4 |


+----+--------+


4 rows in set (0.01 sec)

8.10 找一个mysqld节点,在管理节点进入单用户模式,然后启动sql节点,启动该mysqld节点,并登陆找到最大的epoch的值

ndb_mgm> ENTER SINGLE USER MODE 10;


Single user mode entered


Access is granted for API node 10 only.


ndb_mgm>

mysql> SELECT @LASTEPOCH:=MAX(epoch) FROM mysql.ndb_apply_status;


+------------------------+


| @LASTEPOCH:=MAX(epoch) |


+------------------------+


|        793593992183807 |


+------------------------+


1 row in set (0.04 sec)

根据epoch的值,找到二进制日志的位置以及文件名

mysql> SELECT POSITION, @FIRSTFILE:=FILE


-> 


-> FROM mysql.ndb_binlog_index


-> 


-> WHERE epoch > @LASTEPOCH


-> 


-> ORDER BY epoch ASC


-> 


-> LIMIT 1;


Empty set (0.03 sec)

8.11 根据时间点恢复

找出恢复的时候需要用到的除第一个日志文件以外的其他的二进制日志文件


SELECT DISTINCT File 


FROM mysql.ndb_binlog_index


WHERE epoch > @LASTEPOCH 


AND File <> @FIRSTFILE 


ORDER BY File;

然后进行二进制日志的恢复:


mysqlbinlog -H --set-charset="utf8" -D --start-position=829 ./mysql-bin.000012 | grep -v "RELOAD DATABASE" |mysql bg


mysqlbinlog -H --set-charset="utf8" -D --stop-datetime="2012-07-18 13:30:00" ./mysql-bin.0000013 | grep -v "RELOAD DATABASE" |mysql  bg

恢复完成后,退出单用户模式,并启动另外一个sql节点


ndb_mgm> EXIT SINGLE USER MODE;


Exiting single user mode in progress.


Use ALL STATUS or SHOW to see when single user mode has been exited.


ndb_mgm>

进入mysql节点,查到数据已经恢复了。

MySQL Cluster-备份恢复初步测试的更多相关文章

  1. Xtrabackup原理及使用innobackupex进行MySQL数据库备份恢复

    Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备的工具. Xtrabackup中主要包含两个工 ...

  2. MySQL用户管理、常用sql语句、MySQL数据库备份恢复

    1.MySQL用户管理 给远程登陆用户授权:grant all on *.* to 'user1'@'127.0.0.1' identified by '123456' (这里的127.0.0.1是指 ...

  3. Linux centosVMware mysql用户管理、常用sql语句、mysql数据库备份恢复

    一.mysql用户管理 grant all on *.* to 'user1'@‘127.0.0.1’ identified by 'mimA123'; 创建user1用户 使用user1登录 /us ...

  4. postgresql 和 mysql 数据库备份恢复以及时区问题

    概要 postgesql 12 备份/恢复脚本 时区设置 mysql 5.6 备份/恢复脚本 时区设置 概要 postgresql 和 mysql 是最常用的 2 种开源关系数据库, 很多项目也会优先 ...

  5. mysql xtrabackup 备份恢复实现,mysql命令备份数据库,打包压缩数据库

    简介 Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备的工具.特点: (1)备份过程快速.可靠 ...

  6. mysql数据库备份/恢复

    备份数据库(进入Mysql bin目录下/C:\Program Files\MySQL\MySQL Server 5.6\bin)本地安装mysql数据库 备份表结构及数据 mysqldump -hl ...

  7. mysql物理备份恢复 xtrabackup 初试

    听闻xtrabackup开源且强大 2018-03-06 11:54:41 在官网下载安装了最新的2.4.9版本 网上文章都用的innobackupex,但是最新版已经抛弃了,自己看看手册<Pe ...

  8. 【转】mysql增量备份恢复实战企业案例

    来源地址:http://seanlook.com/2014/12/05/mysql_incremental_backup_example/ 小量的数据库可以每天进行完整备份,因为这也用不了多少时间,但 ...

  9. mysql的备份恢复等操作

    备份数据库 shell> mysqldump -h host -u root -p dbname >dbname_backup.sql 恢复数据库 shell> mysqladmin ...

随机推荐

  1. Android应用开发基础篇(1)-----Button

    Android应用开发基础篇(1)-----Button   一.概述        Button,顾名思义就是按钮的意思,它主要的功能是响应用户按下按钮时的动作. 二.应用      新建一个工程, ...

  2. android 围绕中心旋转动画

    本文主要介绍Android中如何使用rotate实现图片不停旋转的效果.Android 平台提供了两类动画,一类是 Tween 动画,即通过对场景里的对象不断做图像变换(平移.缩放.旋转)产生动画效果 ...

  3. Nhibernate初入门基本配置(二)

    转载地址http://www.cnblogs.com/kissdodog/p/3306428.html 使用NHibernate最重要的一步就是配置,如果连NHibernate都还没有跑的起来,谈何学 ...

  4. Ajax+asp.net实现用户登陆 转自http://www.shangxueba.com/jingyan/2933319.html

    这篇文章主要介绍了Ajax+asp.net实现用户登陆,主要是为了练习ajax的使用方法,有需要的小伙伴参考下. 以用户登录为例练习ajax的使用方法 login.html <!DOCTYPE ...

  5. hough变换是如何检测出直线和圆的?

    (I)直线篇 1 直线是如何表示的?对于平面中的一条直线,在笛卡尔坐标系中,常见的有点斜式,两点式两种表示方法.然而在hough变换中,考虑的是另外一种表示方式:使用(r,theta)来表示一条直线. ...

  6. myeclipse 配置weblogic 异常

    java.lang.UnsupportedClassVersionError: Bad version number in .class file当前JDK与weblogic版本不匹配.

  7. ButterKnife 绑定 RadioGroup

    原则上 ButterKnife 是不支持 RadioGroup 的, 可以通过以下方法添加RadioButton的点击事件: @OnClick({ R.id.radio_btn1, R.id.radi ...

  8. MyEclipse 在loading workbench 启动卡死

    解决方法: 找到Workspace目录,在.metadata(Mac 下是在 .metadata/.plugins)中删掉以下两个文件 org.eclipse.ui.workbench org.ecl ...

  9. linxu添加定时任务

    1. 在需要定时执行的php文件的第一行加 也就是文件开头加  #! /bin/local/php -q 其中 /bin/local/php 是自己的php.exe 所在的位置 2. 上传要定时执行的 ...

  10. synchronized和vilatile

    第一个程序 public class Test06 implements Runnable{ public int a = 0; public static void main(String[] ar ...