[ADD] Restore command for Launch script

This commit is contained in:
Olivier DOSSMANN 2016-01-13 09:13:09 +01:00
parent d27d04398a
commit c9b36bf736

View File

@ -49,8 +49,8 @@ show_help() {
echo -e " - create Create postgreSQL database volume and postgreSQL Docker container"
echo -e " - init Create project directory as python virtual environment, fetch git repository and install Python dependancies"
echo -e " - migrate Launch migration command: python manage.py migrate"
echo -e " - restore "
echo -e " - start Launch Gissmo Docker container (created by 'create' command) with a name given in GISSMO_DOCKER_NAME variable"
echo -e " - restore dump Restore the given dump"
echo -e " - start args Launch Gissmo Docker container (created by 'create' command) with a name given in GISSMO_DOCKER_NAME variable"
echo -e " - stop Stop Gissmo Docker container which name is GISSMO_DOCKER_NAME variable content"
# TODO: Add clean() command to STOP and DELETE Gissmo Docker container
# TODO: Add clean_db() command to STOP and DELETE postgreSQL Docker container
@ -155,8 +155,27 @@ migrate() {
$docker_cmd run -it --rm --link ${POSTGRES_DOCKER_NAME}:db gissmo:${GISSMO_VERSION} python manage.py migrate || error_and_quit "Failed to launch Gissmo migration."
}
test_restore() {
if test -z $ARGS; then
error_and_quit "Missing database dump file"
fi
if ! test -f "$ARGS"; then
error_and_quit "File '${ARGS}' not found."
fi
DUMP_FILE=`basename $ARGS`
info "Dump file found: ${DUMP_FILE}"
DUMP_DIR="${ARGS%/*}"
}
restore() {
not_implemented
test_create
test_restore
$docker_cmd stop ${POSTGRES_DOCKER_NAME} && $docker_cmd rm ${POSTGRES_DOCKER_NAME} || error_and_quit "Failed to stop and delete postgreSQL Docker container: ${POSTGRES_DOCKER_NAME}"
sudo rm -rf ${DB_DIR} || error_and_quit "Failed to delete this directory: ${DB_DIR}"
$docker_cmd run -d --volumes-from "${DB_VOLUME_NAME}" --name "${POSTGRES_DOCKER_NAME}" "postgres:${POSTGRES_VERSION}" || error_and_quit "Launching database docker container failed."
sleep 6 # to wait about docker container runs totally
RESTORE_COMMAND="$docker_cmd run -it --rm --link ${POSTGRES_DOCKER_NAME}:db -v ${DUMP_DIR}:/backup -e PGHOST=`$docker_cmd inspect -f \"{{ .NetworkSettings.IPAddress }}\" ${POSTGRES_DOCKER_NAME}` -e PGUSER=postgres postgres:${POSTGRES_VERSION} pg_restore -d postgres /backup/${DUMP_FILE}"
exec $RESTORE_COMMAND || error_and_quit "Failed to launch this command: ${CMD}"
}
test_start() {