Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
MONTH=`date +"%Y-%m"`
DAY=`date +"%d"`
THISHOUR=`date +"%H"`
LASTHOUR=`expr $THISHOUR - 1`
TIMESTAMP=`date +"%Y-%m-%d"`
TIMESTAMP="${TIMESTAMP}-${LASTHOUR}"
echo "Start: postgresql.log.${TIMESTAMP}"
# download log file
echo "Downloading: postgresql.log.${TIMESTAMP}"
aws rds download-db-log-file-portion \
--profile rds --region us-west-1 \
--db-instance-identifier your-db-name \
--starting-token 0 --log-file-name error/postgresql.log.${TIMESTAMP} \
--output text | gzip -9 > postgresql.log.${TIMESTAMP}.gz
# upload to s3
if [ -e postgresql.log.${TIMESTAMP}.gz ]
then
echo "Uploading: postgresql.log.${TIMESTAMP}"
aws s3 cp --profile s3 postgresql.log.${TIMESTAMP}.gz s3://cru-rds-logs/${MONTH}/${DAY}/postgresql.log.${TIMESTAMP}.gz
rm postgresql.log.${TIMESTAMP}.gz
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.