Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 32 lines (27 sloc) 1.06 KB
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/ubuntu
##
# Bash script to download Postgres SQL log from RDS and upload to S3 bucket
##
# Make sure that you have selected appropriate S3 and RDS IAM role for aws cli user
##
INSTANCE='rds-db-identifier'
BUCKET='backup-db-log-bucket'
mkdir -p ${INSTANCE} && cd ${INSTANCE}
for i in `/home/ubuntu/.local/bin/aws rds describe-db-log-files --db-instance-identifier ${INSTANCE} --output text | awk '{print $3}' | sed '$d' | tail -n 10` ; do
FILE=`basename ${i}`
ARCHIVE=${FILE}.tar.gz
if [ ! -e ${ARCHIVE} ]; then
echo "Downloading ${i} ........."
`which aws` rds download-db-log-file-portion --db-instance-identifier ${INSTANCE} --log-file-name ${i} --starting-token 0 --output text > ${FILE}
tar -cvzf ${ARCHIVE} ${FILE}
echo "Uploading to S3 bucket ........"
`which aws` s3 mv ${ARCHIVE} s3://${BUCKET}/
rm ${FILE}
fi
done
##
# Additionally you can run a cronjob every 45 minutes to upload db log to S3
##
# */45 * * * * /bin/bash /home/ubuntu/.crontasks/script >/dev/null 2>&1
##
You can’t perform that action at this time.