Added gzip compression to snapshots (easy to extend to other compression methods, as well). Issue #1

This commit is contained in:
Morgan Aldridge 2016-12-09 10:04:12 -05:00
parent da41297942
commit 601485558a
1 changed files with 22 additions and 5 deletions

View File

@ -23,6 +23,7 @@ copyright="Copyright (c) 2016 Morgan Aldridge"
# global variables
BASILISKII_BINARY="${BASILISKII_BINARY:=BasiliskII}"
BASILISKII_VMS_PATH="${BASILISKII_VMS_PATH:="${HOME}/Documents/BasiliskII"}"
BASILISKII_SNAPSHOT_COMPRESSION="${BASILISKII_SNAPSHOT_COMPRESSION:=gzip}"
basiliskii_prefs_file=".basilisk_ii_prefs"
basiliskii_pid_file=".basiliskii.pid"
@ -354,14 +355,30 @@ function vm_pkg_create_snapshot() {
if ! mkdir "$snapshot"; then
echo "Error! Unable to create snapshot directory '${snapshot}'."
else
local disk_copy_success=true
local disks_copy_success=true
while IFS= read -r disk; do
if ! cp "${1}/${disk}" "${snapshot}/${disk}"; then
echo "Error! Unable to copy disk '${1}/${disk}' to '${snapshot}/${disk}'."
disk_copy_success=false
local src_disk="${1}/${disk}"
local dst_disk="${snapshot}/${disk}"
local copy_success=true
case "$BASILISKII_SNAPSHOT_COMPRESSION" in
"gzip")
dst_disk="${dst_disk}.gz"
if ! gzip -k -c "$src_disk" > "$dst_disk"; then
copy_success=false
fi
;;
*)
if ! cp "$src_disk" "$dst_disk"; then
copy_success=false
fi
;;
esac
if ! $copy_success; then
echo "Error! Unable to copy disk '${src_disk}' to '${dst_disk}'."
disks_copy_success=false
fi
done <<< "$(vm_pkg_disks "$1")"
if $disk_copy_success; then
if $disks_copy_success; then
echo "Created '${timestamp}' snapshot of '${vm}' BasiliskII VM."
success=true
else