Skip to content

Instantly share code, notes, and snippets.

@davedash
Created April 28, 2016 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davedash/ac5c0ab06f34004373e713dccd2c3f19 to your computer and use it in GitHub Desktop.
Save davedash/ac5c0ab06f34004373e713dccd2c3f19 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script to download all RDS logs for a DB instance
# requires AWS cli and jq.
DB=${1}
if [ -z ${DB} ]; then
echo "Please pass an argument for the database. E.g.:"
echo " ${0} my_rds_db"
fi
if [ -z ${SKIP_LOGFILES} ]; then
echo "Downloading list of logfiles"
aws rds describe-db-log-files --db-instance-identifier ${DB} | \
jq ".DescribeDBLogFiles[].LogFileName" -r > logfiles
fi
test -d logs || mkdir logs
while IFS='' read -r file; do
portion="logs/$(basename ${file})"
if [ ! -f "${portion}" ]; then
echo "Downloading ${file}"
aws rds download-db-log-file-portion --db-instance-identifier ${DB} \
--log-file-name ${file} | jq -r ".LogFileData" > ${portion}
fi
done < logfiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment