From 27eec996aaeb98fc07017c23baeafb39a548876d Mon Sep 17 00:00:00 2001 From: heavybullets8 Date: Sat, 17 Dec 2022 20:27:53 -0700 Subject: [PATCH 1/5] Edit restore message on scale ver change --- functions/backup.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/functions/backup.sh b/functions/backup.sh index 43b44b70..3d795cd2 100644 --- a/functions/backup.sh +++ b/functions/backup.sh @@ -149,9 +149,13 @@ do done +# Boot Query +boot_query=$(cli -m csv -c 'system bootenv query created,realname') + + # Get the date of system version and when it was updated current_version=$(cli -m csv -c 'system version' | awk -F '-' '{print $3}') -when_updated=$(cli -m csv -c 'system bootenv query created,realname' | grep "$current_version",\ +when_updated=$(echo "$boot_query" | grep "$current_version",\ | awk -F ',' '{print $2}' | sed 's/[T|-]/_/g' | sed 's/:/_/g' | awk -F '_' '{print $1 $2 $3 $4 $5}') @@ -159,12 +163,25 @@ when_updated=$(cli -m csv -c 'system bootenv query created,realname' | grep "$cu restore_point_date=$(echo "$restore_point" | awk -F '_' '{print $2 $3 $4 $5 $6}' | tr -d "_") +# Grab previous version +previous_version=$(echo "$boot_query" | sort -nr | grep -A 1 "$current_version," | tail -n 1) + + # Compare the dates while (("$restore_point_date" < "$when_updated" )) do clear -x echo "The restore point you have chosen is from an older version of Truenas Scale" echo "This is not recommended, as it may cause issues with the system" + echo + echo "Current SCALE Information:" + echo "Version: $current_version" + echo "When Updated: $(echo "$restore_point" | awk -F '_' '{print $2 "-" $3 "-" $4}')" + echo + echo "Restore Point SCALE Information:" + echo "Version: $(echo "$previous_version" | awk -F ',' '{print $1}')" + echo "When Updated: $(echo "$previous_version" | awk -F ',' '{print $2}' | awk -F 'T' '{print $1}')" + echo if read -rt 120 -p "Would you like to proceed? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; }; then case $yesno in [Yy] | [Yy][Ee][Ss]) From 12100cf3f04f7d94cb57c248f26360c3f7bbed66 Mon Sep 17 00:00:00 2001 From: heavybullets8 Date: Sun, 18 Dec 2022 10:41:04 -0700 Subject: [PATCH 2/5] initial backup validity checks --- functions/backup.sh | 110 +++++++++++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 32 deletions(-) diff --git a/functions/backup.sh b/functions/backup.sh index 3d795cd2..cd57075e 100644 --- a/functions/backup.sh +++ b/functions/backup.sh @@ -149,40 +149,87 @@ do done -# Boot Query -boot_query=$(cli -m csv -c 'system bootenv query created,realname') +## Check to see if empty PVC data is present in any of the applications ## +# Find all pv_info.json files two subfolders deep +pool=$(cli -c 'app kubernetes config' | grep -E "pool\s\|" | awk -F '|' '{print $3}' | tr -d " \t\n\r") +files=$(find "$(find /mnt/"$pool"/ix-applications/backups -maxdepth 0 )" -name pv_info.json | grep "$restore_point"); -# Get the date of system version and when it was updated -current_version=$(cli -m csv -c 'system version' | awk -F '-' '{print $3}') -when_updated=$(echo "$boot_query" | grep "$current_version",\ -| awk -F ',' '{print $2}' | sed 's/[T|-]/_/g' | sed 's/:/_/g' | awk -F '_' '{print $1 $2 $3 $4 $5}') +# Iterate over the list of files +for file in $files; do + # Check if the file only contains {} subfolders two deep + contents=$(cat $file) + if [[ "$contents" == '{}' ]]; then + # Print the file if it meets the criterion + file=$(echo "$file" | awk -F '/' '{print $7}') + borked_array+="$file\n" + borked=True + fi +done - -# Get the date of the chosen restore point -restore_point_date=$(echo "$restore_point" | awk -F '_' '{print $2 $3 $4 $5 $6}' | tr -d "_") - - -# Grab previous version -previous_version=$(echo "$boot_query" | sort -nr | grep -A 1 "$current_version," | tail -n 1) - - -# Compare the dates -while (("$restore_point_date" < "$when_updated" )) -do - clear -x - echo "The restore point you have chosen is from an older version of Truenas Scale" - echo "This is not recommended, as it may cause issues with the system" - echo - echo "Current SCALE Information:" - echo "Version: $current_version" - echo "When Updated: $(echo "$restore_point" | awk -F '_' '{print $2 "-" $3 "-" $4}')" - echo - echo "Restore Point SCALE Information:" - echo "Version: $(echo "$previous_version" | awk -F ',' '{print $1}')" - echo "When Updated: $(echo "$previous_version" | awk -F ',' '{print $2}' | awk -F 'T' '{print $1}')" - echo - if read -rt 120 -p "Would you like to proceed? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; }; then +# If there is empty PVC data, exit +if [[ $borked == True ]]; then + echo "Warning!:" + echo "The following applications have empty PVC data:" + for file in $borked_array; do + echo -e "$file" + done + echo "You need to ensure these applications are not supposed to have PVC data before proceeding" + while true + do + read -rt 120 -p "Would you like to proceed? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; } + case $yesno in + [Yy] | [Yy][Ee][Ss]) + echo "Proceeding.." + sleep 3 + break + ;; + [Nn] | [Nn][Oo]) + echo "Exiting" + exit + ;; + *) + echo "That was not an option, try again" + sleep 3 + continue + ;; + esac + done +fi + + + +## Check the restore point, and ensure it is the same version as the current system ## +# Boot Query +boot_query=$(cli -m csv -c 'system bootenv query created,realname') + +# Get the date of system version and when it was updated +current_version=$(cli -m csv -c 'system version' | awk -F '-' '{print $3}') +when_updated=$(echo "$boot_query" | grep "$current_version",\ +| awk -F ',' '{print $2}' | sed 's/[T|-]/_/g' | sed 's/:/_/g' | awk -F '_' '{print $1 $2 $3 $4 $5}') + +# Get the date of the chosen restore point +restore_point_date=$(echo "$restore_point" | awk -F '_' '{print $2 $3 $4 $5 $6}' | tr -d "_") + +# Grab previous version +previous_version=$(echo "$boot_query" | sort -nr | grep -A 1 "$current_version," | tail -n 1) + +# Compare the dates +while (("$restore_point_date" < "$when_updated" )) +do + clear -x + echo "The restore point you have chosen is from an older version of Truenas Scale" + echo "This is not recommended, as it may cause issues with the system" + echo + echo "Current SCALE Information:" + echo "Version: $current_version" + echo "When Updated: $(echo "$restore_point" | awk -F '_' '{print $2 "-" $3 "-" $4}')" + echo + echo "Restore Point SCALE Information:" + echo "Version: $(echo "$previous_version" | awk -F ',' '{print $1}')" + echo "When Updated: $(echo "$previous_version" | awk -F ',' '{print $2}' | awk -F 'T' '{print $1}')" + echo + read -rt 120 -p "Would you like to proceed? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; } case $yesno in [Yy] | [Yy][Ee][Ss]) echo "Proceeding.." @@ -199,7 +246,6 @@ do continue ;; esac - fi done From 6bbfa17e1c8100682d983926d623b937bb4749a7 Mon Sep 17 00:00:00 2001 From: heavybullets8 Date: Sun, 18 Dec 2022 13:26:56 -0700 Subject: [PATCH 3/5] Hot patch --- functions/menu.sh | 4 +++ functions/misc.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/functions/menu.sh b/functions/menu.sh index 164bdd7b..67543d08 100644 --- a/functions/menu.sh +++ b/functions/menu.sh @@ -13,6 +13,7 @@ echo "4) Backup Options" echo "5) Update HeavyScript" echo "6) Update Applications" echo "7) Command to Container" +echo "8) Patch 22.12.0" echo echo "0) Exit" read -rt 120 -p "Please select an option by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } @@ -79,6 +80,9 @@ case $selection in 7) cmd_to_container ;; + 8) + patch_2212_backups + ;; *) echo "\"$selection\" was not an option, please try agian" && sleep 3 && menu ;; diff --git a/functions/misc.sh b/functions/misc.sh index 66b93410..decf8899 100644 --- a/functions/misc.sh +++ b/functions/misc.sh @@ -98,3 +98,76 @@ echo exit } export -f help + + + +patch_2212_backups(){ +clear -x +#Check TrueNAS version, skip if not 22.12.0 +if ! [ "$(cli -m csv -c 'system version' | awk -F '-' '{print $3}')" == "22.12.0" ]; then + echo "This patch does not apply to your version of TrueNAS" + return +fi + + +#Description +echo "This patch will fix the issue with backups not restoring properly" +echo "Due to Ix-Systems not saving PVC in backups, this patch will fix that" +echo "Otherwise backups will not restore properly" +echo "You only need to run this patch once, it will not run again" +echo + + +#Download patch +echo "Downloading Backup Patch" +if ! wget -q https://github.com/truecharts/truetool/raw/main/hotpatch/2212/HP1.patch; then + echo "Failed to download Backup Patch" + exit +else + echo "Downloaded Backup Patch" +fi + +echo + +# Apply patch +echo "Applying Backup Patch" +if patch -N --reject-file=/dev/null -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ < HP1.patch &>/dev/null; then + echo "Backup Patch applied" + rm -rf HP1.patch +else + echo "Backup Patch already applied" + rm -rf HP1.patch + exit +fi + +echo + +#Restart middlewared +while true +do + echo "We need to restart middlewared to finish the patch" + echo "This will cause a short downtime for your system" + read -rt 120 -p "Would you like to proceed? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; } + case $yesno in + [Yy] | [Yy][Ee][Ss]) + echo "Restarting middlewared" + service middlewared restart & + wait $! + break + ;; + [Nn] | [Nn][Oo]) + echo "Exiting" + echo "Please restart middlewared manually" + echo "You can do: service middlewared restart" + exit + ;; + *) + echo "That was not an option, try again" + sleep 3 + continue + ;; + esac +done +} +export -f patchv22120 + From 5083926056f7be3512a80e86f8f142e9ed3e05ef Mon Sep 17 00:00:00 2001 From: heavybullets8 Date: Sun, 18 Dec 2022 13:28:52 -0700 Subject: [PATCH 4/5] edit wording --- functions/misc.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions/misc.sh b/functions/misc.sh index decf8899..43e2947a 100644 --- a/functions/misc.sh +++ b/functions/misc.sh @@ -153,6 +153,8 @@ do echo "Restarting middlewared" service middlewared restart & wait $! + echo "Restarted middlewared" + echo "You are set, there is no need to run this patch again" break ;; [Nn] | [Nn][Oo]) From 8ef2a91a73c64a8079c7a1297e8830a92dbddf78 Mon Sep 17 00:00:00 2001 From: heavybullets8 Date: Sun, 18 Dec 2022 13:31:25 -0700 Subject: [PATCH 5/5] last commit on wording --- functions/misc.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/misc.sh b/functions/misc.sh index 43e2947a..372b42d4 100644 --- a/functions/misc.sh +++ b/functions/misc.sh @@ -146,7 +146,8 @@ echo while true do echo "We need to restart middlewared to finish the patch" - echo "This will cause a short downtime for your system" + echo "This will cause a short downtime for some minor services approximately 10-30 seconds" + echo "Applications should not be affected" read -rt 120 -p "Would you like to proceed? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; } case $yesno in [Yy] | [Yy][Ee][Ss])