AWS S3 – Backup Script

Neste script será apresentado como fazer um backup para a S3 de maneira simples e incremental.

O único requisito necessário para utilizar o script é configurar o AWS CLI.

# Fajlinux AWS S3 

DATE=`date +%d%m%y%H%M`
proc=`ps aux | grep "aws s3" | grep -v grep | awk '{print $2}' | xargs | awk '{print $1}'`;
log='/var/log/S3.txt';

# Check Processes
if [ $proc ]
then
echo "The AWS S3 is running" -`date` >> $log;
echo " " >> $log;
elif [ ! -d /backup ]
echo "Backup directory dont't exist" -`date` >> $log;
echo " " >> $log;
else
echo "Start copy "-`date` >> $log;


# TAR data directory 
tar -czvf /backup/site.tar.gz /var/www/html/site

# remove backups older than 5 days
find /backup -mtime +5 -exec rm {} \;

#Run aws cli s3
/usr/local/bin/aws s3 sync /backup s3://BUCKET-BACKUP --delete
echo "Done ! "-`date` >> $log;
echo " " >> $log;
fi