实现流程:
1.给mysql加全局锁
flush tables with read lock;
2.查看pos点
show master status ;或者show slave status;
3.创建快照
lvcreate -L 大小 -s -n 快照名 原lv路径
4.解锁
unlock tables;
5.挂载快照并拷贝快照内容到备份路径
mount cp tar rsync(若文件系统是xfs格式的 需要加上nouuid选项)
6.取消挂载
umount
7.移除快照
remove snapshot
脚本:
#!/bin/bash
dir=/mysqlbackup
password=123456
date=`date +%F`
mkdir -p $dir/$date
echo "flush tables with read lock ; system lvcreate -L 1G -s -n mysql.snapshot /dev/myvg/mysqllv; show master status\G ; unlock tables" | mysql --password=$password &> $dir/$date/position
mount -o ro,nouuid /dev/myvg/mysql.snapshot /mnt
cd /mnt;tar -zcvf $dir/$date/${date}_allback.tar.gz *
cd ; umount /mnt
lvremove /dev/myvg/mysql.snapshot -f