Skip to content

Commit

Permalink
Merge pull request #125 from jujaga/bugfix/targz
Browse files Browse the repository at this point in the history
Revert postgres plugin to use gzip and gunzip
  • Loading branch information
WadeBarnes authored Mar 1, 2024
2 parents cbb866a + eda584f commit b18c486
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions docker/backup.postgres.plugin
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function onBackupDatabase(){

export PGPASSWORD=${_password}
pg_dump -Fp -h "${_hostname}" ${_portArg} -U "${_username}" "${_database}" > "${BACKUP_DIR}backup.sql"
pg_dumpall -h "${_hostname}" ${_portArg} -U "${_username}" --roles-only --no-role-passwords > "${BACKUP_DIR}roles.sql"
tar -C ${BACKUP_DIR} -cvzf ${_backupFile} backup.sql roles.sql
pg_dumpall -h "${_hostname}" ${_portArg} -U "${_username}" --roles-only --no-role-passwords > "${BACKUP_DIR}roles.sql"
cat "${BACKUP_DIR}roles.sql" "${BACKUP_DIR}backup.sql" | gzip > ${_backupFile}
rm "${BACKUP_DIR}roles.sql" && rm "${BACKUP_DIR}backup.sql"
return ${PIPESTATUS[0]}
)
Expand Down Expand Up @@ -94,10 +94,7 @@ function onRestoreDatabase(){

# Restore
if (( ${_rtnCd} == 0 )); then
tar -xzvf "${_fileName}" -C ${BACKUP_DIR}
psql ${_stopOnErrors} -x -h "${_hostname}" ${_portArg} -d "${_database}" < "${BACKUP_DIR}roles.sql"
psql ${_stopOnErrors} -x -h "${_hostname}" ${_portArg} -d "${_database}" < "${BACKUP_DIR}backup.sql"
rm "${BACKUP_DIR}roles.sql" && rm "${BACKUP_DIR}backup.sql"
gunzip -c "${_fileName}" | psql ${_stopOnErrors} -x -h "${_hostname}" ${_portArg} -d "${_database}"
# Get the status code from psql specifically. ${?} would only provide the status of the last command, psql in this case.
_rtnCd=${PIPESTATUS[1]}
fi
Expand Down

0 comments on commit b18c486

Please sign in to comment.