Skip to content

Instantly share code, notes, and snippets.

@lsdr
Last active October 30, 2018 00:08
Show Gist options
  • Save lsdr/ce566cd1a1ccfa2cb8a29d21b698dbb6 to your computer and use it in GitHub Desktop.
Save lsdr/ce566cd1a1ccfa2cb8a29d21b698dbb6 to your computer and use it in GitHub Desktop.
Fetch RDS logs
#!/bin/sh
#
# usage:
# $ sh get_the_logs.sh [rds-instance-name]
#
function __describe_logs {
aws rds describe-db-log-files --db-instance-identifier $1
}
function __extract_log_files {
jq '.["DescribeDBLogFiles"][] | .LogFileName' | tr -d \"
}
function __download_log {
aws rds download-db-log-file-portion --db-instance-identifier $1 \
--starting-token 0 \
--output text \
--log-file-name "$2" > "$2"
}
function get_the_log {
echo "fetching the fuckin' logs!"
local loglist=($(__describe_logs $1 | __extract_log_files))
for f in ${loglist[@]}; do
__download_log $1 $f
printf "."
done
echo "...done!"
}
function usage {
cat >&1 <<CAT
Fetch all logs for given RDS instance.
Example:
$ get_the_logs.sh postgres-ds
Usage: get_the_logs.sh <INSTANCE_NAME>
CAT
exit 1
}
# checks for arguments else prints usage
if [[ $# -eq 0 ]]; then
usage
fi
args=("$@")
get_the_log ${args[0]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment