delete while loop
This commit is contained in:
		| @@ -33,19 +33,54 @@ deleteBackup(){ | |||||||
| 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 | column -t) | list_backups=$(cli -c 'app kubernetes list_backups' | sort -t '_' -Vr -k2,7 | tr -d " \t\r"  | awk -F '|'  '{print $2}' | nl | column -t) | ||||||
| clear -x | clear -x | ||||||
| [[ -z "$list_backups" ]] && echo "No restore points available" && exit || { title; echo -e "Choose a restore point to delete\nThese may be out of order if they are not HeavyScript backups" ;  } | if [[ -z "$list_backups" ]]; then | ||||||
| echo "$list_backups" && read -t 600 -p "Please type a number: " selection && restore_point=$(echo "$list_backups" | grep ^"$selection " | awk '{print $2}') |     echo "No restore points available" | ||||||
| [[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script |     exit | ||||||
| [[ -z "$restore_point" ]] && echo "Invalid Selection: $selection, was not an option" && exit #Check for valid selection. If none, kill script |  | ||||||
| echo -e "\nWARNING:\nYou CANNOT go back after deleting your restore point" || { echo "FAILED"; exit; } |  | ||||||
| echo -e "\n\nYou have chosen:\n$restore_point\n\nWould you like to continue?"  && echo -e "1  Yes\n2  No" && read -t 120 -p "Please type a number: " yesno || { echo "FAILED"; exit; } |  | ||||||
| if [[ $yesno == "1" ]]; then |  | ||||||
|     echo -e "\nDeleting $restore_point" && cli -c 'app kubernetes delete_backup backup_name=''"'"$restore_point"'"' &>/dev/null && echo "Sucessfully deleted" || echo "Deletion Failed" |  | ||||||
| elif [[ $yesno == "2" ]]; then |  | ||||||
|     echo "You've chosen NO, killing script." |  | ||||||
| else | else | ||||||
|     echo "Invalid Selection" |     title | ||||||
|  |     echo -e "Choose a restore point to delete\nThese may be out of order if they are not HeavyScript backups" | ||||||
| fi | fi | ||||||
|  | echo "$list_backups" | ||||||
|  | read -rt 120 -p "Please type a number: " selection | ||||||
|  | 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" | ||||||
|  |     exit  | ||||||
|  | elif [[ -z "$restore_point" ]]; then | ||||||
|  |     echo "Invalid Selection: $selection, was not an option" | ||||||
|  |     exit  | ||||||
|  | fi | ||||||
|  | while true | ||||||
|  | do | ||||||
|  |     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?" | ||||||
|  |     echo -e "Yes\n0 exit" | ||||||
|  |     read -rt 120 -p "Type \"yes\" to continue, or exit with \"0\": " yesno  | ||||||
|  |     case $yesno in | ||||||
|  |         [Yy][Ee][Ss]) | ||||||
|  |             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 | ||||||
|  |             ;; | ||||||
|  |         0|[Ee][Xx][Ii][Tt]) | ||||||
|  |             echo "Exiting" | ||||||
|  |             exit | ||||||
|  |             ;; | ||||||
|  |         *) | ||||||
|  |             echo "Invalid Selection" | ||||||
|  |             ;; | ||||||
|  |     esac | ||||||
|  | done | ||||||
|  | # while true | ||||||
|  | # do | ||||||
|  | #     echo "Delete more?" | ||||||
|  | #     echo  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # done | ||||||
|  |  | ||||||
| } | } | ||||||
| export -f deleteBackup | export -f deleteBackup | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,70 +1,5 @@ | |||||||
| #!/bin/bash | #!/bin/bash | ||||||
|  |  | ||||||
| # mount(){ |  | ||||||
| # clear -x |  | ||||||
| # title |  | ||||||
| # echo -e "1  Mount\n2  Unmount All" && read -t 600 -p "Please type a number: " selection |  | ||||||
| # [[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script |  | ||||||
| # if [[ $selection == "1" ]]; then |  | ||||||
| #     list=$(k3s kubectl get pvc -A | sort -u | awk '{print NR-1, "\t" $1 "\t" $2 "\t" $4}' | column -t | sed "s/^0/ /") |  | ||||||
| #     echo "$list" && read -t 120 -p "Please type a number: " selection |  | ||||||
| #     [[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script |  | ||||||
| #     app=$(echo -e "$list" | grep ^"$selection " | awk '{print $2}' | cut -c 4- ) |  | ||||||
| #     [[ -z "$app" ]] && echo "Invalid Selection: $selection, was not an option" && exit #Check for valid selection. If none, kill script |  | ||||||
| #     pvc=$(echo -e "$list" | grep ^"$selection ") |  | ||||||
| #     status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "^$app\b" | awk -F ',' '{print $2}'| tr -d " \t\n\r") |  | ||||||
| #     if [[ "$status" != "STOPPED" ]]; then |  | ||||||
| #         [[ -z $timeout ]] && echo -e "\nDefault Timeout: 500" && timeout=500 || echo -e "\nCustom Timeout: $timeout" |  | ||||||
| #         SECONDS=0 && echo -e "\nScaling down $app" && midclt call chart.release.scale "$app" '{"replica_count": 0}' &> /dev/null |  | ||||||
| #     else |  | ||||||
| #         echo -e "\n$app is already stopped" |  | ||||||
| #     fi |  | ||||||
| #     while [[ "$SECONDS" -le "$timeout" && "$status" != "STOPPED" ]] |  | ||||||
| #     do |  | ||||||
| #         status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "^$app\b" | awk -F ',' '{print $2}'| tr -d " \t\n\r") |  | ||||||
| #         echo -e "Waiting $((timeout-SECONDS)) more seconds for $app to be STOPPED" && sleep 5 |  | ||||||
| #     done |  | ||||||
| #     data_name=$(echo "$pvc" | awk '{print $3}') |  | ||||||
| #     mount=$(echo "$pvc" | awk '{print $4}') |  | ||||||
| #     volume_name=$(echo "$pvc" | awk '{print $4}') |  | ||||||
| #     mapfile -t full_path < <(zfs list | grep "$volume_name" | awk '{print $1}') |  | ||||||
| #     if [[  "${#full_path[@]}" -gt 1 ]]; then #if there is another app with the same name on another pool, use the current pools application, since the other instance is probably old, or unused, or a backup. |  | ||||||
| #             echo "$app is using the same volume identifier on more than one pool.. attempting to use your current kubernetes apps pool" |  | ||||||
| #             pool=$(cli -c 'app kubernetes config' | grep -E "dataset\s\|" | awk -F '|' '{print $3}' | awk -F '/' '{print $1}' | tr -d " \t\n\r") |  | ||||||
| #             full_path=$(zfs list | grep "$volume_name" | grep "$pool" | awk '{print $1}') |  | ||||||
| #     fi |  | ||||||
| #     echo -e "\nMounting\n$full_path\nTo\n/mnt/heavyscript/$data_name" |  | ||||||
| #     zfs set mountpoint=/heavyscript/"$data_name" "$full_path" || echo "Failed to mount $app" |  | ||||||
| #     echo -e "Mounted\n\nUnmount with:\nzfs set mountpoint=legacy $full_path && rmdir /mnt/heavyscript/$data_name\n\nOr use the Unmount All option\n" |  | ||||||
| #     exit |  | ||||||
| # elif [[ $selection == "2" ]]; then |  | ||||||
| #     mapfile -t unmount_array < <(basename -a /mnt/heavyscript/* | sed "s/*//") |  | ||||||
| #     [[ -z ${unmount_array[*]} ]] && echo "Theres nothing to unmount" && exit |  | ||||||
| #     for i in "${unmount_array[@]}" |  | ||||||
| #     do |  | ||||||
| #         main=$(k3s kubectl get pvc -A | grep -E "\s$i\s" | awk '{print $1, $2, $4}') |  | ||||||
| #         app=$(echo "$main" | awk '{print $1}' | cut -c 4-) |  | ||||||
| #         pvc=$(echo "$main" | awk '{print $3}') |  | ||||||
| #         mapfile -t path < <(find /mnt/*/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-) |  | ||||||
| #         if [[  "${#path[@]}" -gt 1 ]]; then #if there is another app with the same name on another pool, use the current pools application, since the other instance is probably old, or unused, or a backup. |  | ||||||
| #             echo "$i is a name used on more than one pool.. attempting to use your current kubernetes apps pool" |  | ||||||
| #             pool=$(cli -c 'app kubernetes config' | grep -E "dataset\s\|" | awk -F '|' '{print $3}' | awk -F '/' '{print $1}' | tr -d " \t\n\r") |  | ||||||
| #             full_path=$(find /mnt/"$pool"/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-) |  | ||||||
| #             zfs set mountpoint=legacy "$full_path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i" |  | ||||||
| #         else |  | ||||||
| #             zfs set mountpoint=legacy "$path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i" |  | ||||||
| #         fi |  | ||||||
| #     done |  | ||||||
| #     rmdir /mnt/heavyscript |  | ||||||
| # else |  | ||||||
| #     echo "Invalid selection, \"$selection\" was not an option" |  | ||||||
| # fi |  | ||||||
| # } |  | ||||||
| # export -f mount |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| mount(){ | mount(){ | ||||||
| while true | while true | ||||||
| do | do | ||||||
| @@ -165,63 +100,3 @@ do | |||||||
| done | done | ||||||
| } | } | ||||||
| export -f mount | export -f mount | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| # [[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script |  | ||||||
| # if [[ $selection == "1" ]]; then |  | ||||||
|     # list=$(k3s kubectl get pvc -A | sort -u | awk '{print NR-1, "\t" $1 "\t" $2 "\t" $4}' | column -t | sed "s/^0/ /") |  | ||||||
|     # echo "$list" && read -t 120 -p "Please type a number: " selection |  | ||||||
|     # [[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script |  | ||||||
|     # app=$(echo -e "$list" | grep ^"$selection " | awk '{print $2}' | cut -c 4- ) |  | ||||||
|     # [[ -z "$app" ]] && echo "Invalid Selection: $selection, was not an option" && exit #Check for valid selection. If none, kill script |  | ||||||
|     # pvc=$(echo -e "$list" | grep ^"$selection ") |  | ||||||
|     # status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "^$app\b" | awk -F ',' '{print $2}'| tr -d " \t\n\r") |  | ||||||
|     # if [[ "$status" != "STOPPED" ]]; then |  | ||||||
|     #     [[ -z $timeout ]] && echo -e "\nDefault Timeout: 500" && timeout=500 || echo -e "\nCustom Timeout: $timeout" |  | ||||||
|     #     SECONDS=0 && echo -e "\nScaling down $app" && midclt call chart.release.scale "$app" '{"replica_count": 0}' &> /dev/null |  | ||||||
|     # else |  | ||||||
|     #     echo -e "\n$app is already stopped" |  | ||||||
|     # fi |  | ||||||
|     # while [[ "$SECONDS" -le "$timeout" && "$status" != "STOPPED" ]] |  | ||||||
|     # do |  | ||||||
|     #     status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "^$app\b" | awk -F ',' '{print $2}'| tr -d " \t\n\r") |  | ||||||
|     #     echo -e "Waiting $((timeout-SECONDS)) more seconds for $app to be STOPPED" && sleep 5 |  | ||||||
|     # done |  | ||||||
|     # data_name=$(echo "$pvc" | awk '{print $3}') |  | ||||||
|     # mount=$(echo "$pvc" | awk '{print $4}') |  | ||||||
|     # volume_name=$(echo "$pvc" | awk '{print $4}') |  | ||||||
|     # mapfile -t full_path < <(zfs list | grep "$volume_name" | awk '{print $1}') |  | ||||||
|     # if [[  "${#full_path[@]}" -gt 1 ]]; then #if there is another app with the same name on another pool, use the current pools application, since the other instance is probably old, or unused, or a backup. |  | ||||||
|     #         echo "$app is using the same volume identifier on more than one pool.. attempting to use your current kubernetes apps pool" |  | ||||||
|     #         pool=$(cli -c 'app kubernetes config' | grep -E "dataset\s\|" | awk -F '|' '{print $3}' | awk -F '/' '{print $1}' | tr -d " \t\n\r") |  | ||||||
|     #         full_path=$(zfs list | grep "$volume_name" | grep "$pool" | awk '{print $1}') |  | ||||||
|     # fi |  | ||||||
|     # echo -e "\nMounting\n$full_path\nTo\n/mnt/heavyscript/$data_name" |  | ||||||
|     # zfs set mountpoint=/heavyscript/"$data_name" "$full_path" || echo "Failed to mount $app" |  | ||||||
|     # echo -e "Mounted\n\nUnmount with:\nzfs set mountpoint=legacy $full_path && rmdir /mnt/heavyscript/$data_name\n\nOr use the Unmount All option\n" |  | ||||||
|     # exit |  | ||||||
| # elif [[ $selection == "2" ]]; then |  | ||||||
| #     # mapfile -t unmount_array < <(basename -a /mnt/heavyscript/* | sed "s/*//") |  | ||||||
|     # [[ -z ${unmount_array[*]} ]] && echo "Theres nothing to unmount" && exit |  | ||||||
|     # for i in "${unmount_array[@]}" |  | ||||||
|     # do |  | ||||||
|     #     main=$(k3s kubectl get pvc -A | grep -E "\s$i\s" | awk '{print $1, $2, $4}') |  | ||||||
|     #     app=$(echo "$main" | awk '{print $1}' | cut -c 4-) |  | ||||||
|     #     pvc=$(echo "$main" | awk '{print $3}') |  | ||||||
|     #     mapfile -t path < <(find /mnt/*/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-) |  | ||||||
|     #     if [[  "${#path[@]}" -gt 1 ]]; then #if there is another app with the same name on another pool, use the current pools application, since the other instance is probably old, or unused, or a backup. |  | ||||||
|     #         echo "$i is a name used on more than one pool.. attempting to use your current kubernetes apps pool" |  | ||||||
|     #         pool=$(cli -c 'app kubernetes config' | grep -E "dataset\s\|" | awk -F '|' '{print $3}' | awk -F '/' '{print $1}' | tr -d " \t\n\r") |  | ||||||
|     #         full_path=$(find /mnt/"$pool"/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-) |  | ||||||
|     #         zfs set mountpoint=legacy "$full_path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i" |  | ||||||
|     #     else |  | ||||||
|     #         zfs set mountpoint=legacy "$path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i" |  | ||||||
|     #     fi |  | ||||||
|     # done |  | ||||||
|     # rmdir /mnt/heavyscript |  | ||||||
| # else |  | ||||||
| #     echo "Invalid selection, \"$selection\" was not an option" |  | ||||||
| # fi |  | ||||||
| # } |  | ||||||
| # export -f mount |  | ||||||
		Reference in New Issue
	
	Block a user