Merge pull request #32 from Heavybullets8/restore_validation

Restore validation
This commit is contained in:
Heavybullets8 2022-12-16 03:04:37 +00:00 committed by GitHub
commit 3fe18c0eff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,16 +31,16 @@ export -f backup
deleteBackup(){ deleteBackup(){
while true clear -x && echo "pulling all restore points.."
do list_backups=$(cli -c 'app kubernetes list_backups' | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl -s ") " | column -t)
clear -x && echo "pulling all restore points.." if [[ -z "$list_backups" ]]; then
list_backups=$(cli -c 'app kubernetes list_backups' | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl -s ") " | column -t)
if [[ -z "$list_backups" ]]; then
echo "No restore points available" echo "No restore points available"
exit exit
fi fi
while true
do #Select a restore point
while true
do
clear -x clear -x
title title
echo -e "Choose a Restore Point to Delete\nThese may be out of order if they are not HeavyScript backups" echo -e "Choose a Restore Point to Delete\nThese may be out of order if they are not HeavyScript backups"
@ -62,9 +62,11 @@ do
continue continue
fi fi
break # Break out of the loop if all of the If statement checks above are untrue break # Break out of the loop if all of the If statement checks above are untrue
done done
while true
do #Confirm deletion
while true
do
clear -x clear -x
echo -e "WARNING:\nYou CANNOT go back after deleting your restore point" echo -e "WARNING:\nYou CANNOT go back after deleting your restore point"
echo -e "\n\nYou have chosen:\n$restore_point\n\n" echo -e "\n\nYou have chosen:\n$restore_point\n\n"
@ -86,9 +88,11 @@ do
continue continue
;; ;;
esac esac
done done
while true
do #Check if there are more backups to delete
while true
do
read -rt 120 -p "Delete more backups? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; } read -rt 120 -p "Delete more backups? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; }
case $yesno in case $yesno in
[Yy] | [Yy][Ee][Ss]) [Yy] | [Yy][Ee][Ss])
@ -105,23 +109,22 @@ do
esac esac
done
done done
} }
export -f deleteBackup export -f deleteBackup
restore(){ restore(){
while true clear -x && echo "pulling restore points.."
do list_backups=$(cli -c 'app kubernetes list_backups' | grep -E "HeavyScript_|TrueTool_" | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl -s ") " | column -t)
clear -x && echo "pulling restore points.." if [[ -z "$list_backups" ]]; then
list_backups=$(cli -c 'app kubernetes list_backups' | grep -E "HeavyScript_|TrueTool_" | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl -s ") " | column -t)
if [[ -z "$list_backups" ]]; then
echo "No HeavyScript restore points available" echo "No HeavyScript restore points available"
exit exit
fi fi
while true
do #Select a restore point
while true
do
clear -x clear -x
title title
echo "Choose a Restore Point" echo "Choose a Restore Point"
@ -143,9 +146,49 @@ do
continue continue
fi fi
break break
done done
while true
do
# 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",\
| 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 "_")
# 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"
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])
echo "Proceeding.."
sleep 3
break
;;
[Nn] | [Nn][Oo])
echo "Exiting"
exit
;;
*)
echo "That was not an option, try again"
sleep 3
continue
;;
esac
fi
done
#Confirm restore
while true
do
clear -x clear -x
echo -e "WARNING:\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 -e "WARNING:\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 -e "\n\nYou have chosen:\n$restore_point\n\n" echo -e "\n\nYou have chosen:\n$restore_point\n\n"
@ -192,7 +235,7 @@ do
continue continue
;; ;;
esac esac
done
done done
} }
export -f restore export -f restore