Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 72c6f84

Browse files
dmiusDmitry
authored andcommitted
dump as text + gz\bz2\sql file
1 parent 841e5ee commit 72c6f84

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

nancy_run.sh

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,20 @@ function checkParams() {
375375
exit 1
376376
fi
377377

378-
[ ! -z ${DB_DUMP_PATH+x} ] && ! checkPath DB_DUMP_PATH \
379-
&& >&2 echo "ERROR: file $DB_DUMP_PATH given by db_dump_path not found" \
380-
&& exit 1
378+
if [ ! -z ${DB_DUMP_PATH+x} ]; then
379+
checkPath DB_DUMP_PATH
380+
if [ "$?" -ne "0" ]; then
381+
echo "$DB_DUMP_PATH" > $TMP_PATH/db_dump_tmp.sql
382+
DB_DUMP_PATH="$TMP_PATH/db_dump_tmp.sql"
383+
else
384+
[ "$DEBUG" -eq "1" ] && echo "DEBUG: Value given as db-dump-path will use as filename"
385+
fi
386+
DB_DUMP_FILENAME=$(basename $DB_DUMP_PATH)
387+
DB_DUMP_EXT=${DB_DUMP_FILENAME##*.}
388+
else
389+
echo "ERROR: file $DB_DUMP_PATH given by db_dump_path not found"
390+
exit 1
391+
fi
381392

382393
if [ -z ${PG_CONFIG+x} ]; then
383394
>&2 echo "WARNING: No DB config provided. Using default one."
@@ -684,8 +695,21 @@ function copyFile() {
684695
## Apply machine features
685696
# Dump
686697
sleep 2 # wait for postgres up&running
687-
DB_DUMP_FILENAME=$(basename $DB_DUMP_PATH)
688-
docker_exec bash -c "bzcat $MACHINE_HOME/$DB_DUMP_FILENAME | psql --set ON_ERROR_STOP=on -U postgres test"
698+
699+
case "$DB_DUMP_EXT" in
700+
sql)
701+
docker_exec bash -c "cat $MACHINE_HOME/$DB_DUMP_FILENAME | psql --set ON_ERROR_STOP=on -U postgres test"
702+
;;
703+
bz2)
704+
docker_exec bash -c "bzcat $MACHINE_HOME/$DB_DUMP_FILENAME | psql --set ON_ERROR_STOP=on -U postgres test"
705+
;;
706+
gz)
707+
docker_exec bash -c "zcat $MACHINE_HOME/$DB_DUMP_FILENAME | psql --set ON_ERROR_STOP=on -U postgres test"
708+
;;
709+
esac
710+
711+
exit 1;
712+
689713
# After init database sql code apply
690714
echo "Apply sql code after db init"
691715
if ([ ! -z ${AFTER_DB_INIT_CODE+x} ] && [ "$AFTER_DB_INIT_CODE" != "" ])

0 commit comments

Comments
 (0)