fp/scripts/postgres-restore.sh

33 lines
1.5 KiB
Bash
Raw Normal View History

2024-05-29 23:43:47 +00:00
#!/bin/bash
2024-07-23 02:59:41 +00:00
postgres_pod_name="postgresql-primary-0"
2024-07-06 08:49:51 +00:00
dbname=20240704T204659Z_development.psql
2024-05-27 22:20:58 +00:00
## drop futureporn_db
2024-07-23 02:59:41 +00:00
kubectl -n futureporn exec "${postgres_pod_name}" -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres --command "DROP DATABASE futureporn_db;"
2024-05-27 22:20:58 +00:00
## create futureporn_db
2024-07-23 02:59:41 +00:00
kubectl -n futureporn exec "${postgres_pod_name}" -- env PGPASSWORD=${POSTGRES_PASSWORD} psql -U postgres --command "\
2024-05-27 22:20:58 +00:00
CREATE DATABASE futureporn_db \
WITH \
OWNER = postgres \
ENCODING = 'UTF8' \
LOCALE_PROVIDER = 'libc' \
CONNECTION LIMIT = -1 \
IS_TEMPLATE = False;"
## 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
2024-07-23 02:59:41 +00:00
kubectl -n futureporn cp /home/cj/Documents/futureporn-meta/backups/$dbname "${postgres_pod_name}":/tmp/db.psql
kubectl -n futureporn exec -i "${postgres_pod_name}" -- env PGPASSWORD=${POSTGRES_PASSWORD} pg_restore -U postgres -d futureporn_db /tmp/db.psql
2024-06-20 01:43:25 +00:00
# kubectl -n futureporn exec -ti db-postgresql-0 -- rm /tmp/db.psql