From 2e3a7d58731f626e610f2ff14aea634dac7777a4 Mon Sep 17 00:00:00 2001 From: jmbott Date: Tue, 26 Nov 2019 17:30:35 -0500 Subject: [PATCH 1/2] install fix --- README.md | 30 ++++++++++++++++++++++++++++++ prod/install.sh | 15 ++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6fd590b..8010b64 100644 --- a/README.md +++ b/README.md @@ -45,3 +45,33 @@ Created user with e-mail your_email_address $ docker exec dev_minigrid_1 dev/commands.py create_user --db_host=db --kwarg email= Created user with e-mail your_email_address ``` + +## Restoring Database from backup + +* download backup, from S3 or otherwise +* use `scp` to copy the db from your host computer to the new server, + +``` +$ scp @: +``` + +* break connections, remove old db, and recreate so its blank + +``` +$ docker exec root_db_1 psql -U postgres -d minigrid -c "SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid();" +$ docker exec root_db_1 psql -U postgres -c "DROP DATABASE minigrid" +$ docker exec root_db_1 psql -U postgres -c "CREATE DATABASE minigrid" +``` + +* copy backup into the database container + +``` +$ docker cp demo.sharedsolar.org-db-bak-11-26.pg root_db_1:/demo.sharedsolar.org-db-bak-11-26.pg +``` + +* restore the backup and restart the containers + +``` +$ docker exec root_db_1 psql -U postgres -d minigrid --set ON_ERROR_STOP=on -f demo.sharedsolar.org-db-bak-11-26.pg +$ docker restart $(docker ps -a -q) +``` diff --git a/prod/install.sh b/prod/install.sh index 9a9d977..1a7e67c 100755 --- a/prod/install.sh +++ b/prod/install.sh @@ -134,7 +134,8 @@ if [ -f /etc/redhat-release ] ; then fi $DOCKER_COMPOSE up -d MINIGRID_CONTAINER_NAME=$($DOCKER_COMPOSE ps | grep _minigrid_ | cut -d' ' -f1) -sleep 4 +printf "pause for 10 seconds... \n" +sleep 10 docker exec $MINIGRID_CONTAINER_NAME ""prod/create_initial_user.py --db-host=db $ADMIN_EMAIL"" docker exec $MINIGRID_CONTAINER_NAME ""prod/create_payment_ids.py --db-host=db"" NGINX_CONTAINER_NAME=$($DOCKER_COMPOSE ps | grep _nginx_ | cut -d' ' -f1) @@ -167,18 +168,18 @@ printf " \n" printf "========================================\n" printf "[Y/n]:\n>>> " read REPLY -if [[ $REPLY =~ ^[Yy]$ ]] +found=`echo $REPLY | grep -coP '^[Yy]$'` +if [ $found -ne 0 ]; then # install awscli - printf "Installing the awscli" - $SUDO apt-get install awscli -qq > /dev/null + printf "Installing the awscli \n" + $SUDO apt-get install awscli -qq # Ask for AWS bucket name printf "========================================\n" printf " Please enter your AWS backup bucket \n" printf " name. \n" - printf " \n" printf "========================================\n" printf "Bucket:\n>>> " read BUCKET @@ -207,8 +208,8 @@ then # Backup database every week at 2:15 DB_CONTAINER_NAME=$($DOCKER_COMPOSE ps | grep _db_ | cut -d' ' -f1) CRON_CMD_2="mkdir -p /db-bak && "\ - "docker exec $DB_CONTAINER_NAME pg_dump -U postgres minigrid > /db-bak/$LETSENCRYPT_DIR-db-bak.pg && "\ - "aws s3 cp /db-bak/$LETSENCRYPT_DIR-db-bak.pg s3://$AWS_BUCKET/$LETSENCRYPT_DIR-db-$(date +%d-%m-%y).pg" +"docker exec $DB_CONTAINER_NAME pg_dump -U postgres minigrid > /db-bak/$LETSENCRYPT_DIR-db-bak.pg && "\ +"aws s3 cp /db-bak/$LETSENCRYPT_DIR-db-bak.pg s3://$AWS_BUCKET/$LETSENCRYPT_DIR-db-\$(date +%d-%m-%y).pg" CRON_JOB_2="15 2 * * 0 $CRON_CMD_2" crontab -l | fgrep -i -v "$CRON_CMD_2" | { cat; echo "$CRON_JOB_2"; } | crontab - From d623d85d1922b1be1ad3b964383ea0a834004d5e Mon Sep 17 00:00:00 2001 From: jmbott Date: Tue, 26 Nov 2019 17:33:02 -0500 Subject: [PATCH 2/2] version bump --- prod/docker-compose.yml | 2 +- prod/install.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/prod/docker-compose.yml b/prod/docker-compose.yml index 25d22a4..ca9b41b 100644 --- a/prod/docker-compose.yml +++ b/prod/docker-compose.yml @@ -1,7 +1,7 @@ version: '2' services: minigrid: - image: selcolumbia/minigrid-server:0.3.4 + image: selcolumbia/minigrid-server:0.3.5 command: ./prod/run.sh --db_host=db --redis_url=redis://redis:6379/0 --minigrid-website-url=https://www.example.com depends_on: - redis diff --git a/prod/install.sh b/prod/install.sh index 1a7e67c..c7c99bf 100755 --- a/prod/install.sh +++ b/prod/install.sh @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# Minigrid Server installer for version 0.3.4 +# Minigrid Server installer for version 0.3.5 set -e # Do you have docker installed? @@ -108,8 +108,8 @@ $SUDO openssl dhparam -out /etc/letsencrypt/live/$LETSENCRYPT_DIR/dhparam.pem 20 printf "========================================\n" printf " Generating configuration \n" printf "========================================\n" -$CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.3.4/prod/docker-compose.yml > docker-compose.yml -$CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.3.4/prod/nginx.conf > nginx.conf +$CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.3.5/prod/docker-compose.yml > docker-compose.yml +$CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.3.5/prod/nginx.conf > nginx.conf sed -i s/www.example.com/$LETSENCRYPT_DIR/g docker-compose.yml sed -i s/www.example.com/$LETSENCRYPT_DIR/g nginx.conf