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

Commit

Permalink
Use long flag names and update readme to explain changing paths is an…
Browse files Browse the repository at this point in the history
… option
  • Loading branch information
aloftus23 committed Jun 28, 2022
1 parent b4d5731 commit 07a282a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,17 @@ Follow the instructions below to backup the P&E database instance and restore lo

In the P&E database environment:

- Add output path to: ./pe-reports/src/pe_reports/pe_db/pg_backup.sh
- If necessary, edit ./pe-reports/src/pe_reports/pe_db/pg_backup.sh and replace the
default output path ($PWD) with your preferred output path.
- Open terminal and run:
`bash ./pe-reports/src/pe_reports/pe_db/pg_backup.sh`
- Export resulting .zip file

In your local environment:

- Pull the latest repository
- Add path to the backup files: ./pe-reports/src/pe_reports/pe_db/pg_restore.sh
- If necessary, edit ./pe-reports/src/pe_reports/pe_db/pg_restore.sh and replace
the default path to the backup files ($PWD) with your preferred path.
- Start local postgres
- Run:
`bash ./pe-reports/src/pe_reports/pe_db/pg_restore.sh`
Expand Down
6 changes: 3 additions & 3 deletions src/pe_reports/pe_db/pg_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ zipfile=$path/pedb_dump_$(date +%m-%d-%Y).zip
mkdir -p "$backup_folder"

# Create globals backup
if pg_dumpall --globals-only --no-role-passwords -l "$PE_DB_NAME" -p "$PE_DB_PORT" -U "$PE_DB_USER" -h "$PE_DB_HOST" -w 2> "$errfile" > "$globalsqlfile"; then
if pg_dumpall --globals-only --no-role-passwords --database "$PE_DB_NAME" --port "$PE_DB_PORT" --username "$PE_DB_USER" --host "$DATABASE_HOST" --no-password 2> "$errfile" > "$globalsqlfile"; then
echo 'Globals dump created'
else
echo 'Globals pg_dump return non-zero code'
exit
fi

# Create backup
if pg_dump -d "$PE_DB_NAME" -p "$PE_DB_PORT" -U "$PE_DB_USER" -h "$PE_DB_HOST" -Fc -w 2> "$errfile" > "$sqlfile"; then
if pg_dump --dbname "$PE_DB_NAME" --port "$PE_DB_PORT" --username "$PE_DB_USER" --host "$DATABASE_HOST" --format custom --no-password 2> "$errfile" > "$sqlfile"; then
echo 'PG dump created'
else
echo 'pg_dump return non-zero code'
exit
fi

# Zip folder
zip -r "$zipfile" "$backup_folder"
zip --recurse-paths "$zipfile" "$backup_folder"
10 changes: 5 additions & 5 deletions src/pe_reports/pe_db/pg_restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ set -o pipefail
# Set path to pg dump and globals backup files. ex: /Users/user/Desktop/backups
path=$PWD

dropdb pe -h localhost -U postgres --if-exists
dropdb pe ---host localhost --username postgres --if-exists

globalsql=$path/pedb_globals.sql
dumpsql=$path/pedb_dump.sql

psql -U postgres -h localhost -c "CREATE DATABASE pe;"
psql --username postgres --host localhost --command "CREATE DATABASE pe;"

# rdsadmin database (even if empty) is required for the next script
psql -U postgres -h localhost -c "CREATE DATABASE rdsadmin;"
psql --username postgres --host localhost --command "CREATE DATABASE rdsadmin;"

psql -U postgres -h localhost pe < "$globalsql"
psql --username postgres --host localhost pe < "$globalsql"

pg_restore -U postgres -h localhost -d pe "$dumpsql"
pg_restore --username postgres --host localhost --dbname pe "$dumpsql"

0 comments on commit 07a282a

Please sign in to comment.