Skip to content

Commit

Permalink
feat: self-hosted db backup and snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
neilsong committed Oct 29, 2024
1 parent 81eca4a commit 6bf6810
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ferry_db_snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Ferry DB Snapshot

on:
push:
branches: [main]
paths:
- 'db/**'
- '.github/workflows/ferry_db_snapshot.yml'
schedule:
- cron: '0 0 * * 1' # Every Monday
workflow_dispatch:

jobs:
backup:
runs-on: self-hosted
steps:
- name: Dump Ferry DB
run: |
docker exec db pg_dump -U postgres -x postgres > "/home/app/ferry_snapshots/$(date +%F).sql"
- name: Upload to R2
run: |
rclone copy "/home/app/ferry_snapshots/$(date +%F).sql" r2:ferry-backup/
- name: Create R2 Signed URL
run: |
rclone link "r2:ferry-backup/$(date +%F).sql" | grep -o 'https://[^"]*' > output.txt
- name: Update Doppler Secret
run: |
doppler setup -p coursetable -c dev
doppler secrets set FERRY_DUMP_URL="$(cat output.txt)"
- name: Delete Old Snapshots
run: |
find /home/app/ferry_snapshots -type f -mtime +30 -delete
rclone delete r2:ferry-backup/ --min-age 30d
19 changes: 19 additions & 0 deletions .github/workflows/user_db_backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: User DB Backup

on:
push:
branches: [main]
paths:
- 'db/**'
- '.github/workflows/user_db_backup.yml'
schedule:
- cron: '0 0 * * 0' # Every Sunday
workflow_dispatch:

jobs:
backup:
runs-on: self-hosted
steps:
- name: Backup User DB
run: |
bash home/app/infra/db/cron_script.sh
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ Below is the list of every network and its attached services (including those de
- Container Name / Docker Hostname: `traefik`
- Purpose: Reverse proxy router for all incoming requests
- Access: Public (*coursetable.com)
- **[`mysql`](mysql/)**
- `mysql`
- Container Name / Docker Hostname: `${MYSQL_HOST}`
- Purpose: Standing MySQL DB for all user data
- Access: Local
- `phpmyadmin`
- Container Name / Docker Hostname:`phpmyadmin`
- Purpose: PHP My Admin GUI for MySQL DB
- Access: Authorized Public [pma.coursetable.com](https://pma.coursetable.com)
- **[`ferry`](ferry/)**
- **[`db`](db/)**
- `db`
- Container Name / Docker Hostname: `${FERRY_HOST}`
- Purpose: Standing Postgres DB for all course data (see [ferry](https://github.com/coursetable/ferry/))
- Container Name / Docker Hostname: `${DB_HOST?db}`
- Purpose: Standing Postgres DB for all course data (see [ferry](https://github.com/coursetable/ferry/)) and user data
- Access: Local
- `pgadmin`
- Container Name / Docker Hostname: `pgadmin`
- Purpose: DB Management GUI
- Access: Authorized Public
- `pgbouncer`
- Container Name / Docker Hostname: `pgbouncer`
- Purpose: Connection pooler for Postgres DB
- Access: Authorized Public
- **[`${API_NETWORK}`](https://github.com/coursetable/coursetable/tree/master/api/)**
- `api`
Expand Down

0 comments on commit 6bf6810

Please sign in to comment.