Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
backup output change
Browse files Browse the repository at this point in the history
  • Loading branch information
Heavybullets8 committed Aug 21, 2023
1 parent 8c19cd9 commit 4511e70
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion functions/backup_restore/create_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ create_backup(){
fi

echo_backup+=("🄱 🄰 🄲 🄺 🅄 🄿 🅂")
echo_backup+=("Number of backups was set to $retention\n")
echo_backup+=("Backup retention: $retention\n")

if [[ "$db_backups_enabled" == "true" ]]; then
backup_cnpg_databases "$retention" "$timestamp" "$dump_folder"
Expand Down
12 changes: 8 additions & 4 deletions functions/backup_restore/database/cnpg_dump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ scale_deployments() {
deployment_name="$4"

# Specific deployment passed, scale only this deployment
k3s kubectl scale deployments/"$deployment_name" -n ix-"$app_name" --replicas="$replicas"
k3s kubectl scale deployments/"$deployment_name" -n ix-"$app_name" --replicas="$replicas" || return 1

if [[ $replicas -eq 0 ]]; then
wait_for_pods_to_stop "$app_name" "$timeout" "$deployment_name" && return 0 || return 1
Expand Down Expand Up @@ -197,6 +197,8 @@ backup_cnpg_databases() {
# Return if there are no app status lines
if [[ ${#app_status_lines[@]} -eq 0 ]]; then
return
else
echo_backup+=("--CNPG Database Backups--")
fi

# Loop through each app status line
Expand All @@ -218,10 +220,12 @@ backup_cnpg_databases() {
original_replicas["$key"]=$value
done

# Scale down all non CNPG deployments to 0 replicas
# Scale down all non-CNPG deployments to 0 replicas
for deployment in "${!original_replicas[@]}"; do
if [[ ${original_replicas[$deployment]} -ne 0 ]]; then
scale_deployments "$app_name" 300 0 "$deployment" > /dev/null 2>&1
# Check if the deployment is not already at 0 replicas
if [[ ${original_replicas[$deployment]} -ne 0 ]] && ! scale_deployments "$app_name" 300 0 "$deployment" > /dev/null 2>&1; then
echo_backup+=("Failed to scale down $app_name's $deployment deployment.")
failure=true
fi
done

Expand Down
7 changes: 5 additions & 2 deletions functions/backup_restore/snapshot/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ create_snapshot(){
local number_of_backups="$1"
local timestamp="$2"

echo_backup+=("--Snapshots--")

# Create a new backup with the current date and time as the name
if ! output=$(cli -c "app kubernetes backup_chart_releases backup_name=\"HeavyScript_$timestamp\""); then
echo_array+=("Error: Failed to create new backup")
return 1
fi

if [[ "$verbose" == true ]]; then
echo_backup+=("$output")
else
echo_backup+=("\nNew Backup Name:" "$(echo -e "$output" | tail -n 1)")
echo_backup+=("\nNew Snapshot Name:" "$(echo -e "$output" | tail -n 1)")
fi

# Get a list of backups sorted by name in descending order
Expand All @@ -25,7 +28,7 @@ create_snapshot(){

# If there are more backups than the allowed number, delete the oldest ones
if [[ ${#current_backups[@]} -gt "$number_of_backups" ]]; then
echo_backup+=("\nDeleted the oldest backup(s) for exceeding limit:")
echo_backup+=("\nDeleted the oldest Snapshot(s) for exceeding limit:")
overflow=$(( ${#current_backups[@]} - "$number_of_backups" ))
# Place excess backups into an array for deletion
mapfile -t list_overflow < <(cli -c 'app kubernetes list_backups' |
Expand Down

0 comments on commit 4511e70

Please sign in to comment.