=random commit, no notes
This commit is contained in:
parent
40c0da1cf2
commit
c78ed8c081
3 changed files with 171 additions and 3 deletions
|
@ -1,10 +1,24 @@
|
|||
#!/bin/bash
|
||||
#! /usr/bin/env bash
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
USER_HOME=$HOME
|
||||
[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")"
|
||||
. ${SHRC_D:-$SCRIPT_DIR}/01_util.functions
|
||||
|
||||
set -e
|
||||
|
||||
# create backup folder
|
||||
folder="./dumps/"
|
||||
mkdir -p "$folder"
|
||||
|
||||
# get namespaces with postgres database pod
|
||||
namespaces=$(k3s kubectl get pods -A | grep postgres | awk '{print $1}')
|
||||
json_results=$(
|
||||
# While tcdbinfo lists all SQL databases, we want only postgresql
|
||||
# in this script.
|
||||
"${SCRIPT_DIR}/tcdbinfo.sh" --json "${@}" \
|
||||
| jq -s '.[] | select( .protocol = "postgresql" )'
|
||||
)
|
||||
|
||||
namespaces=$(<<<"$json_results" jq -sr '.[] | .name')
|
||||
|
||||
for ns in $namespaces; do
|
||||
# extract application name
|
||||
|
@ -18,7 +32,10 @@ for ns in $namespaces; do
|
|||
k3s kubectl scale deploy "$app" -n "$ns" --replicas=0
|
||||
while true; do k3s kubectl get pods -n "$ns" | grep -i -q terminating || break; done;
|
||||
|
||||
k3s kubectl exec -n "$ns" -c "$app"-postgresql "$app"-postgresql-0 -- bash -c 'PGPASSWORD=$POSTGRES_PASSWORD pg_dump -Fc -U $POSTGRES_USER -d $POSTGRES_DB -f /tmp/'$file
|
||||
k3s kubectl exec -n "$ns" -c "$app"-postgresql "$app"-postgresql-0 -- bash -c "
|
||||
PGPASSWORD=\$POSTGRES_PASSWORD $( # Does not affect the output
|
||||
) pg_dump -Fc -U \$POSTGRES_USER -d \$POSTGRES_DB -f /tmp/$file
|
||||
"
|
||||
k3s kubectl cp -n "$ns" -c "$app"-postgresql "$app-postgresql-0:tmp/$file" $folder$file
|
||||
|
||||
# Scale deployment back up
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue