Backup All Your Amazon Instance Files to S3 Bucket
Wall Script
Follow Me:
Sunday, July 24, 2016

Backup All Your Amazon Instance Files to S3 Bucket

In our previous posts, Amazon EC2 Cloud Installation and Amazon EC2 Setup with Ubuntu and XAMPP Installation discuss how to launch virtual servers as you need, configure security and networking and manage storage. This allows you to eliminate your investment in hardware, so you can develop and deploy applications faster. AWS is used by most of the smart people in this present technical world. But any old or new application maintained in a server needs a backup, so that any unfortunate crash in the system should not lead you to be in a state of pressure of what to do next. Today’s post help you to maintain the backup of your files as per the daily basis.

Backup your Amazon Instance Files to S3 Bucket

Create IAM user account in Amazon
Click here and go to Users -> Create New Users.
Create Amazon IAM User

Download Keys
Trigger Download Credentials button, you will get a .csv file.
Create Amazon IAM User Download Keys

Manage Policy Settings
Select on your user account, you will find permissions tab.
Create Amazon IAM User 
Manage Policy Settings

Attach Policy
Enable AdministratorAccess and AmazonEC2FullAccess, click Attach Policy button.
Create Amazon IAM Attach Policy

Attached Policies
Policies has been added to user account.
Create Amazon IAM User Attached Policies

Create S3 Bucket
Go to Amazon S3 Page and create a bucket.
Create Amazon S3 bucket

Create a Folder
You have to create a backup folder.
Create Amazon S3 bucket

Connect your Amazon EC2 server using SSH command or Putty, Amazon EC2 Cloud Installation.

Install AWS Command Line
#sudo su
#apt-get install awscli

Configure AWS Command with Your IAM User
Execute in following way.
# aws configure
AWS Access Key ID [None]: AKIAIEWU7M456AJ7PZHA //Your AWS Key
AWS Secret Access Key [None]: DPPSi84TKIcSDmWkHkzesyQlTZj2x8ADerRUsZIe //Your Secret Key
Default region name [None]: us-east-1
Default output format [None]: ENTER

Backup your XAMPP Files
#aws s3 sync /opt/lampp/htdocs/ s3://YourBucketName/backupFolder/

Backup your Database Files
#aws s3 sync /opt/lampp/var/mysql/ s3://YourBucketName/database/

Synchronize form S3 Bucket
Use this following command for synchronizing with other instance.
#aws s3 sync s3://YourBucketName/backupFolder/ /opt/lampp/htdocs/

SetupYour Server Cron Job
This Cron Job will run at 6.20 PM everyday.
#vi /etc/crontab
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#Schedule Your Database
20 18 * * *  root aws s3 sync /opt/lampp/var/mysql/databaseName/ s3://YourBucketName/database/databaseName/


wq! Save and Quit vim editor.
Was this article helpful?
Thanks! Your feedback helps us to improve


  1. Hi Srinivas,

    I wouldn't recommend you to create an access key and secret key with administrative access and use it in an instance.

    The best way is to create a role and attach an inline policy with s3 access to that specific bucket. Then while launching the instance, attach that particular role to it. BY doing this you dont have to store the keys in your instance. BY default you can make AWS cli calls if you have the cli installed. AWS will automatically rotate your keys for security.


Make in India