Sync EC2 Data In S3 Storage

Sync EC2 Data In S3 Storage

Sync EC2 Data In S3 Storage

Use S3 Bucket for backup Management

  •     Install pip
  •     Install the AWS CLI with pip
  •     Add the AWS CLI Executable to Your Command Line Path
  •     Installing Python on Linux
  •     Install the AWS CLI on Linux Box

To install pip use the curl command to download the installation script.

    $ curl -O https://bootstrap.pypa.io/get-pip.py

Run the script with Python to download and install the latest version of pip and other required support packages.

  $ python get-pip.py --user

add in .bash_profile

export PATH=~/.local/bin:$PATH

Now you can test to verify that pip is installed correctly.

[root@ip-10-0-1-98 html]# pip2 --version
pip 19.0.3 from /root/.local/lib/python2.7/site-packages/pip (python 2.7)

Install the AWS CLI with pip
Use pip to install the AWS CLI.

$ pip3 install awscli --upgrade --user
[root@ip-10-0-1-98 html]# aws --version
aws-cli/1.16.137 Python/2.7.5 Linux/3.10.0-957.el7.x86_64 botocore/1.12.127

Now authenticate with access key and secret key

[root@ip-10-0-1-98 ~]# aws configure
AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXX
AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXX
Default region name [None]: us-east-2
Default output format [None]: json

Install Apache and make backup of "/var/www/html" on S3 "s3://feenix-prometheus/html"

[root@ip-10-0-1-98 ~]# yum install httpd -y
[root@ip-10-0-1-98 ~]# cd /var/www/html/
[root@ip-10-0-1-98 html]# vim index.html
[root@ip-10-0-1-98 html]# aws s3 sync /var/www/html/ s3://feenix-prometheus/html
upload: ./index.html to s3://feenix-prometheus/html/index.html

Make cron job to automate this.

[root@ip-10-0-1-98 html]# crontab -l
* * * * * /root/.local/bin/aws s3 sync /var/www/html/ s3://feenix-prometheus/html

[root@ip-10-0-1-98 html]# tailf /var/log/cron
Apr  3 16:04:01 ip-10-0-1-98 CROND[4500]: (root) CMD (/root/.local/bin/aws s3 sync /var/www/html/ s3://feenix-prometheus/html)
Apr  3 16:05:01 ip-10-0-1-98 CROND[4511]: (root) CMD (/root/.local/bin/aws s3 sync /var/www/html/ s3://feenix-prometheus/html)

 

Leave a Reply

Your email address will not be published. Required fields are marked *