2022-07-25 02:29:58 +00:00
#!/bin/bash
backup( ) {
2022-07-28 19:31:48 +00:00
echo_backup += ( "\n🄱 🄰 🄲 🄺 🅄 🄿 🅂" )
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-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"
read -rt 120 -p "Please type a number: " selection
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
break
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"
echo -e " \n\nYou have chosen:\n $restore_point \n\nWould you like to continue? "
2022-07-29 05:32:01 +00:00
echo -e "1) Yes\n2) Exit\n"
read -rt 120 -p "Please type a number: " yesno
2022-07-29 05:22:06 +00:00
case $yesno in
2022-07-29 05:32:01 +00:00
1)
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-29 05:32:01 +00:00
2)
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
echo "Delete more?"
2022-07-29 05:32:01 +00:00
echo "1) Yes"
echo "2) No"
2022-07-29 05:22:06 +00:00
read -rt 120 -p "Please type a number: " yesno
case $yesno in
1)
break
; ;
2)
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)
clear -x
if [ [ -z " $list_backups " ] ] ; then
echo "No HeavyScript restore points available"
exit
else
title
2022-07-29 06:08:30 +00:00
echo "Choose a Restore Point"
2022-07-29 05:46:08 +00:00
fi
echo " $list_backups "
2022-07-29 05:49:53 +00:00
echo
echo "0) Exit"
2022-07-29 05:46:08 +00:00
read -rt 120 -p "Please type a number: " selection
2022-07-29 05:49:53 +00:00
[ [ $selection = = 0 ] ] && echo "Exiting.." && exit
2022-07-29 05:46:08 +00:00
restore_point = $( echo " $list_backups " | grep ^" $selection ) " | awk '{print $2}' )
#Check for valid selection. If none, kill script
if [ [ -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
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"
echo -e " \n\nYou have chosen:\n $restore_point \n\nWould you like to continue? "
echo -e "1) Yes\n2) Exit\n"
read -rt 120 -p "Please type a number: " yesno
case $yesno in
1)
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
; ;
2)
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