基于LVM快照备份 MySQL数据

本文介绍了如何基于LVM快照技术备份MySQL数据,这种方法能够在不停止服务的情况下进行一致性的数据备份。通过创建快照、锁定数据库、刷新二进制日志,然后释放读锁,可以实现数据备份。LVM快照备份速度快,但存在预留空间限制和数据一致性问题。文章详细讲解了备份和恢复过程,包括快照合并与单独备份快照的区别以及风险提示。
摘要由CSDN通过智能技术生成


基于LVM快照备份 MySQL数据

这是基于linux系统虚拟卷的一种快照技术,这种技术只对LVM有效,也就是说你的系统是基于LVM虚拟卷的。

LVS快照创建特别快,无论数据量大小,机会都是瞬间完成。因为创建的时候,只是创建了一个快照空间而已,并没有数据的拷贝。
当原始卷里的数据有写入时,备份卷开始记录原始卷哪些数据发生了变化,然后在原始卷新数据覆盖旧数据时,将旧数据拷贝到快照的预留空间,
起到备份数据的作用,这就是LVM快照备份,采用写时复制技术(Copy-On-Write,COW),不用停止服务或将逻辑卷设为只读就可以进行备份,
使用LVM快照功能既可以获得一致备份,又不会影响服务器的可用性。

恢复速度非常快。应该是最快的一种备份方案。
逻辑卷是创建在卷组之上的。逻辑卷对应的设备文件保存在卷组目录下,
例如:在卷组"vg1000"上创建一个逻辑卷"lvol0",则此逻辑卷对应的设备文件为"/dev/vg1000/lvol0"。

LVM基本术语:
1)物理存储介质:这里指系统的存储设备:硬盘,如: /dev/hda、/dev/sda等等,是存储系统最低层的存储单元。
2)物理卷physical volume (PV )
物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如 RAID),是 LVM的基本存储逻辑块
3)卷组Volume Group (VG )
LVM卷组由一个或多个物理卷组成,但是更确切的说,它包含由这些物理卷提供的许多PE。
4)逻辑卷logical volume (LV )
这里是我们存储信息的地方,在逻辑卷之上可以建立文件系统 (比如/home或者 /usr等)。
5)PE(physical extent )
每一个物理卷被划分为称为 PE的基本单元,具有唯一编号的 PE是可以被 LVM寻址的最小单元。 PE的大小是可配置的,默认为 4MB。


缺陷:因为COW原因,预留空间有限,也就是说变更过于频繁,变更过大,会导致预留空间被再次覆盖。因此,需要单独备份快照。Linux下不能对LVM,LVS进行错误的操作,这可能导致快照失效,无法恢复。

进行数据库数据备份就必须进行如下2个操作。否则数据会是不一致的,恢复之后可能存在问题。

为了安全 首先在数据库上施加读锁
mysql>FLUSH TABLES WITH READ LOCK;

刷新一下二进制日志,便于做时间点恢复
mysql

Legal Notice Copyright © 2017 Veritas Technologies LLC. All rights reserved. Veritas and the Veritas Logo are trademarks or registered trademarks of Veritas Technologies LLC or its affiliates in the U.S. and other countries. Other names may be trademarks of their respective owners. This product may contain third party software for which Veritas is required to provide attribution to the third party (“Third Party Programs”). Some of the Third Party Programs are available under open source or free software licenses. The License Agreement accompanying the Software does not alter any rights or obligations you may have under those open source or free software licenses. Please see the Third Party Legal Notice Appendix to this Documentation or TPIP ReadMe File accompanying this product for more information on the Third Party Programs. The product described in this document is distributed under licenses restricting its use, copying, distribution, and decompilation/reverse engineering. No part of this document may be reproduced in any form by any means without prior written authorization of Veritas Technologies LLC and its licensors, if any. THE DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. VERITAS TECHNOLOGIES LLC SHALL NOT BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH THE FURNISHING, PERFORMANCE, OR USE OF THIS DOCUMENTATION. THE INFORMATION CONTAINED IN THIS DOCUMENTATION IS SUBJECT TO CHANGE WITHOUT NOTICE. The Licensed Software and Documentation are deemed to be commercial computer software as defined in FAR 12.212 and subject to restricted rights as defined in FAR Section 52.227-19 "Commercial Computer Software - Restricted Rights" and DFARS 227.7202, et seq. "Commercial Computer Software and Commercial Computer Software Documentation," as applicable, and any successor regulations, whether delivered by Veritas as on premises or hosted services. Any use, modification, reproduction release, performance, display or disclosure of the Licensed Software and Documentation by the U.S. Government shall be solely in accordance with the terms of this Agreement.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值