Skip to content

Commit

Permalink
Removed backupSchema option until further development
Browse files Browse the repository at this point in the history
Signed-off-by: Emiliano Suñé <emiliano.sune@gmail.com>
  • Loading branch information
esune committed Jan 16, 2025
1 parent c6a8a60 commit 5b17a50
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/backup.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# Full Example:
# -----------------------------------------------------------
# postgres=postgresql:5432/TheOrgBook_Database
# postgres=postgresql:5432/mydb?backupSchema=my_schema&verifySchema=my_schema
# postgres=postgresql:5432/mydb?verifySchema=my_schema
# mongo=mender-mongodb:27017/useradm
# postgres=wallet-db/tob_issuer
# mssql=pims-db-dev:1433/pims
Expand Down
6 changes: 4 additions & 2 deletions docker/backup.config.utils
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ function getDatabaseName(){
function getSchema(){
(
_databaseSpec=${1}
_backupMode=${2:-'backup'}
_backupMode=${2:-'verify'}
_schema=""

if [ "${_backupMode}" == 'backup' ]; then
_schema=$(echo ${_databaseSpec} | sed -n 's~^.*backupSchema=\([^&]*\).*~\1~p')
# Currently not in use, needs more tweaks to be used.
# _schema=$(echo ${_databaseSpec} | sed -n 's~^.*backupSchema=\([^&]*\).*~\1~p')
echoYellow "Backing up only a specific schema is not supported yet."
elif [ "${_backupMode}" == 'verify' ]; then
_verifySchema=$(echo ${_databaseSpec} | sed -n 's~^.*verifySchema=\([^&]*\).*~\1~p')
_schema="${_verifySchema:-$TABLE_SCHEMA}"
Expand Down
10 changes: 2 additions & 8 deletions docker/backup.postgres.plugin
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,15 @@ function onBackupDatabase(){

_hostname=$(getHostname ${_databaseSpec})
_database=$(getDatabaseName ${_databaseSpec})
_schema=$(getSchema ${_databaseSpec} 'backup')
_port=$(getPort ${_databaseSpec})
_portArg=${_port:+"-p ${_port}"}
_username=$(getUsername ${_databaseSpec})
_password=$(getPassword ${_databaseSpec})

# Add schema to backup command, if specified
if [ ! -z "${_schema}" ]; then
_schemaLog="schema '${_schema}' in "
_schemaParam="-n ${_schema} "
fi
echoGreen "Backing up ${_schemaLog}'${_hostname}${_port:+:${_port}}${_database:+/${_database}}' to '${_backupFile}' ..."
echoGreen "Backing up '${_hostname}${_port:+:${_port}}${_database:+/${_database}}' to '${_backupFile}' ..."

export PGPASSWORD=${_password}
pg_dump -Fp -h "${_hostname}" ${_portArg} -U "${_username}" "${_schemaParam}""${_database}" > "${BACKUP_DIR}backup.sql"
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"

# post-process roles.sql to remove the "CREATE ROLE" and "ALTER ROLE" statements for the default roles
Expand Down

0 comments on commit 5b17a50

Please sign in to comment.