You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.5 KiB

5 years ago
  1. # postgres-backup-s3
  2. Backup PostgresSQL to S3 (supports periodic backups)
  3. ## Usage
  4. Docker:
  5. ```sh
  6. $ docker run -e S3_ACCESS_KEY_ID=key -e S3_SECRET_ACCESS_KEY=secret -e S3_BUCKET=my-bucket -e S3_PREFIX=backup -e POSTGRES_DATABASE=dbname -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_HOST=localhost schickling/postgres-backup-s3
  7. ```
  8. Docker Compose:
  9. ```yaml
  10. postgres:
  11. image: postgres
  12. environment:
  13. POSTGRES_USER: user
  14. POSTGRES_PASSWORD: password
  15. pgbackups3:
  16. image: schickling/postgres-backup-s3
  17. depends_on:
  18. - postgres
  19. links:
  20. - postgres
  21. environment:
  22. SCHEDULE: '@daily'
  23. S3_REGION: region
  24. S3_ACCESS_KEY_ID: key
  25. S3_SECRET_ACCESS_KEY: secret
  26. S3_BUCKET: my-bucket
  27. S3_PREFIX: backup
  28. POSTGRES_BACKUP_ALL: "false"
  29. POSTGRES_HOST: host
  30. POSTGRES_DATABASE: dbname
  31. POSTGRES_USER: user
  32. POSTGRES_PASSWORD: password
  33. POSTGRES_EXTRA_OPTS: '--schema=public --blobs'
  34. POSTGRES_FORMAT: 'c'
  35. ```
  36. ### Automatic Periodic Backups
  37. You can additionally set the `SCHEDULE` environment variable like `-e SCHEDULE="@daily"` to run the backup automatically.
  38. More information about the scheduling can be found [here](http://godoc.org/github.com/robfig/cron#hdr-Predefined_schedules).
  39. ### Backup File Name / Path
  40. By default, if `POSTGRES_BACKUP_ALL` is true, the dump file will be put at `<S3_PREFIX=''>/all_<timestamp>.sql.gz`. When using `POSTGRES_DATABASE`, each database listed will be backed up to the object path `<S3_PREFIX=''>/<database>_<timestamp>.<extension>`.
  41. If you wish to make these filenames static, you can use the `S3_FILE_NAME` variable, which will change these formats to `<S3_PREFIX=''>/<S3_FILE_NAME>.<extension>` or `<S3_PREFIX=''>/<S3_FILE_NAME>_<database>.<extension>` accordingly.
  42. ### Backup All Databases
  43. You can backup all available databases by setting `POSTGRES_BACKUP_ALL="true"`.
  44. Single archive with the name `all_<timestamp>.sql.gz` will be uploaded to S3
  45. ### Endpoints for S3
  46. An Endpoint is the URL of the entry point for an AWS web service or S3 Compitable Storage Provider.
  47. You can specify an alternate endpoint by setting `S3_ENDPOINT` environment variable like `protocol://endpoint`
  48. **Note:** S3 Compitable Storage Provider requires `S3_ENDPOINT` environment variable
  49. ### Encryption
  50. You can additionally set the `ENCRYPTION_PASSWORD` environment variable like `-e ENCRYPTION_PASSWORD="superstrongpassword"` to encrypt the backup. It can be decrypted using `openssl aes-256-cbc -d -in backup.sql.gz.enc -out backup.sql.gz`.