测试LVM的快照功能
作者:网络转载 发布时间:[ 2015/9/9 14:28:39 ] 推荐标签:软件测试技术
三 测试给lv01建立快照
1、创建快照
[root@tvm-test /]# lvcreate -L 2G -s -n snap_lv01 /dev/vg01/lv01
Logical volume "snap_lv01" created
2、挂载后压缩备份
[root@tvm-test ~]# lv_snap="/dev/vg01/snap_lv01"
&& d_backup='/data/backup/snapshot'
&& f_snap="/data/backup/snapshot/lv01_$(date +%F).tar.gz"
test -d ${d_backup} || mkdir -p ${d_backup}/mnt
&& mount -o ro ${lv_snap} ${d_backup}/mnt
&& cd ${d_backup}
&& tar zcf ${f_snap} mnt/*
&& ls -lh ${f_snap}
&& df -h
-rw-r--r-- 1 root root 438K Jul 31 16:23 /data/backup/snapshot/lv01_2015-07-31.tar.gz
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 3.8G 1.7G 2.0G 46% /
tmpfs 246M 12K 246M 1% /dev/shm
/dev/sda1 194M 29M 155M 16% /boot
/dev/mapper/vg01-lv01 9.9G 590M 8.8G 7% /DATA01
/dev/mapper/vg01-snap_lv01 9.9G 590M 8.8G 7% /data/backup/snapshot/mnt
3、卸载后移除快照
[root@tvm-test /]# umount ${d_backup}/mnt && lvremove -f ${lv_snap}
Logical volume "snap_lv01" successfully removed
4、总结步骤
#1 create 创建快照
#2 mount to tar backup 挂载后压缩备份
#3 umount to remove 卸载后移除快照
(可以写成脚本了)
[root@tvm-test bin]# cat lvm_test_snapshot.sh
#!/bin/bash
#
# 2015/7/31
n_size='2G'
f_vg='vg01'
f_orin='lv01'
f_snap='snap_lv01'
lv_orig="/dev/${f_vg}/${f_orig}"
lv_snap="/dev/${f_vg}/${f_snap}"
d_backup='/data/backup/snapshot'
f_snap="${d_backup}/${f_orig}_$(date +%F).tar.gz"
#1 create 创建快照
lvcreate -L ${n_size} -s -n ${f_snap} ${lv_orig}
#2 mount to tar backup 挂载后压缩备份
test -d ${d_backup} || mkdir -p ${d_backup}/mnt
&& mount -o remount,ro ${lv_snap} ${d_backup}/mnt
&& df -h
cd ${d_backup}
&& tar zcf ${f_snap} mnt/*
&& ls -lh ${f_snap}
#3 umount to remove 卸载后移除快照
umount ${d_backup}/mnt && lvremove -f ${lv_snap}
四、疑问
Q:建立快照时,要分配多大的size呢?
A:翻一下lvcreate的man,注意-s选项的描述中有这么一段话:
The non thin volume snapshot with the specified size does not need the
same amount of storage the origin has. In a typical scenario, 15-20%
might be enough. In case the snapshot runs out of storage, use lvextend(8)
to grow it. Shrinking a snapshot is supported by lvreduce(8) as well.
Run lvs(8) on the snapshot in order to check how much data is allocated
to it. Note: a small amount of the space you allocate to the snapshot is
used to track the locations of the chunks of data, so you should allocate
slightly more space than you actually need and monitor (--monitor) the rate
at which the snapshot data is growing so you can avoid running out of space.
给snapshot分配20%左右的origin的容量即可。
测试:
[root@tvm-test /]# dd if=/dev/zero of=/DATA01/dir2_3/test3.dd bs=4096 count=200000
200000+0 records in
200000+0 records out
819200000 bytes (819 MB) copied, 1.21615 s, 674 MB/s
[root@tvm-test snapshot]# rm -f /DATA01/dir2_3/test2.dd
[root@tvm-test snapshot]# pwd
/data/backup/snapshot
[root@tvm-test snapshot]# ls
lv01_2015-07-31.tar.gz mnt
[root@tvm-test snapshot]# tar zxvf lv01_2015-07-31.tar.gz
mnt/dir2_1/
mnt/dir2_1/file3.aa
mnt/dir2_1/file3.bb
mnt/dir2_1/file3.cc
mnt/dir2_2/
mnt/dir2_2/file3.aa
mnt/dir2_2/file3.bb
mnt/dir2_2/file3.cc
mnt/dir2_3/
mnt/dir2_3/test2.dd
mnt/dir2_3/test1.dd
mnt/file2_1
mnt/file2_2
mnt/file2_3
mnt/file2_4
mnt/file2_5
[root@tvm-test snapshot]# ls mnt/
dir2_1 dir2_2 dir2_3 file2_1 file2_2 file2_3 file2_4 file2_5
[root@tvm-test snapshot]# ll -h mnt/dir2_3/
total 440M
-rw-r--r-- 1 root root 49M Jul 31 15:35 test1.dd
-rw-r--r-- 1 root root 391M Jul 31 15:36 test2.dd
拷贝到另一台主机:
[root@tvm-test snapshot]# rsync -avzP lv01_2015-07-31.tar.gz 192.168.56.253:/data/testarea
The authenticity of host '192.168.56.253 (192.168.56.253)' can't be established.
RSA key fingerprint is 35:10:6d:25:4e:3d:6f:59:86:87:e3:88:9f:9c:81:a8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.253' (RSA) to the list of known hosts.
root@192.168.56.253's password:
sending incremental file list
lv01_2015-07-31.tar.gz
447649 79.13MB/s 0:00:00 (xfer#1, to-check=0/1)
sent 447890 bytes received 31 bytes 68910.92 bytes/sec
total size is 447649 speedup is 1.00
在另一台主机上操作:
[root@tvm-saltmaster testarea]# ll -h
total 440K
-rw-r--r-- 1 root root 438K Jul 31 16:23 lv01_2015-07-31.tar.gz
[root@tvm-saltmaster testarea]# tar zxvf lv01_2015-07-31.tar.gz
mnt/dir2_1/
mnt/dir2_1/file3.aa
mnt/dir2_1/file3.bb
mnt/dir2_1/file3.cc
mnt/dir2_2/
mnt/dir2_2/file3.aa
mnt/dir2_2/file3.bb
mnt/dir2_2/file3.cc
mnt/dir2_3/
mnt/dir2_3/test2.dd
mnt/dir2_3/test1.dd
mnt/file2_1
mnt/file2_2
mnt/file2_3
mnt/file2_4
mnt/file2_5
[root@tvm-saltmaster testarea]# ls mnt/
dir2_1 dir2_2 dir2_3 file2_1 file2_2 file2_3 file2_4 file2_5
[root@tvm-saltmaster testarea]# ll -h mnt/dir2_3/
total 440M
-rw-r--r-- 1 root root 49M Jul 31 15:35 test1.dd
-rw-r--r-- 1 root root 391M Jul 31 15:36 test2.dd
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11热门文章
常见的移动App Bug??崩溃的测试用例设计如何用Jmeter做压力测试QC使用说明APP压力测试入门教程移动app测试中的主要问题jenkins+testng+ant+webdriver持续集成测试使用JMeter进行HTTP负载测试Selenium 2.0 WebDriver 使用指南