-
Notifications
You must be signed in to change notification settings - Fork 16
143 lines (127 loc) · 4.29 KB
/
Copy pathdb-backup.yml
File metadata and controls
143 lines (127 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Database Dump
on:
schedule:
- cron: '0 0 * * 1' # Every Monday at midnight UTC
workflow_dispatch:
permissions: {}
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
jobs:
preflight:
name: Preflight
timeout-minutes: 5
runs-on: ubuntu-latest
permissions:
contents: read # Tag-collision check
outputs:
dump-file: ${{ steps.names.outputs.dump-file }}
tag: ${{ steps.names.outputs.tag }}
date: ${{ steps.names.outputs.date }}
steps:
- name: Compute dump name and release tag
id: names
run: |
set -euo pipefail
DATE="$(date -u +%Y-%m-%d)"
{
echo "date=${DATE}"
echo "dump-file=inferencex-${DATE}.dump.zst"
echo "tag=db-dump/${DATE}"
} >> "$GITHUB_OUTPUT"
- name: Fail fast if the release tag already exists
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.names.outputs.tag }}
run: |
set -euo pipefail
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "::error::Release $TAG already exists; delete it first to re-dump for the same date."
exit 1
fi
dump:
name: Dump and compress
needs: preflight
timeout-minutes: 180
runs-on: ubuntu-latest
steps:
- name: Dump, compress, and split database
env:
DATABASE_URL: ${{ secrets.DATABASE_WRITE_URL }}
DUMP_FILE: ${{ needs.preflight.outputs.dump-file }}
run: |
set -euo pipefail
docker run --rm --env DATABASE_URL \
postgres:18-alpine@sha256:9a8afca54e7861fd90fab5fdf4c42477a6b1cb7d293595148e674e0a3181de15 \
sh -ceu 'exec pg_dump \
--dbname="$DATABASE_URL" \
--format=custom \
--compress=none \
--no-owner \
--no-privileges \
--exclude-table-data=public.user_feedback \
--verbose' \
| zstd -v -T0 -19 --long=27 \
| split -b 1900m -d -a 2 - "${DUMP_FILE}.part"
- name: Verify compressed stream
env:
DUMP_FILE: ${{ needs.preflight.outputs.dump-file }}
run: |
set -euo pipefail
cat "${DUMP_FILE}".part* | zstd -t --long=27
- name: Checksum parts
env:
DUMP_FILE: ${{ needs.preflight.outputs.dump-file }}
run: |
set -euo pipefail
sha256sum "${DUMP_FILE}".part* > SHA256SUMS
cat SHA256SUMS
- name: Upload dump parts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: db-dump-parts
path: |
inferencex-*.dump.zst.part*
SHA256SUMS
if-no-files-found: error
retention-days: 1
compression-level: 0
release:
name: Create release
needs: [preflight, dump]
timeout-minutes: 30
runs-on: ubuntu-latest
permissions:
contents: write # Create the database dump release
steps:
- name: Download dump parts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: db-dump-parts
- name: Verify checksums
run: |
set -euo pipefail
sha256sum -c SHA256SUMS
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.preflight.outputs.tag }}
DATE: ${{ needs.preflight.outputs.date }}
DUMP_GLOB: ${{ needs.preflight.outputs.dump-file }}.part*
run: |
set -euo pipefail
cat > release-notes.md <<'EOF'
Weekly InferenceX database dump.
Verify (optional):
`sha256sum -c SHA256SUMS`
Reassemble and decompress:
`cat *.dump.zst.part* | zstd -d --long=27 > inferencex.dump`
Restore to PostgreSQL or Neon:
`pg_restore --exit-on-error --clean --if-exists --no-owner --no-privileges --dbname="YOUR_TARGET_DATABASE_URL" inferencex.dump`
EOF
# shellcheck disable=SC2086
gh release create "$TAG" $DUMP_GLOB SHA256SUMS \
--repo "$GITHUB_REPOSITORY" \
--title "DB Dump $DATE" \
--notes-file release-notes.md \
--latest=false