Skip to content

Commit

Permalink
install fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbott committed Nov 26, 2019
1 parent 408ee5f commit 2e3a7d5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 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)
```
15 changes: 8 additions & 7 deletions prod/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 2e3a7d5

Please sign in to comment.