Skip to content

Commit

Permalink
Merge pull request #93 from SEL-Columbia/0.3.5-dev
Browse files Browse the repository at this point in the history
0.3.5 dev
  • Loading branch information
jmbott authored Nov 26, 2019
2 parents 3a3b6c7 + d623d85 commit f13dcc7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<your_email_address>
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 <BACKUP name> <USER>@<HOSTNAME>:<PATH on server>
```

* 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)
```
2 changes: 1 addition & 1 deletion prod/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 11 additions & 10 deletions prod/install.sh
Original file line number Diff line number Diff line change
@@ -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?
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 -
Expand Down

0 comments on commit f13dcc7

Please sign in to comment.