Throw backups into AWS S3 from the local server.

Every restaurant has a base sauce ready for different dishes, the same way I am sharing a base shell script to push backups into S3. You can modify the script as per the taste (^_-)

To begin with, you must install a Python environment followed by AWS CLI on your server first and configure it.

Then follows this shell script.

#!/bin/bash
set -x
cd <path>/s3data && rm -rf *
filelist=`cd <path> && find -maxdepth 1 -type d -mtime -1|grep epic|cut -d ‘/’ -f 2`
echo $filelist
cd <path> && tar -cvzf <name>_prod_daily-`date ‘+%D’|sed s/’\/’/-/g`.tgz $filelist && chmod 777 *.tgz && mv -f *.tgz s3data/
source <path>/aws/bin/activate
cd <path> && aws s3 cp s3data s3://<bucket-path>/<sub-directory> –grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers –recursive
deactivate

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s