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,14 +31,14 @@ export -f backup
deleteBackup(){ deleteBackup(){
while true
do
clear -x && echo "pulling all restore points.." clear -x && echo "pulling all restore points.."
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) 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 if [[ -z "$list_backups" ]]; then
echo "No restore points available" echo "No restore points available"
exit exit
fi fi
#Select a restore point
while true while true
do do
clear -x clear -x
@ -63,6 +63,8 @@ do
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
#Confirm deletion
while true while true
do do
clear -x clear -x
@ -87,6 +89,8 @@ do
;; ;;
esac esac
done done
#Check if there are more backups to delete
while true while true
do 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; }
@ -106,20 +110,19 @@ do
esac esac
done done
done
} }
export -f deleteBackup export -f deleteBackup
restore(){ restore(){
while true
do
clear -x && echo "pulling restore points.." clear -x && echo "pulling restore points.."
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) 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 if [[ -z "$list_backups" ]]; then
echo "No HeavyScript restore points available" echo "No HeavyScript restore points available"
exit exit
fi fi
#Select a restore point
while true while true
do do
clear -x clear -x
@ -144,6 +147,46 @@ do
fi fi
break break
done done
# 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 while true
do do
clear -x clear -x
@ -193,6 +236,6 @@ do
;; ;;
esac esac
done done
done
} }
export -f restore export -f restore