Amazon S3 sync script

aws s3 sync

Here is a step by step guide on how to backup your data to amazon S3. At end of this tutorial you will be able to create a bash script to sync your data to amazon S3.

Create a S3 bucket

  1. Log in to your AWS account and go to S3.
  2. Create a new bucket providing a unique name (just use the default settings for now).

Create a user for s3 access

For security purpose let’s create a separate user for S3 access.

  1. Go to aws IAM
  2. Go to users
  3. Click ‘Add user’
  4. Enter a name
  5. Chose only ‘Programmatic access’
  6. Next go to permissions and select ‘Attach existing policies directly’
  7. Grant ‘AmazonS3FullAccess’ policy to user
  8. Download credentials.cvs file on the final step

Amazon CLI configuration

Let’s configure an aws profile to use credentials we have created.
First install AWS CLI according to following guide,

Issue following command to verify your AWS CLI setup.

aws --version

If you get the CLI version you are ready to go!

Once you have successfully installed, open a command prompts and issue following command to create a AWS CLI profile.

aws configure --profile my-s3

You can use any name for the profile.

You will be asked for your credentials and region. Provide all your details correctly.

Script to backup files to amazon S3

Use following bash script to backup your data to amazon S3.


aws s3 sync $backup_path s3://$bucket_name --storage-class=STANDARD_IA --profile=$aws_profile

You can find more details about these options from:

Enjoyed this article? Share with friends

  • prashant

    whai is this backup_path used here?


Subscribe to our email feed and never miss a post

Join Us