fp/scripts/postgres-backup.sh

23 lines
1.4 KiB
Bash

#!/bin/bash
## restore
# kubectl -n futureporn exec postgres -- psql -U postgres -d futureporn_db -f - < "/home/cj/Documents/futureporn-meta/backups/2024-05-21_21-44-35-futureporn-db.psql"
# kubectl -n futureporn exec -it postgres -- bash -c "psql -U postgres futureporn_db -f /home/cj/Documents/futureporn-meta/backups/2024-05-21_21-44-35-futureporn-db.psql"
# kubectl -n futureporn exec -i postgres -- pg_restore -U postgres -d futureporn_db < /home/cj/Documents/futureporn-meta/backups/2024-05-21_21-44-35-futureporn-db.psql
# kubectl exec -i POD_NAME -- pg_restore -U USERNAME -C -d DATABASE < dump.sql
# kubectl -n futureporn cp /home/cj/Documents/futureporn-meta/backups/2024-05-29-futureporn_db-dev.psql postgres:/tmp/db.psql
# kubectl -n futureporn exec -i postgres -- pg_restore -U postgres -d futureporn_db /tmp/db.psql
# kubectl -n futureporn exec -ti db-postgresql-0 -- rm /tmp/db.psql
datestamp=$(date -u "+%Y%m%dT%H%M%SZ")
outputfilename="${datestamp}_development.psql"
outputfullpath="/tmp/${outputfilename}"
kubectl -n futureporn exec -i postgres -- pg_dump --file "${outputfullpath}" --port "5432" --username "postgres" --no-password --format=c --large-objects --verbose "futureporn_db"
echo "outputfilename=${outputfilename}, outputfullpath=${outputfullpath}"
kubectl -n futureporn cp "postgres:${outputfullpath}" "/home/cj/Documents/futureporn-meta/backups/${outputfilename}"