[ADD] Restore command for Launch script
This commit is contained in:
parent
d27d04398a
commit
c9b36bf736
25
launch.sh
25
launch.sh
@ -49,8 +49,8 @@ show_help() {
|
|||||||
echo -e " - create Create postgreSQL database volume and postgreSQL Docker container"
|
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 " - 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 " - migrate Launch migration command: python manage.py migrate"
|
||||||
echo -e " - restore "
|
echo -e " - restore dump Restore the given dump"
|
||||||
echo -e " - start Launch Gissmo Docker container (created by 'create' command) with a name given in GISSMO_DOCKER_NAME variable"
|
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"
|
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() command to STOP and DELETE Gissmo Docker container
|
||||||
# TODO: Add clean_db() command to STOP and DELETE postgreSQL 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."
|
$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() {
|
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() {
|
test_start() {
|
||||||
|
Loading…
Reference in New Issue
Block a user