From: Thierry Parmentelat Date: Thu, 21 Nov 2024 10:04:35 +0000 (+0100) Subject: a more robust, and tested, way to restore the DBs X-Git-Tag: plcapi-7.2-5~3 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=8c3e2a29531ba076e5c5f354d5e48218feb10ceb;p=plcapi.git a more robust, and tested, way to restore the DBs --- diff --git a/plc.d/db b/plc.d/db index 49f177a2..66c173ec 100755 --- a/plc.d/db +++ b/plc.d/db @@ -102,14 +102,6 @@ function checkpoint_planetlab_db() { check } -function restore_planetlab_db() { - dumpfile=$1 - if [ -n "$dumpfile" ]; then - [ -f "$dumpfile" ] && psql -a -U $PLC_DB_USER $PLC_DB_NAME <$dumpfile - check - fi -} - # use a single date of this script invocation for the dump_*_db functions. DATE=$(date +"%Y-%m-%d-%H-%M-%S") @@ -126,14 +118,6 @@ function dump_planetlab_db() { checkpoint_planetlab_db $dumpfile } -function restore_drupal_db() { - dumpfile=$1 - if [ -n "$dumpfile" ]; then - [ -f "$dumpfile" ] && psql -a -U $PLC_DB_USER drupal <$1 - check - fi -} - function checkpoint_drupal_db() { local dumpfile="$1"; shift pg_dump -U $PLC_DB_USER drupal >$dumpfile @@ -146,6 +130,22 @@ function dump_drupal_db() { check } +function restore_planetlab_db() { + local dumpfile="$1"; shift + [[ -z "$dumpfile" ]] && { echo "Usage: $0 restore (planetlab5) "; return 1; } + psql -U postgres -c "DROP DATABASE $PLC_DB_NAME" + createdb -U postgres --template=template0 --encoding=UNICODE --owner=$PLC_DB_USER $PLC_DB_NAME + psql -a -U $PLC_DB_USER $PLC_DB_NAME -f $dumpfile +} + +function restore_drupal_db() { + local dumpfile="$1"; shift + [[ -z "$dumpfile" ]] && { echo "Usage: $0 restore (drupal) "; return 1; } + psql -U postgres -c "DROP DATABASE drupal" + createdb -U postgres --template=template0 --encoding=UNICODE --owner=$PLC_DB_USER drupal + psql -a -U $PLC_DB_USER drupal -f $dumpfile +} + # Clean up old backups function clean_dump() { local days="$1"; shift