-
Notifications
You must be signed in to change notification settings - Fork 24
104 lines (85 loc) · 3.06 KB
/
restore-sanitized-db.yml
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
name: Restore Sanitized DB
concurrency: stage
on:
workflow_dispatch:
workflow_call:
schedule:
- cron: '50 1 * * MON' # At 01:50 UTC every Monday
jobs:
sanitize-db:
runs-on: ubuntu-latest
environment: ProductionRO
env:
MYSQL_ROOT_PASSWORD: root
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download DB backup
id: get-db
uses: ./.github/actions/get-db
with:
workflow: backup-db.yml
zip-password: ${{ secrets.BACKUP_PASSWORD }}
- name: Load DB
run: cat ${{ steps.get-db.outputs.db-dump-file }} | /usr/bin/mysql -h 127.0.0.1 -u root -p$MYSQL_ROOT_PASSWORD
- uses: actions/checkout@v3
- name: Remove PII
run: |
# execute SQL script with PII removal
cat $GITHUB_WORKSPACE/mysql/sanitize-db.sql | \
/usr/bin/mysql -h 127.0.0.1 -u root -p$MYSQL_ROOT_PASSWORD --database orbitar_db
- name: Dump database
run: |
mysqldump --host 127.0.0.1 --column-statistics=0 --default-character-set=utf8mb4 --single-transaction \
--add-drop-database --databases orbitar_db activity_db -u root -p$MYSQL_ROOT_PASSWORD > stage-backup.sql
- name: Compress database
env:
STAGING_BACKUP_PASSWORD: ${{ secrets.STAGING_BACKUP_PASSWORD }}
run: |
pwd
ls -la
zip -m -P $STAGING_BACKUP_PASSWORD stage-backup.zip stage-backup.sql
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: stage-backup
path: stage-backup.zip
if-no-files-found: error
restore-db:
needs: sanitize-db
environment: Staging
runs-on: [self-hosted, stage]
steps:
- uses: actions/checkout@v3
- name: Download DB backup
uses: ./.github/actions/get-db
id: get-db
with:
zip-password: ${{ secrets.STAGING_BACKUP_PASSWORD }}
- name: Stop backend
working-directory: /orbitar
run: docker compose -f docker-compose.ssl.local.yml stop backend
- name: Restore backup
working-directory: /orbitar
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
run: |
docker compose -f docker-compose.ssl.local.yml exec -T mysql /usr/bin/mysql \
-u root --password=$MYSQL_ROOT_PASSWORD --default-character-set=utf8mb4 \
< ${{ steps.get-db.outputs.db-dump-file }}
- name: Flush Redis cache
working-directory: /orbitar
env:
REDIS_PASSWORD: orbitar
run: docker compose -f docker-compose.ssl.local.yml exec -e REDISCLI_AUTH=$REDIS_PASSWORD redis redis-cli FLUSHALL
- name: Restart backend
working-directory: /orbitar
run: docker compose -f docker-compose.ssl.local.yml start backend