Install and Use AWS CLI for backup
1.Check python version
#python –version
2.Download the AWS CLI Bundled Installer
#curl “https://s3.amazonaws.com/aws-cli/awscli-bundle.zip” -o “awscli-bundle.zip”
3.Unzip and install
#unzip awscli-bundle.zip
#./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
4.Installed Version Check
#/usr/local/bin/aws –version
5.Configuring AWS Bucket
#aws configure
Or can configure at location
#/root/.aws/credentials in file.
aws_access_key_id = ****************
aws_secret_access_key = ***************************
Provide the below details
a)Your AWS Access Key ID
b)AWS Secret Access Key
6. Full path to file is to be used if used in cron.
Added the cron in crontab file
30 23 * * * /bin/bash /root/dbtos3.sh
where its content is as follows
cat dbtos3.sh
#!/bin/bash
TIME_STAMP=$(date +”%F:%T”)
BACKUP_DIR=”/backup/dbdir/$TIME_STAMP”
mkdir -p $BACKUP_DIR
cd $BACKUP_DIR
mysqldump dbname > dbname.sql
/usr/local/bin/aws s3 sync /backup/dbdir/ s3://foldername/dbbackup
find /backup/dbdir/ -mtime +28 -type d -exec rm -rf {} \;
where dbdir refers to a directory where we take the database dump
and dbname refers to name of the database for which we take the backup