-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: self-hosted db backup and snapshot
- Loading branch information
Showing
3 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters