MySQL备份和同步时使用LVM
2007-02-14 10:53:23 来源:WEB开发网6) 拷贝备份数据。通常备份时可以略过慢查询日志和错误日志。也可以略过大部分的二进制日志 -- 然而如果有些slave远远落后于master的话,就必须保留所需的二进制日志了,或者你可以假设这种情况下在slave上从备份上恢复数据也可以忽略掉二进制日志。
7) Unmount filesystem umount /mnt/backup
7) 卸载文件系统:umount /mnt/backup
8) Remove snapshot: lvremove -f /dev/Main/dbbackup
8) 删除快照:lvremove -f /dev/Main/dbbackup
If you want to create slave based on such snapshot you need to perform couple of more simple steps
如果你想创建基于slave的快照,就需要多做2个步骤。
9) Extract/Copy database to the slave database directory.
9) 提取/拷贝数据库到slave的数据库目录下。
10) Start MySQL Server. Wait for it to perform recovery.
10) 启动MySQL服务器,等待执行恢复。
11) Use CHANGE MASTER TO to point slave to saved binary log position:
11) 用 CHANGE MASTER TO 告诉slave要保存的二进制日志位置:
PLAIN TEXT
SQL:
CHANGE
master
TO
master_host="master", master_user="user", master_password="password", master_log_file="host-bin.000335", master_log_pos=401934686;
12) Run SLAVE START to restart replication.
12) 运行 SLAVE START 重启复制。
With slightly modified process you can clone slaves from the slaves without stopping them - you just need to use SHOW SLAVE STATUS instead of SHOW MASTER STATUS to find out appropriate binary log position. Be careful however - cloning slave from the slave also clones inconsistences in data which slave could have accomulated - especially if you use slave_skip_errors or sql_slave_skip_counter. Cloning master you're starting from consistent copy.
使用稍微修改过的进程,就能无需停止slave的情况下克隆它 -- 运行 SHOW SLAVE STATUS 而不是 SHOW MASTER STATUS,找出合适的二进制日志位置。不过要小心 -- 克隆slave的时候也会把它积累的不一致的数据也克隆了 -- 尤其是使用 slave_skip_errors 或 sql_slave_skip_counter时。克隆master就可以拷贝保持一致的数据。
If you're interested in ready script you can try mylvmbackup by Lenz Grimmer
如果你对上面的过程有兴趣,可以试试 Lenz Grimmer 的 mylvmbackup。
更多精彩
赞助商链接