-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3-backup.sh
More file actions
executable file
·25 lines (19 loc) · 943 Bytes
/
s3-backup.sh
File metadata and controls
executable file
·25 lines (19 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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