patternsqlMajor
Best way to pg_dump PostgreSQL on RDS to S3
Viewed 0 times
postgresqlpg_dumpwayrdsbest
Problem
I need to dump my PostgreSQL on RDS to a file on S3 periodically (to use it elsewhere than AWS).
Is there a better way than running a script that runs
Is there a better way than running a script that runs
pg_dump and uploads results to S3 using e.g. boto3?Solution
You can directly upload the (gzipped)
At work we wrapped this in a script which additionally fetches the required credentials from parameter store and then stores the backup in s3. The script runs within a docker container as a scheduled ecs task. Maybe the code in this repository will help you.
pg_dump results to s3 using the aws cli:pg_dump -Z 9 -v -h ${DATABASE_HOST} -U ${DATABASE_USER} -d ${DATABASE_NAME} | aws s3 cp --storage-class STANDARD_IA --sse aws:kms - s3://my-bucket/dump.sql.gzAt work we wrapped this in a script which additionally fetches the required credentials from parameter store and then stores the backup in s3. The script runs within a docker container as a scheduled ecs task. Maybe the code in this repository will help you.
Code Snippets
pg_dump -Z 9 -v -h ${DATABASE_HOST} -U ${DATABASE_USER} -d ${DATABASE_NAME} | aws s3 cp --storage-class STANDARD_IA --sse aws:kms - s3://my-bucket/dump.sql.gzContext
StackExchange Database Administrators Q#221454, answer score: 22
Revisions (0)
No revisions yet.