diff --git a/Dockerfile b/Dockerfile index 342da29..0726a8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,6 +49,8 @@ ADD github-backup.sh /usr/bin/backup-github ADD gdrive-backup.sh /usr/bin/backup-gdrive ADD loki-logcli-backup.sh /usr/bin/backup-loki-logs-as-json ADD vault-backup.sh /usr/bin/backup-vault +ADD s3-backup.sh /usr/bin/s3-backup + WORKDIR /app diff --git a/s3-backup.sh b/s3-backup.sh new file mode 100755 index 0000000..bf8df24 --- /dev/null +++ b/s3-backup.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +# Ensure all required environment variables are set +if [ -z "$SRC_AWS_ACCESS_KEY_ID" ] || [ -z "$SRC_AWS_SECRET_ACCESS_KEY" ] || [ -z "$DST_AWS_ACCESS_KEY_ID" ] || [ -z "$DST_AWS_SECRET_ACCESS_KEY" ] || [ -z "$SRC_BUCKET" ] || [ -z "$DST_BUCKET" ]; then + echo "One or more required environment variables are not set." + exit 1 +fi + +# Configure AWS CLI for source account +export AWS_ACCESS_KEY_ID=$SRC_AWS_ACCESS_KEY_ID +export AWS_SECRET_ACCESS_KEY=$SRC_AWS_SECRET_ACCESS_KEY + +# Copy data from source bucket to a local directory +aws s3 cp s3://$SRC_BUCKET /tmp/s3_copy --recursive + +# Configure AWS CLI for destination account +export AWS_ACCESS_KEY_ID=$DST_AWS_ACCESS_KEY_ID +export AWS_SECRET_ACCESS_KEY=$DST_AWS_SECRET_ACCESS_KEY + +# Copy data from local directory to destination bucket +aws s3 cp /tmp/s3_copy s3://$DST_BUCKET/s3_bucket_backups/$SRC_BUCKET --recursive + +# Clean up the local directory +rm -rf /tmp/s3_copy