Skip to content

Instantly share code, notes, and snippets.

@ruckus
Created January 2, 2018 00:02
Show Gist options
  • Save ruckus/52517a0612af548ca66b8a3f2b422b39 to your computer and use it in GitHub Desktop.
Save ruckus/52517a0612af548ca66b8a3f2b422b39 to your computer and use it in GitHub Desktop.
#!/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