From a215e064cd5dbdc3c7bce34e0fbf8008836e3a11 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 26 Jul 2018 16:29:30 +0200 Subject: [PATCH] new: [postgres] added ``save`` action --- postgres/actions/save | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 postgres/actions/save diff --git a/postgres/actions/save b/postgres/actions/save new file mode 100755 index 0000000..d241fb9 --- /dev/null +++ b/postgres/actions/save @@ -0,0 +1,61 @@ +#!/bin/bash + +## Load action gets a first argument a DIRECTORY holding the necessary files. +## +## + +if [ -z "$SERVICE_DATASTORE" ]; then + echo "This script is meant to be run through 'compose' to work properly." >&2 + exit 1 +fi + +usage="$exname [-h|--help] DBNAME DEST" + +dbname= +postgis= +while [ "$1" ]; do + case "$1" in + "--help"|"-h") + print_usage + exit 0 + ;; + *) + [ -z "$dbname" ] && { dbname=$1 ; shift ; continue ; } + [ -z "$DEST" ] && { DEST=$1 ; shift ; continue ; } + err "Unexpected argument '$1'." + exit 1 + ;; + esac + shift +done + + +if [ -z "$dbname" ]; then + err "You must provide a source database name as first argument." + print_usage + exit 1 +fi + +if [ -z "$DEST" ]; then + err "You must provide a dest file as second argument." + print_usage + exit 1 +fi + +if [[ "$dbname" == *"@"* ]]; then + IFS="@" read user dbname < <(echo "$dbname") +fi + +. "$CHARM_PATH"/lib/common + +set -e + +if ! db_has_database "$dbname"; then + err "Can't find database '$dbname'." + exit 1 +fi + +PGM cp "$dbname" "$DEST" || { + die "pgm command failed !" +} +info "Saved database '$dbname' into '$DEST'." \ No newline at end of file