forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (74 loc) · 2.62 KB
/
Copy pathdb-backup.yml
File metadata and controls
85 lines (74 loc) · 2.62 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
name: Database Backup
on:
schedule:
- cron: '0 2 * * *' # daily backup at 02:00 UTC
- cron: '0 3 * * 0' # weekly restore test on Sunday at 03:00 UTC
workflow_dispatch:
inputs:
run_restore_test:
description: 'Also run restore test'
type: boolean
default: false
jobs:
backup:
name: Backup PostgreSQL
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.event.schedule == '0 2 * * *'
steps:
- uses: actions/checkout@v7
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Install PostgreSQL client
run: sudo apt-get install -y postgresql-client
- name: Run backup
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
BACKUP_S3_BUCKET: ${{ secrets.BACKUP_S3_BUCKET }}
BACKUP_PASSPHRASE: ${{ secrets.BACKUP_PASSPHRASE }}
AWS_REGION: ${{ secrets.AWS_REGION }}
run: |
chmod +x scripts/db-backup.sh
scripts/db-backup.sh
restore-test:
name: Weekly Restore Test
runs-on: ubuntu-latest
if: >
github.event.schedule == '0 3 * * 0' ||
(github.event_name == 'workflow_dispatch' && inputs.run_restore_test == true)
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: restore_test
POSTGRES_PASSWORD: restore_test
POSTGRES_DB: restore_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v7
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Install PostgreSQL client
run: sudo apt-get install -y postgresql-client
- name: Run restore test
env:
BACKUP_S3_BUCKET: ${{ secrets.BACKUP_S3_BUCKET }}
BACKUP_PASSPHRASE: ${{ secrets.BACKUP_PASSPHRASE }}
AWS_REGION: ${{ secrets.AWS_REGION }}
TEST_DATABASE_URL: postgresql://restore_test:restore_test@localhost:5432/restore_test
run: |
chmod +x scripts/db-restore-test.sh
scripts/db-restore-test.sh