From 4379aadd877c260fa0b2e22b72f42ab5f28e42c6 Mon Sep 17 00:00:00 2001 From: Yannic Kilcher Date: Tue, 17 Jan 2023 12:21:16 +0100 Subject: [PATCH] added backup script --- docker/Dockerfile.postgres | 2 ++ docker/backup_pg_to_s3.sh | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100755 docker/backup_pg_to_s3.sh diff --git a/docker/Dockerfile.postgres b/docker/Dockerfile.postgres index b5b98c07..b78e5e3b 100644 --- a/docker/Dockerfile.postgres +++ b/docker/Dockerfile.postgres @@ -7,3 +7,5 @@ RUN apt-get update && apt-get install -y unzip curl && rm -rf /var/lib/apt/lists RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" RUN unzip -q awscliv2.zip RUN ./aws/install + +COPY ./backup_pg_to_s3.sh . \ No newline at end of file diff --git a/docker/backup_pg_to_s3.sh b/docker/backup_pg_to_s3.sh new file mode 100755 index 00000000..b3f4ab84 --- /dev/null +++ b/docker/backup_pg_to_s3.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e +set -x + +# filename with timestamp +filename="postgres-$(date +%Y-%m-%d_%H-%M-%S).sql" + +# perform pg_dump +pg_dump -U postgres postgres > /tmp/$filename + +# upload to s3 +aws s3 cp /tmp/$filename s3://$S3_BUCKET_NAME/$filename \ No newline at end of file