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(){
while true
do
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)
if [[ -z "$list_backups" ]]; then
echo "No restore points available"
exit
fi
#Select a restore point
while true
do
clear -x
@ -63,6 +63,8 @@ do
fi
break # Break out of the loop if all of the If statement checks above are untrue
done
#Confirm deletion
while true
do
clear -x
@ -87,6 +89,8 @@ do
;;
esac
done
#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; }
@ -106,20 +110,19 @@ do
esac
done
done
}
export -f deleteBackup
restore(){
while true
do
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)
if [[ -z "$list_backups" ]]; then
echo "No HeavyScript restore points available"
exit
fi
#Select a restore point
while true
do
clear -x
@ -144,6 +147,46 @@ do
fi
break
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
do
clear -x
@ -193,6 +236,6 @@ do
;;
esac
done
done
}
export -f restore