|
| 1 | +name: Nightly DB backup |
| 2 | + |
| 3 | +# Nightly logical backup of the mainnet and testnet Postgres databases, so a |
| 4 | +# lost or capped managed instance has a minutes-not-days restore path. See |
| 5 | +# docs/backup-restore.md for the restore procedure. This is the durability |
| 6 | +# fallback noted in docs/DUAL_NETWORK.md (#165) — Wraith's data is also |
| 7 | +# re-derivable by re-indexing from chain, so this backup exists to make that |
| 8 | +# unnecessary, not because it's the only copy. |
| 9 | + |
| 10 | +on: |
| 11 | + schedule: |
| 12 | + # Nightly at 03:00 UTC. |
| 13 | + - cron: "0 3 * * *" |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + network: |
| 17 | + description: "Network to back up" |
| 18 | + required: false |
| 19 | + default: "both" |
| 20 | + type: choice |
| 21 | + options: |
| 22 | + - both |
| 23 | + - testnet |
| 24 | + - mainnet |
| 25 | + |
| 26 | +jobs: |
| 27 | + backup-testnet: |
| 28 | + name: pg_dump (testnet) |
| 29 | + if: ${{ github.event.inputs.network == '' || github.event.inputs.network == 'both' || github.event.inputs.network == 'testnet' }} |
| 30 | + runs-on: ubuntu-latest |
| 31 | + timeout-minutes: 20 |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Check secrets are configured |
| 36 | + id: check |
| 37 | + env: |
| 38 | + DATABASE_URL_TESTNET: ${{ secrets.DATABASE_URL_TESTNET }} |
| 39 | + BACKUP_PASSPHRASE: ${{ secrets.BACKUP_PASSPHRASE }} |
| 40 | + run: | |
| 41 | + if [[ -z "$DATABASE_URL_TESTNET" ]]; then |
| 42 | + echo "::warning::DATABASE_URL_TESTNET is not set — skipping testnet backup." |
| 43 | + echo "configured=false" >> "$GITHUB_OUTPUT" |
| 44 | + elif [[ -z "$BACKUP_PASSPHRASE" ]]; then |
| 45 | + # Skip rather than dump: this repository is public, so an |
| 46 | + # unencrypted artifact would be world-readable. A missing backup is |
| 47 | + # recoverable — Wraith re-derives its data by re-indexing — whereas |
| 48 | + # a published one is not. |
| 49 | + echo "::warning::BACKUP_PASSPHRASE is not set — skipping testnet backup rather than writing an unencrypted dump." |
| 50 | + echo "configured=false" >> "$GITHUB_OUTPUT" |
| 51 | + else |
| 52 | + echo "configured=true" >> "$GITHUB_OUTPUT" |
| 53 | + fi |
| 54 | +
|
| 55 | + - name: Install postgresql-client |
| 56 | + if: steps.check.outputs.configured == 'true' |
| 57 | + run: sudo apt-get update && sudo apt-get install -y --no-install-recommends postgresql-client |
| 58 | + |
| 59 | + - name: Dump and compress |
| 60 | + if: steps.check.outputs.configured == 'true' |
| 61 | + env: |
| 62 | + NETWORK: testnet |
| 63 | + DATABASE_URL: ${{ secrets.DATABASE_URL_TESTNET }} |
| 64 | + BACKUP_PASSPHRASE: ${{ secrets.BACKUP_PASSPHRASE }} |
| 65 | + run: | |
| 66 | + chmod +x ops/backup/dump.sh |
| 67 | + ops/backup/dump.sh |
| 68 | +
|
| 69 | + - name: Upload backup artifact |
| 70 | + if: steps.check.outputs.configured == 'true' |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + with: |
| 73 | + name: wraith-db-backup-testnet-${{ github.run_id }} |
| 74 | + # Encrypted files only. The glob is deliberately not `*.dump.gz*` — |
| 75 | + # if encryption ever fails to run, this must find nothing and fail the |
| 76 | + # job, not quietly publish the cleartext dump. |
| 77 | + path: backups/*.dump.gz.gpg |
| 78 | + retention-days: 14 |
| 79 | + if-no-files-found: error |
| 80 | + |
| 81 | + backup-mainnet: |
| 82 | + name: pg_dump (mainnet) |
| 83 | + if: ${{ github.event.inputs.network == '' || github.event.inputs.network == 'both' || github.event.inputs.network == 'mainnet' }} |
| 84 | + runs-on: ubuntu-latest |
| 85 | + timeout-minutes: 20 |
| 86 | + steps: |
| 87 | + - uses: actions/checkout@v4 |
| 88 | + |
| 89 | + - name: Check secrets are configured |
| 90 | + id: check |
| 91 | + env: |
| 92 | + DATABASE_URL_MAINNET: ${{ secrets.DATABASE_URL_MAINNET }} |
| 93 | + BACKUP_PASSPHRASE: ${{ secrets.BACKUP_PASSPHRASE }} |
| 94 | + run: | |
| 95 | + if [[ -z "$DATABASE_URL_MAINNET" ]]; then |
| 96 | + echo "::warning::DATABASE_URL_MAINNET is not set — skipping mainnet backup." |
| 97 | + echo "configured=false" >> "$GITHUB_OUTPUT" |
| 98 | + elif [[ -z "$BACKUP_PASSPHRASE" ]]; then |
| 99 | + # Skip rather than dump: this repository is public, so an |
| 100 | + # unencrypted artifact would be world-readable. A missing backup is |
| 101 | + # recoverable — Wraith re-derives its data by re-indexing — whereas |
| 102 | + # a published one is not. |
| 103 | + echo "::warning::BACKUP_PASSPHRASE is not set — skipping mainnet backup rather than writing an unencrypted dump." |
| 104 | + echo "configured=false" >> "$GITHUB_OUTPUT" |
| 105 | + else |
| 106 | + echo "configured=true" >> "$GITHUB_OUTPUT" |
| 107 | + fi |
| 108 | +
|
| 109 | + - name: Install postgresql-client |
| 110 | + if: steps.check.outputs.configured == 'true' |
| 111 | + run: sudo apt-get update && sudo apt-get install -y --no-install-recommends postgresql-client |
| 112 | + |
| 113 | + - name: Dump and compress |
| 114 | + if: steps.check.outputs.configured == 'true' |
| 115 | + env: |
| 116 | + NETWORK: mainnet |
| 117 | + DATABASE_URL: ${{ secrets.DATABASE_URL_MAINNET }} |
| 118 | + BACKUP_PASSPHRASE: ${{ secrets.BACKUP_PASSPHRASE }} |
| 119 | + run: | |
| 120 | + chmod +x ops/backup/dump.sh |
| 121 | + ops/backup/dump.sh |
| 122 | +
|
| 123 | + - name: Upload backup artifact |
| 124 | + if: steps.check.outputs.configured == 'true' |
| 125 | + uses: actions/upload-artifact@v4 |
| 126 | + with: |
| 127 | + name: wraith-db-backup-mainnet-${{ github.run_id }} |
| 128 | + # Encrypted files only. The glob is deliberately not `*.dump.gz*` — |
| 129 | + # if encryption ever fails to run, this must find nothing and fail the |
| 130 | + # job, not quietly publish the cleartext dump. |
| 131 | + path: backups/*.dump.gz.gpg |
| 132 | + retention-days: 14 |
| 133 | + if-no-files-found: error |
0 commit comments