|
| 1 | +# postgres2s3 |
| 2 | +💾 Backup all PostgreSQL databases to S3 Storage |
| 3 | + |
| 4 | +## Usage |
| 5 | +```bash |
| 6 | +$ docker run \ |
| 7 | + -e POSTGRES_HOST=localhost |
| 8 | + -e POSTGRES_USER=postgres |
| 9 | + -e POSTGRES_PASSWORD=postgrespw |
| 10 | + -e S3_ENDPOINT=http://localhost:9000 |
| 11 | + -e S3_ACCESS_KEY=accessKey |
| 12 | + -e S3_SECRET_KEY=secretKey |
| 13 | + -e S3_BUCKET=backups |
| 14 | + -e ENCRYPTION_PASSWORD=supersecretpassword |
| 15 | + --rm |
| 16 | + nikitakoschelenko/postgres2s3 |
| 17 | +``` |
| 18 | + |
| 19 | +## Environment variables |
| 20 | +#### `POSTGRES_HOST`* |
| 21 | +Host of the PostgreSQL database. |
| 22 | + |
| 23 | +#### `POSTGRES_PORT`* |
| 24 | +Port of the PostgreSQL database. Default to `5432`. |
| 25 | + |
| 26 | +#### `POSTGRES_USER`* |
| 27 | +Username of the PostgreSQL user. |
| 28 | + |
| 29 | +#### `POSTGRES_PASSWORD`* |
| 30 | +Password of the PostgreSQL user. |
| 31 | + |
| 32 | +#### `S3_ENDPOINT`* |
| 33 | +Endpoint URL of the S3. |
| 34 | + |
| 35 | +#### `S3_ACCESS_KEY`* |
| 36 | +Access key of the S3. |
| 37 | + |
| 38 | +#### `S3_SECRET_KEY`* |
| 39 | +Secret key of the S3. |
| 40 | + |
| 41 | +#### `S3_BUCKET`* |
| 42 | +Name of the bucket for saving backups to S3. |
| 43 | + |
| 44 | +#### `S3_FILE_PREFIX` |
| 45 | +Prefix for the backup file name for saving to S3. Default to `backup-`. |
| 46 | + |
| 47 | +#### `ENCRYPTION_PASSWORD` |
| 48 | +Password for encryption. |
| 49 | + |
| 50 | +#### `PG_DUMPALL_EXTRA_ARGS` |
| 51 | +Extra options for `pg_dumpall` command. |
| 52 | + |
| 53 | +#### `OPENSSL_ENC_EXTRA_ARGS` |
| 54 | +Extra options for `openssl enc` command. |
| 55 | + |
| 56 | +#### `AWS_S3_CP_EXTRA_ARGS` |
| 57 | +Extra options for `aws s3 cp` command. |
| 58 | + |
| 59 | +## Decryption |
| 60 | +```bash |
| 61 | +openssl enc -d -aes-256-cbc -pbkdf2 -iter 20000 -in backup.bak.gz.enc -out backup.bak.gz |
| 62 | +``` |
| 63 | + |
| 64 | +## Kubernetes |
| 65 | +To use with Kubernetes, you need to create a CronJob: |
| 66 | +```yaml |
| 67 | +apiVersion: batch/v1 |
| 68 | +kind: CronJob |
| 69 | +metadata: |
| 70 | + name: postgresql-backup |
| 71 | + namespace: shared |
| 72 | +spec: |
| 73 | + schedule: 0 */8 * * * |
| 74 | + jobTemplate: |
| 75 | + spec: |
| 76 | + template: |
| 77 | + spec: |
| 78 | + containers: |
| 79 | + - name: postgresql-backup |
| 80 | + image: nikitakoschelenko/postgres2s3:15.1 |
| 81 | + env: |
| 82 | + - name: POSTGRES_HOST |
| 83 | + value: postgresql.shared |
| 84 | + - name: POSTGRES_USER |
| 85 | + valueFrom: |
| 86 | + secretKeyRef: |
| 87 | + name: postgresql-backup-secret |
| 88 | + key: POSTGRES_USER |
| 89 | + - name: POSTGRES_PASSWORD |
| 90 | + valueFrom: |
| 91 | + secretKeyRef: |
| 92 | + name: postgresql-backup-secret |
| 93 | + key: POSTGRES_PASSWORD |
| 94 | + - name: S3_ENDPOINT |
| 95 | + value: http://minio.shared:9000/ |
| 96 | + - name: S3_ACCESS_KEY |
| 97 | + valueFrom: |
| 98 | + secretKeyRef: |
| 99 | + name: postgresql-backup-secret |
| 100 | + key: S3_ACCESS_KEY |
| 101 | + - name: S3_SECRET_KEY |
| 102 | + valueFrom: |
| 103 | + secretKeyRef: |
| 104 | + name: postgresql-backup-secret |
| 105 | + key: S3_SECRET_KEY |
| 106 | + - name: S3_BUCKET |
| 107 | + value: backups |
| 108 | + - name: S3_PREFIX |
| 109 | + value: postresql/backup- |
| 110 | + - name: ENCRYPTION_PASSWORD |
| 111 | + valueFrom: |
| 112 | + secretKeyRef: |
| 113 | + name: postgresql-backup-secret |
| 114 | + key: ENCRYPTION_PASSWORD |
| 115 | + restartPolicy: OnFailure |
| 116 | +``` |
0 commit comments