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.
Create IAM user account in Amazon
Click here and go to Users -> Create New Users.
Trigger Download Credentials button, you will get a .csv file.
Manage Policy Settings
Select on your user account, you will find permissions tab.
Enable AdministratorAccess and AmazonEC2FullAccess, click Attach Policy button.
Policies has been added to user account.
Create S3 Bucket
Go to Amazon S3 Page and create a bucket.
Create a Folder
You have to create a backup folder.
Connect your Amazon EC2 server using SSH command or Putty, Amazon EC2 Cloud Installation.
Install AWS Command Line
#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.
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.