Skip to content

Disaster Recovery

This guide covers procedures for recovering Keshless data from backups in case of data loss, corruption, or system failure.

Quick Reference

Data TypeBackup LocationRestore Method
PostgreSQLgs://keshless-backups/postgresql/pg_restore or psql
Documentsgs://keshless-documents/GCS copy
Secretsgs://keshless-backups/secrets/Manual decryption

Prerequisites

Before running any restore:

RequirementDescription
GCS AccessCloud Run service account credentials
Environment.env with correct values
Database AccessValid DATABASE_URL connection string
Encryption KeySECRETS_ENCRYPTION_KEY for secrets restore

PostgreSQL Restore

List Available Backups

bash
# List daily backups
gcloud storage ls gs://keshless-backups/postgresql/daily/

# List monthly backups
gcloud storage ls gs://keshless-backups/postgresql/monthly/

# Check specific backup manifest
gcloud storage cat gs://keshless-backups/postgresql/daily/{date}/manifest.json

Download and Restore

bash
# Download backup
gcloud storage cp gs://keshless-backups/postgresql/daily/{date}/keshless-daily.sql.gz ./

# Extract
gunzip keshless-daily.sql.gz

# Start Cloud SQL proxy
/tmp/cloud-sql-proxy contracts-470406:europe-west1:keshless-postgres --port=5442 &

# Restore to database
psql -h 127.0.0.1 -p 5442 -U keshless_admin -d keshless_prod < keshless-daily.sql

Restore Options

ScenarioCommand
Full restorepsql -d keshless_prod < backup.sql
Single tablepg_restore -t tablename -d keshless_prod backup.sql
Clean restoreDrop schema first, then restore

Restore Notes

NoteDescription
Duplicate keysRestoring to existing DB fails on duplicates
Clean restoreDrop and recreate schema first
Selective restoreUse pg_restore for specific tables

Document Restore

GCS Commands

bash
# List documents
gcloud storage ls gs://keshless-documents/{folder}/

# Download single file
gcloud storage cp gs://keshless-documents/{folder}/{file} ./

# Restore entire folder
gcloud storage cp -r gs://keshless-documents/{folder}/ ./restored-{folder}/

Document Folders

FolderContents
kyc/User KYC documents (ID cards, passports)
selfies/User verification selfies
vendor-kyc/Vendor verification documents
vendor-media/Vendor logos and media

Secrets Restore

Download Encrypted Backup

bash
gcloud storage cp gs://keshless-backups/secrets/latest.json.encrypted ./

Decryption Process

  1. Load encryption key from password manager
  2. Run decryption script with key
  3. Output decrypted secrets to file
  4. Manually restore to Cloud Run / .env files

Decryption Parameters

ParameterValue
AlgorithmAES-256-GCM
Key DerivationSHA-256 hash of encryption key
IVBase64 encoded in backup file
Auth TagBase64 encoded in backup file

Post-Decryption

StepAction
1Review decrypted secrets
2Update Cloud Run service configuration
3Update local .env files
4Update Secret Manager (if used)

Full Disaster Recovery Drill

Pre-Drill Checklist

StepVerification
GCS AccessCan access backup bucket
Latest PostgreSQLBackup exists and is recent
DocumentsFiles accessible in GCS
SecretsEncrypted backup available

PostgreSQL Restore Test

StepAction
1List available backups
2Download latest daily backup
3Restore to test database
4Verify row counts match manifest

Document Restore Test

StepAction
1List documents in each folder
2Download single file from each folder
3Verify file integrity

Secrets Restore Test

StepAction
1Download encrypted backup
2Verify encryption key works
3Decrypt and inspect contents

Post-Drill

StepAction
1Record any issues found
2Update procedures if needed
3Note time to complete each step

Estimated Recovery Times

Recovery TypeEstimated Time
Single table restore5-15 minutes
Full PostgreSQL restore30-60 minutes
Single GCS folder restore15-30 minutes
Full GCS restore1-2 hours
Secrets restore15 minutes
Full system recovery2-4 hours

Recovery Decision Matrix

ScenarioAction
Single row missingRestore specific table from daily backup
Database corruptionFull restore from last known good backup
Accidental table dropRestore specific table from daily backup
Media files deletedRestore from GCS using gcloud storage cp
API secrets compromisedRotate secrets, restore config, redeploy
Complete data lossFull PostgreSQL + GCS restore

Emergency Procedure

StepAction
1Notify stakeholders about the incident
2Document the failure (what, when, impact)
3Assess damage (which data is affected)
4Execute recovery following this guide
5Verify restoration using checksums and counts
6Post-mortem to prevent recurrence

Best Practices

PracticeDescription
Test regularlyRun DR drills quarterly
Verify backupsCheck backup completion status
Monitor retentionEnsure old backups are cleaned up
Secure encryption keyStore in multiple secure locations
Document changesUpdate this guide when procedures change
Practice restoresTeam should be familiar with procedures

Internal use only - Keshless Payment Platform