From 1abf5479359a6ee4a8f5a80f28fa4e3b16b5cf95 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 12 Aug 2017 01:19:31 +0200 Subject: [PATCH 1/2] Use rsync instead of lxc-snapshot for temporary snapshot --- package_check.sh | 4 +-- sub_scripts/launcher.sh | 55 ++++++++++++++++------------------ sub_scripts/testing_process.sh | 6 ++-- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/package_check.sh b/package_check.sh index 7389db0..7d39b08 100755 --- a/package_check.sh +++ b/package_check.sh @@ -1017,8 +1017,8 @@ then # Print the final results of the tests TEST_RESULTS - # Destroy all snapshots other than snap0 - destroy_temporary_snapshot + # Set snap0 as the current snapshot + current_snapshot=snap0 done 3<<< "$(grep "^;; " "$check_process")" diff --git a/sub_scripts/launcher.sh b/sub_scripts/launcher.sh index 7634cbb..1b14842 100755 --- a/sub_scripts/launcher.sh +++ b/sub_scripts/launcher.sh @@ -65,6 +65,9 @@ stop_timer () { create_temp_backup () { # Create a temporary snapshot + # snap1 for subpath or snap2 for root install + snap_number=$1 + start_timer # Check all the witness files, to verify if them still here check_witness_files >&2 @@ -72,13 +75,28 @@ create_temp_backup () { # Stop the container, before its snapshot sudo lxc-stop --name $lxc_name >&2 - # Create the snapshot. - sudo lxc-snapshot --name $lxc_name >> "$test_result" 2>&1 + # Check if the snapshot already exist + if [ ! -e "$snapshot_path/snap$snap_number" ] + then + echo "snap$snap_number doesn't exist, its first creation can be take a little while." >&2 + # Create the snapshot. + sudo lxc-snapshot --name $lxc_name >> "$test_result" 2>&1 + + # lxc always creates the first snapshot it can creates. + # So if snap1 doesn't exist and you try to create snap2, it will be named snap1. + if [ "$snap_number" == "2" ] && [ ! -e "$snapshot_path/snap1" ] + then + # Rename snap1 to snap2 + sudo mv "$snapshot_path/snap1" "$snapshot_path/snap2" + fi + fi + + # Update the snapshot with rsync to clone the current lxc state + sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "/var/lib/lxc/$lxc_name/rootfs/" "$snapshot_path/snap$snap_number/rootfs/" > /dev/null 2>> "$test_result" + + # Set this snapshot as the current snapshot + current_snapshot=snap$snap_number - # Get the last created snapshot, and set it as the new current snapshot. - current_snapshot=$(sudo lxc-snapshot --name $lxc_name --list | sort | tail --lines=1 | cut --delimiter=' ' --fields=1) - # And return it - echo "$current_snapshot" stop_timer 1 >&2 # Restart the container, after the snapshot @@ -106,27 +124,6 @@ use_temp_snapshot () { yunohost_result=0 } -destroy_temporary_snapshot () { - # Destroy all snapshots other than snap0 - - while true - do - local snapshot=$(sudo lxc-snapshot --name $lxc_name --list | sort | tail --lines=1 | cut --delimiter=' ' --fields=1) - if [ -n "$snapshot" ] && [ "$snapshot" != "snap0" ] - then - echo "Destroy temporary snapshot $snapshot." - sudo lxc-snapshot --name $lxc_name --destroy $snapshot - else - break - fi - done - - # Clear the variables which contains the snapshot names - unset root_snapshot - unset subpath_snapshot - current_snapshot=snap0 -} - #================================================= is_lxc_running () { @@ -292,8 +289,8 @@ LXC_TURNOFF () { sudo ifdown --force $lxc_bridge | tee --append "$test_result" 2>&1 fi - # Destroy all snapshots other than snap0 - destroy_temporary_snapshot + # Set snap0 as the current snapshot + current_snapshot=snap0 } LXC_CONNECT_INFO () { diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index 43b8803..e0f5082 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -443,7 +443,8 @@ CHECK_SETUP () { if [ -z "$root_snapshot" ] then ECHO_FORMAT "Create a snapshot for root installation.\n" "white" clog - root_snapshot=$(create_temp_backup) + create_temp_backup 2 + root_snapshot=snap2 fi else # Check if a snapshot already exist for a subpath (or no_url) install @@ -451,7 +452,8 @@ CHECK_SETUP () { then # Then create a snapshot ECHO_FORMAT "Create a snapshot for sub path installation.\n" "white" clog - subpath_snapshot=$(create_temp_backup) + create_temp_backup 1 + subpath_snapshot=snap1 fi fi fi From 8408a70934d205e33817fae483f28146e128fa77 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 12 Aug 2017 20:04:38 +0200 Subject: [PATCH 2/2] Fix snapshots usage --- package_check.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package_check.sh b/package_check.sh index 7d39b08..e3e6315 100755 --- a/package_check.sh +++ b/package_check.sh @@ -1019,6 +1019,9 @@ then # Set snap0 as the current snapshot current_snapshot=snap0 + # And clean temporary snapshots + unset root_snapshot + unset subpath_snapshot done 3<<< "$(grep "^;; " "$check_process")"