Skip to content

Commit

Permalink
add db backup and restore workflow to devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tubo committed Nov 11, 2024
1 parent 9bc5262 commit 15e8d50
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
19 changes: 12 additions & 7 deletions .devcontainer/bashrc.override.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#
# .bashrc.override.sh
#
Expand All @@ -17,14 +16,20 @@ set +o nounset

alias makemigrations="python manage.py makemigrations"
alias migrate="python manage.py migrate"
alias reset_db="python manage.py reset_db && python manage.py drop_test_database && python manage.py migrate && python manage.py import resources/2021-2023.csv"
alias reset_db="python manage.py reset_db && python manage.py drop_test_database && python manage.py migrate && python manage.py import"

# start ssh-agent
# https://code.visualstudio.com/docs/remote/troubleshooting
eval "$(ssh-agent -s)"

npm install

# install flyctl
curl -L "https://fly.io/install.sh" | sh
export PATH="$HOME/.fly/bin:$PATH"
# Run npm install only for the first bash session
if [ ! -f ~/.npm_installed ]; then
npm install
touch ~/.npm_installed
fi

# install flyctl if not installed
if ! command -v flyctl &> /dev/null; then
curl -L "https://fly.io/install.sh" | sh
export PATH="$HOME/.fly/bin:$PATH"
fi
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
],
"features": {
"ghcr.io/devcontainers/features/node": {},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
"ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {
"version": "15"
}
},
// Tells devcontainer.json supporting services / tools whether they should run
// /bin/sh -c "while sleep 1000; do :; done" when starting the container instead of the container’s default command
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ License: MIT
## Back up and restore a database from fly.io

Start a proxy to fly postgres:
`flyctl proxy 54321:5432 --app app-name`
`flyctl proxy 54321:5432 --app radscheduler-db`

Set env for FLY_DATABASE_URL with credentials.
Find urls to postgres via:
`flyctl ssh console -C 'env'`

Download a dump:
`pg_dump -d $FLY_DATABASE_URL | gzip > backups/first.sql.gz`
`pg_dump -d postgres://radscheduler:{password}2localhost:54321 | gzip > backups/db.sql.gz`

Restore using
`docker-compose -f local.yml run postgres restore first.sql.gz`
`docker-compose -f local.yml run postgres restore db.sql.gz`

or

`docker exec radscheduler_local_postgres restore db.sql.gz`
2 changes: 0 additions & 2 deletions local.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

volumes:
radscheduler_local_postgres_data: {}
radscheduler_local_postgres_data_backups: {}
Expand Down

0 comments on commit 15e8d50

Please sign in to comment.