Skip to content

Commit

Permalink
chore: backup, migrate, restore scripts
Browse files Browse the repository at this point in the history
docker and deploy tweaks; readme

resolves #1
  • Loading branch information
adekbadek committed Nov 16, 2017
1 parent 929560c commit 17d1534
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ client/build
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.env
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,24 @@ npm install
npm start
```

This project uses [commitizen](https://commitizen.github.io/cz-cli/), please commit with `npm run commit`
This project uses [commitizen](https://commitizen.github.io/cz-cli/), commit with `npm run commit`

## testing

```shell
cd client/
npm t
```

## running on production

to launch on production, run `docker-compose up -d`, and then:

start from scratch | restore backup
--- | ---
`bash ./scripts/migrate.sh` | `bash ./scripts/restore.sh`

to backup the DB (while the container is running), run:
```
bash ./scripts/backup.sh
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"scripts": {
"start": "concurrently --prefix \"{name}\" --names \"RAILS,REACT,CSS\" -c \"bgBlue,black.bgGreen,black.bgYellow\" \"rails s -p 3001\" \"(cd client && npm run start)\" \"(cd client && npm run watch-css)\"",
"deploy": "rsync -avz -e 'ssh' --exclude-from '.rsync-exclude' . scylla:/home/scylla/books",
"deploy": "rsync -avz -e 'ssh' --exclude-from '.rsync-exclude' . ostia:/home/ostia/books",
"build:deploy": "npm run build && npm run deploy",
"build": "(cd client && npm run build)",
"postinstall": "cd client/ && yarn install",
Expand Down
7 changes: 7 additions & 0 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mkdir -p backup

_now=$(date +"%m_%d_%Y"_"%H_%M_%S")
_file="backup/data_$_now.sql"

# using `--inserts` to avoid '\N' problems https://stackoverflow.com/a/37531223/3772847
docker-compose exec postgres sh -c 'pg_dumpall --inserts -c -U postgres' > $_file
1 change: 1 addition & 0 deletions scripts/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose exec api sh -c 'bundle exec rails db:migrate'
7 changes: 7 additions & 0 deletions scripts/restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cd backup
# get the most recent file
dump_file=$(ls -t . | head -1 )

printf "\nrestoring from "$dump_file"\n\n"

egrep -v '^(CREATE|DROP) ROLE postgres;' $dump_file | docker-compose exec postgres psql -U postgres

0 comments on commit 17d1534

Please sign in to comment.