Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding s3 backup script to backup between bucks using aws cli #27

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions s3-backup.sh
Original file line number Diff line number Diff line change
@@ -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