2022-07-25 02:29:58 +00:00
#!/bin/bash
backup( ) {
2022-07-31 18:56:50 +00:00
echo_backup += ( "🄱 🄰 🄲 🄺 🅄 🄿 🅂" )
2022-07-26 23:53:08 +00:00
echo_backup += ( " Number of backups was set to $number_of_backups " )
2022-07-25 02:29:58 +00:00
date = $( date '+%Y_%m_%d_%H_%M_%S' )
2022-07-26 06:39:25 +00:00
[ [ " $verbose " = = "true" ] ] && cli -c 'app kubernetes backup_chart_releases backup_name=' '"' HeavyScript_" $date " '"' & > /dev/null && echo_backup += ( HeavyScript_" $date " )
[ [ -z " $verbose " ] ] && echo_backup += ( "\nNew Backup Name:" ) && cli -c 'app kubernetes backup_chart_releases backup_name=' '"' HeavyScript_" $date " '"' | tail -n 1 & > /dev/null && echo_backup += ( HeavyScript_" $date " )
2022-07-25 02:29:58 +00:00
mapfile -t list_backups < <( cli -c 'app kubernetes list_backups' | grep "HeavyScript_" | sort -t '_' -Vr -k2,7 | awk -F '|' '{print $2}' | tr -d " \t\r" )
2022-07-27 02:20:16 +00:00
if [ [ ${# list_backups [@] } -gt " $number_of_backups " ] ] ; then
2022-07-26 23:43:06 +00:00
echo_backup += ( "\nDeleted the oldest backup(s) for exceeding limit:" )
2022-07-25 02:29:58 +00:00
overflow = $(( ${# list_backups [@] } - " $number_of_backups " ))
mapfile -t list_overflow < <( cli -c 'app kubernetes list_backups' | grep "HeavyScript_" | sort -t '_' -V -k2,7 | awk -F '|' '{print $2}' | tr -d " \t\r" | head -n " $overflow " )
for i in " ${ list_overflow [@] } "
do
2022-07-26 06:32:37 +00:00
cli -c 'app kubernetes delete_backup backup_name=' '"' " $i " '"' & > /dev/null || echo_backup += ( " Failed to delete $i " )
echo_backup += ( " $i " )
2022-07-25 02:29:58 +00:00
done
fi
2022-07-26 06:32:37 +00:00
#Dump the echo_array, ensures all output is in a neat order.
for i in " ${ echo_backup [@] } "
do
echo -e " $i "
done
2022-07-31 18:56:50 +00:00
echo
echo
2022-07-25 02:29:58 +00:00
}
export -f backup
deleteBackup( ) {
2022-07-29 05:11:09 +00:00
while true
do
2022-07-29 05:22:06 +00:00
clear -x && echo "pulling all restore points.."
2022-07-29 05:32:45 +00:00
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)
2022-07-29 05:22:06 +00:00
if [ [ -z " $list_backups " ] ] ; then
echo "No restore points available"
exit
fi
2022-07-29 06:25:20 +00:00
while true
do
2022-07-29 06:26:47 +00:00
clear -x
title
echo -e "Choose a Restore Point to Delete\nThese may be out of order if they are not HeavyScript backups"
2022-07-29 06:25:20 +00:00
echo " $list_backups "
echo
echo "0) Exit"
2022-07-30 22:43:42 +00:00
read -rt 240 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; }
2022-07-29 06:25:20 +00:00
restore_point = $( echo " $list_backups " | grep ^" $selection ) " | awk '{print $2}' )
if [ [ $selection = = 0 ] ] ; then
echo "Exiting.."
exit
elif [ [ -z " $selection " ] ] ; then
echo "Your selection cannot be empty"
sleep 3
continue
elif [ [ -z " $restore_point " ] ] ; then
echo " Invalid Selection: $selection , was not an option "
sleep 3
continue
fi
2022-07-29 22:13:01 +00:00
break # Break out of the loop if all of the If statement checks above are untrue
2022-07-29 06:25:20 +00:00
done
2022-07-29 05:22:06 +00:00
while true
do
2022-07-29 05:32:01 +00:00
clear -x
2022-07-29 05:22:06 +00:00
echo -e "\nWARNING:\nYou CANNOT go back after deleting your restore point"
2022-07-30 22:57:52 +00:00
echo -e " \n\nYou have chosen:\n $restore_point \n\n "
2022-07-30 23:07:28 +00:00
read -rt 120 -p "Would you like to proceed with deletion? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; }
2022-07-29 05:22:06 +00:00
case $yesno in
2022-07-30 22:57:52 +00:00
[ Yy] | [ Yy] [ Ee] [ Ss] )
2022-07-29 05:22:06 +00:00
echo -e " \nDeleting $restore_point "
cli -c 'app kubernetes delete_backup backup_name=' '"' " $restore_point " '"' & >/dev/null || { echo "Failed to delete backup.." ; exit; }
echo "Sucessfully deleted"
break
; ;
2022-07-30 22:57:52 +00:00
[ Nn] | [ Nn] [ Oo] )
2022-07-29 05:22:06 +00:00
echo "Exiting"
exit
; ;
*)
2022-07-29 05:32:01 +00:00
echo "That was not an option, try again"
sleep 3
continue
2022-07-29 05:22:06 +00:00
; ;
esac
done
while true
do
2022-07-30 23:07:28 +00:00
read -rt 120 -p "Delete more backups? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; }
2022-07-29 05:22:06 +00:00
case $yesno in
2022-07-30 22:57:52 +00:00
[ Yy] | [ Yy] [ Ee] [ Ss] )
2022-07-29 05:22:06 +00:00
break
; ;
2022-07-30 22:57:52 +00:00
[ Nn] | [ Nn] [ Oo] )
2022-07-29 05:22:06 +00:00
exit
; ;
*)
echo " $yesno was not an option, try again "
sleep 2
continue
; ;
2022-07-29 05:11:09 +00:00
2022-07-29 05:22:06 +00:00
esac
2022-07-29 05:11:09 +00:00
2022-07-29 05:22:06 +00:00
done
done
2022-07-25 02:29:58 +00:00
}
export -f deleteBackup
restore( ) {
2022-07-29 05:46:08 +00:00
while true
do
clear -x && echo "pulling restore points.."
list_backups = $( cli -c 'app kubernetes list_backups' | grep "HeavyScript_" | 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
2022-07-29 06:34:55 +00:00
fi
while true
do
clear -x
2022-07-29 05:46:08 +00:00
title
2022-07-29 06:08:30 +00:00
echo "Choose a Restore Point"
2022-07-29 06:34:55 +00:00
echo " $list_backups "
echo
echo "0) Exit"
2022-07-30 22:43:42 +00:00
read -rt 240 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; }
2022-07-29 06:34:55 +00:00
restore_point = $( echo " $list_backups " | grep ^" $selection ) " | awk '{print $2}' )
if [ [ $selection = = 0 ] ] ; then
echo "Exiting.."
exit
elif [ [ -z " $selection " ] ] ; then
echo "Your selection cannot be empty"
sleep 3
continue
elif [ [ -z " $restore_point " ] ] ; then
echo " Invalid Selection: $selection , was not an option "
sleep 3
continue
fi
2022-07-29 06:35:54 +00:00
break
2022-07-29 06:34:55 +00:00
done
2022-07-29 05:46:08 +00:00
while true
do
clear -x
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"
2022-07-30 22:57:52 +00:00
echo -e " \n\nYou have chosen:\n $restore_point \n\n "
2022-07-30 23:07:28 +00:00
read -rt 120 -p "Would you like to proceed with restore? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; }
2022-07-29 05:46:08 +00:00
case $yesno in
2022-07-30 22:57:52 +00:00
[ Yy] | [ Yy] [ Ee] [ Ss] )
2022-07-29 05:46:08 +00:00
echo -e "\nStarting Backup, this will take a LONG time."
cli -c 'app kubernetes restore_backup backup_name=' '"' " $restore_point " '"' || { echo "Failed to delete backup.." ; exit; }
exit
; ;
2022-07-30 22:57:52 +00:00
[ Nn] | [ Nn] [ Oo] )
2022-07-29 05:46:08 +00:00
echo "Exiting"
exit
; ;
*)
echo "That was not an option, try again"
sleep 3
continue
; ;
esac
done
done
2022-07-25 02:29:58 +00:00
}
export -f restore