Added TrueCharts db tools
Copied from here:
https://truecharts.org/manual/SCALE/guides/sql-export/
Link to source of page:
https://github.com/truecharts/website/blame/main/docs/manual/SCALE/guides/sql-export.md#L13
Permalink in space/time:
30484d04f7/docs/manual/SCALE/guides/sql-export.md (L13)
This commit is contained in:
parent
9860c9a2d6
commit
121ac483ca
2 changed files with 65 additions and 0 deletions
37
tcdbbackup.sh
Executable file
37
tcdbbackup.sh
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
# 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}')
|
||||
|
||||
for ns in $namespaces; do
|
||||
# extract application name
|
||||
app=$(echo "$ns" | sed 's/^ix-//')
|
||||
|
||||
echo "Creating database backup for $app."
|
||||
|
||||
file="$app.sql"
|
||||
|
||||
# Scale down deployment to avoid inconsistencies in DB
|
||||
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 cp -n "$ns" -c "$app"-postgresql "$app-postgresql-0:tmp/$file" $folder$file
|
||||
|
||||
# Scale deployment back up
|
||||
k3s kubectl scale deploy "$app" -n "$ns" --replicas=1
|
||||
|
||||
if [ ! -f "$folder$file" ]; then
|
||||
>&2 echo "$folder$file does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "File $file created."
|
||||
|
||||
done
|
||||
|
||||
exit 0
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue