From 442e75d678af7785715aec9a2c6397a48ad16fca Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Tue, 27 Dec 2022 13:27:38 +0100 Subject: [PATCH] removing old backup version and moving to HeavyScript library backup --- includes/backup.sh | 96 ---------------------------------------------- truetool.sh | 9 +++-- 2 files changed, 5 insertions(+), 100 deletions(-) delete mode 100755 includes/backup.sh diff --git a/includes/backup.sh b/includes/backup.sh deleted file mode 100755 index e09449f9..00000000 --- a/includes/backup.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - -## Simple shortcut to just list the backups without promts and such -listBackups(){ -echo -e "${BWhite}Backup Listing Tool${Color_Off}" -clear -x && echo "pulling all restore points.." -list_backups=$(cli -c 'app kubernetes list_backups' | grep -v system-update | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl | column -t) -[[ -z "$list_backups" ]] && echo -e "${IRed}No restore points available${Color_Off}" && exit || echo "Detected Backups:" && echo "$list_backups" -} -export -f listBackups - -## Lists backups, except system-created backups, and promts which one to delete -deleteBackup(){ -echo -e "${BWhite}Backup Deletion Tool${Color_Off}" -clear -x && echo "pulling all restore points.." -list_delete_backups=$(cli -c 'app kubernetes list_backups' | grep -v system-update | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl | column -t) -clear -x -# shellcheck disable=SC2015 -[[ -z "$list_delete_backups" ]] && echo -e "${IRed}No restore points available${Color_Off}" && exit || { title; echo -e "Choose a restore point to delete\nThese may be out of order if they are not TrueTool backups" ; } -# shellcheck disable=SC2015 -echo "$list_delete_backups" && read -rt 600 -p "Please type a number: " selection && restore_point=$(echo "$list_delete_backups" | grep ^"$selection " | awk '{print $2}') -[[ -z "$selection" ]] && echo "${IRed}Your selection cannot be empty${Color_Off}" && exit #Check for valid selection. If none, kill script -[[ -z "$restore_point" ]] && echo "Invalid Selection: $selection, was not an option" && exit #Check for valid selection. If none, kill script -echo -e "\nWARNING:\nYou CANNOT go back after deleting your restore point" || { echo "${IRed}FAILED${Color_Off}"; exit; } -# shellcheck disable=SC2015 -echo -e "\n\nYou have chosen:\n$restore_point\n\nWould you like to continue?" && echo -e "1 Yes\n2 No" && read -rt 120 -p "Please type a number: " yesno || { echo "${IRed}FAILED${Color_Off}"; exit; } -if [[ $yesno == "1" ]]; then - echo -e "\nDeleting $restore_point" && cli -c 'app kubernetes delete_backup backup_name=''"'"$restore_point"'"' &>/dev/null && echo -e "${IGreen}Sucessfully deleted${Color_Off}" || echo -e "${IRed}Deletion FAILED${Color_Off}" -elif [[ $yesno == "2" ]]; then - echo "You've chosen NO, killing script." -else - echo -e "${IRed}Invalid Selection${Color_Off}" -fi -} -export -f deleteBackup - -## Creates backups and deletes backups if a "backups to keep"-count is exceeded. -# backups-to-keep takes only heavyscript and truetool created backups into account, as other backups aren't guaranteed to be sorted correctly -backup(){ -echo -e "${BWhite}Backup Tool${Color_Off}" -echo -e "\nNumber of backups was set to $number_of_backups" -date=$(date '+%Y_%m_%d_%H_%M_%S') -[[ "$verbose" == "true" ]] && cli -c 'app kubernetes backup_chart_releases backup_name=''"'TrueTool_"$date"'"' -[[ -z "$verbose" ]] && echo -e "\nNew Backup Name:" && cli -c 'app kubernetes backup_chart_releases backup_name=''"'TrueTool_"$date"'"' | tail -n 1 -mapfile -t list_create_backups < <(cli -c 'app kubernetes list_backups' | grep 'HeavyScript\|TrueTool_' | sort -t '_' -Vr -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r") -# shellcheck disable=SC2309 -if [[ ${#list_create_backups[@]} -gt "number_of_backups" ]]; then - echo -e "\nDeleting the oldest backup(s) for exceeding limit:" - overflow=$(( ${#list_create_backups[@]} - "$number_of_backups" )) - mapfile -t list_overflow < <(cli -c 'app kubernetes list_backups' | grep "TrueTool_" | sort -t '_' -V -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r" | head -n "$overflow") - for i in "${list_overflow[@]}" - do - cli -c 'app kubernetes delete_backup backup_name=''"'"$i"'"' &> /dev/null || echo "${IRed}FAILED${Color_Off} to delete $i" - echo "$i" - done -fi -} -export -f backup - -## Lists available backup and prompts the users to select a backup to restore -restore(){ -echo -e "${BWhite}Backup Restoration Tool${Color_Off}" -clear -x && echo "pulling restore points.." -list_restore_backups=$(cli -c 'app kubernetes list_backups' | grep "TrueTool_" | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl | column -t) -clear -x -# shellcheck disable=SC2015 -[[ -z "$list_restore_backups" ]] && echo "No TrueTool restore points available" && exit || { title; echo "Choose a restore point" ; } -echo "$list_restore_backups" && read -rt 600 -p "Please type a number: " selection && restore_point=$(echo "$list_restore_backups" | grep ^"$selection " | awk '{print $2}') -[[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script -[[ -z "$restore_point" ]] && echo "Invalid Selection: $selection, was not an option" && exit #Check for valid selection. If none, kill script -echo -e "\nWARNING:\nThis is NOT guranteed to work\nThis is ONLY supposed to be used as a LAST RESORT\nConsider rolling back your applications instead if possible" || { echo "${IRed}FAILED${Color_Off}"; exit; } -# shellcheck disable=SC2015 -echo -e "\n\nYou have chosen:\n$restore_point\n\nWould you like to continue?" && echo -e "1 Yes\n2 No" && read -rt 120 -p "Please type a number: " yesno || { echo "${IRed}FAILED${Color_Off}"; exit; } -if [[ $yesno == "1" ]]; then - echo -e "\nStarting Restore, this will take a ${BWhite}LONG${Color_Off} time." - pool=$(cli -c 'app kubernetes config' | grep -E "pool\s\|" | awk -F '|' '{print $3}' | tr -d " \t\n\r") - echo "Correcting PVC mountpoints..." - for pvc in $(zfs list -t filesystem -r "$pool"/ix-applications -o name -H | grep "/ix-applications/" | grep "volumes/pvc") - do - zfs set mountpoint=legacy "${pvc}" || echo "Fixing PVC mountpoints Failed for ${pvc}... Continuing..." - done - # Ensure readonly is turned off - if ! zfs set readonly=off "$pool"/ix-applications;then - echo -e "Error: Failed to set ZFS ReadOnly to \"off\"" - echo -e "After the restore, attempt to run the following command manually:" - echo "zfs set readonly=off $pool/ix-applications" - fi - echo "Triggering restore process..." - cli -c 'app kubernetes restore_backup backup_name=''"'"$restore_point"'"' || echo "Restore ${IRed}FAILED${Color_Off}" -elif [[ $yesno == "2" ]]; then - echo "You've chosen NO, killing script. Good luck." -else - echo -e "${IRed}Invalid Selection${Color_Off}" -fi -} -export -f restore diff --git a/truetool.sh b/truetool.sh index e76566cc..cf7809ea 100755 --- a/truetool.sh +++ b/truetool.sh @@ -12,8 +12,6 @@ targetRepo="https://github.com/truecharts/truetool.git" cd "${SCRIPT_DIR}" || echo -e "ERROR: Something went wrong accessing the script directory" # Includes -# shellcheck source=includes/backup.sh -source includes/backup.sh # shellcheck source=includes/chores.sh source includes/chores.sh # shellcheck source=includes/colors.sh @@ -22,8 +20,6 @@ source includes/colors.sh source includes/help.sh # shellcheck source=includes/help.sh source includes/patch.sh -# shellcheck source=includes/mount.sh -source includes/mount.sh # shellcheck source=includes/no_args.sh source includes/no_args.sh # shellcheck source=includes/title.sh @@ -40,6 +36,9 @@ source functions/dns.sh source functions/misc.sh # shellcheck source=functions/mount.sh source functions/mount.sh +# shellcheck source=functions/backup.sh +source functions/backup.sh + #If no argument is passed, set flag to show menu if [[ -z "$*" || "-" == "$*" || "--" == "$*" ]]; then @@ -138,6 +137,8 @@ title [[ "$enableUpdate" == "true" ]] && updater "$@" scaleVersion=$(version="$(cli -c 'system version' | awk -F '-' '{print $3}' | awk -F '.' '{print $1 $2 $3}' | tr -d " \t\r\.")") +update_limit=$(nproc --all) +rollback="true" ## Always check if a hotpatch needs to be applied hotpatch