Backup S3 Bucket to your local directory

Backup S3 Bucket to your local directory
Photo by Maksym Kaharlytskyi / Unsplash

I am logging down the script that I used to backup my entire S3 bucket files to local directory.

Prerequisites:

  1. AWS CLI (verify by aws --version)
  2. Access Key and Secret for S3 access

Once you have the information ready. Get the script ready.

BUCKET_NAME="<>"
AWS_SECRET_KEY="<>"
AWS_ACCESS_KEY="<>"

BACKUP_TO_DIR="/media/local/dir/path"
BACKUP_FROM_DIR=s3://${BUCKET_NAME}

export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY}
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_KEY}

aws s3 sync ${BACKUP_FROM_DIR} ${BACKUP_TO_DIR}	

Fill the information in the script and run it. If you have the proper access to bucket the sync operation will run.