如何确定LVM快照的最佳大小?

我想创build一个在备份过程中使用LVM快照的备份脚本。 这个脚本将在几台Linux机器上运行。 我想避免在备份过程中创build过小的快照。 我只有卷大小,在这个卷上使用和可用空间的百分比作为input参数。 在这个卷上,我没有平均的磁盘I / O速度和数据量的变化。 有没有一种方法可以根据这个条件计算卷的最佳快照大小? 创build快照的可用空间有限。

请记住,您可以随时调整快照大小,例如使用lvextend。 所以你可以给他们一个合理的初始尺寸,然后随着他们变得越来越成熟。

这甚至可以自动完成:使用dmeventd并在lvm.conf中设置:

# 'snapshot_autoextend_threshold' and 'snapshot_autoextend_percent' define # how to handle automatic snapshot extension. The former defines when the # snapshot should be extended: when its space usage exceeds this many # percent. The latter defines how much extra space should be allocated for # the snapshot, in percent of its current size. # # For example, if you set snapshot_autoextend_threshold to 70 and # snapshot_autoextend_percent to 20, whenever a snapshot exceeds 70% usage, # it will be extended by another 20%. For a 1G snapshot, using up 700M will # trigger a resize to 1.2G. When the usage exceeds 840M, the snapshot will # be extended to 1.44G, and so on. # # Setting snapshot_autoextend_threshold to 100 disables automatic # extensions. The minimum value is 50 (A setting below 50 will be treated # as 50). snapshot_autoextend_threshold = 50 snapshot_autoextend_percent = 50 

自动延伸不能即时运行,dmeventd需要花费几秒钟的时间来做出反应……而50%的填充等级和50%的增长是相当苛刻的,但是对于非常小的快照进行testing(从而快速填充数据)是需要的。

 # lvcreate -n TEST_LV -L 1G /dev/base_vg Logical volume "TEST_LV" created # mke2fs -t ext4 /dev/base_vg/TEST_LV mke2fs 1.42.5 (29-Jul-2012) [...] Writing superblocks and filesystem accounting information: done # mount /dev/base_vg/TEST_LV /mnt 

不需要root来写文件

 # cd /mnt # chown USER . # $ for i in 1 2 3 4 5 6 7 8 9 10 11 12 ; do dd if=/dev/urandom bs=1024k count=10 > /mnt/File$i done $ # lvcreate -n TEST_LV-SNAP -s /dev/base_vg/TEST_LV -L 25M Rounding up size to full physical extent 28.00 MiB Logical volume "TEST_LV-SNAP" created # lvs /dev/base_vg/TEST_LV-SNAP; \ while true; do lvs /dev/base_vg/TEST_LV-SNAP | grep -v Origin sleep 1 done | uniq 

这是运行,开始

 $ for i in 1 2 3 4 5 6 7 8 9 10 11 12 ; do dd if=/dev/urandom bs=1024k count=10 > /mnt/File$i sleep 10 done 

写作中的睡眠需要让dmeventd赶上— IIRC它只会每隔10秒检查一次。

回到我们的输出:

  LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert TEST_LV-SNAP base_vg swi-as- 28.00m TEST_LV 0.04 TEST_LV-SNAP base_vg swi-as- 28.00m TEST_LV 0.04 TEST_LV-SNAP base_vg swi-as- 28.00m TEST_LV 35.90 TEST_LV-SNAP base_vg swi-as- 28.00m TEST_LV 36.01 TEST_LV-SNAP base_vg swi-as- 28.00m TEST_LV 71.86 TEST_LV-SNAP base_vg swi-as- 44.00m TEST_LV 45.82 TEST_LV-SNAP base_vg swi-as- 44.00m TEST_LV 68.63 TEST_LV-SNAP base_vg swi-as- 68.00m TEST_LV 44.46 TEST_LV-SNAP base_vg swi-as- 68.00m TEST_LV 59.22 TEST_LV-SNAP base_vg swi-as- 104.00m TEST_LV 38.75 TEST_LV-SNAP base_vg swi-as- 104.00m TEST_LV 48.40 TEST_LV-SNAP base_vg swi-as- 104.00m TEST_LV 48.43 TEST_LV-SNAP base_vg swi-as- 156.00m TEST_LV 38.74 TEST_LV-SNAP base_vg swi-as- 156.00m TEST_LV 45.17 TEST_LV-SNAP base_vg swi-as- 156.00m TEST_LV 45.19 TEST_LV-SNAP base_vg swi-as- 156.00m TEST_LV 51.63 TEST_LV-SNAP base_vg swi-as- 156.00m TEST_LV 51.65 TEST_LV-SNAP base_vg swi-as- 236.00m TEST_LV 34.14 TEST_LV-SNAP base_vg swi-as- 236.00m TEST_LV 38.39 TEST_LV-SNAP base_vg swi-as- 236.00m TEST_LV 38.40 TEST_LV-SNAP base_vg swi-as- 236.00m TEST_LV 42.66 TEST_LV-SNAP base_vg swi-as- 236.00m TEST_LV 42.67 TEST_LV-SNAP base_vg swi-as- 236.00m TEST_LV 46.92 TEST_LV-SNAP base_vg swi-as- 236.00m TEST_LV 46.94 TEST_LV-SNAP base_vg swi-as- 236.00m TEST_LV 51.19 TEST_LV-SNAP base_vg swi-as- 236.00m TEST_LV 51.20 TEST_LV-SNAP base_vg swi-as- 356.00m TEST_LV 33.94 

看着它成长…

不,如果您不知道快照处于活动状态时将写入多less数据,则无法确定“最佳”大小。 这是find合适大小的唯一信息。