diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2017-12-31 13:35:15 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2017-12-31 13:35:15 -0200 |
commit | ac369edea092ef40dcf021f3a6baabd63413ca2c (patch) | |
tree | 13b990ec106da4c202df5238d17940c39924dadd | |
parent | 0fd5bcd6ebb162ea3efce7d3bfd3c013157bc717 (diff) | |
download | kvmx-ac369edea092ef40dcf021f3a6baabd63413ca2c.tar.gz kvmx-ac369edea092ef40dcf021f3a6baabd63413ca2c.tar.bz2 |
Adds compress action
-rwxr-xr-x | kvmx | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -1559,6 +1559,38 @@ function kvmx_serial { kvmx_console $* } +# Compress guest image +function kvmx_compress { + if kvmx_running; then + echo "$BASENAME: guest $VM is running" + exit 1 + fi + + # Avoid trying to convert guest using other images such as LVM volumes + if [ "$format" != "qcow2" ]; then + echo "$BASENAME: please convert guest $VM image to qcow2 and update your config" + exit 1 + fi + + # Size before compression + local size_before_bytes="`du $image | awk '{ print $1 }'`" + local size_before_human="`du -h $image | awk '{ print $1 }'`" + + qemu-img convert -O qcow2 -p -c $image $image.new && mv $image.new $image || exit 1 + + # Size after compression + local size_after_bytes="`du $image | awk '{ print $1 }'`" + local size_after_human="`du -h $image | awk '{ print $1 }'`" + + # Ratio + #local ratio="$(($size_after_bytes / $size_before_bytes))" + local ratio="$(echo "scale=4 ; $size_after_bytes / $size_before_bytes" | bc -l)" + + echo "size before: $size_before_human" + echo "size_after: $size_after_human" + echo "compression ratio: $ratio" +} + # Dispatch if type kvmx_$ACTION 2> /dev/null | grep -q "kvmx_$ACTION ()"; then __kvmx_initialize $* |