Skip to content

Instantly share code, notes, and snippets.

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 mvn-bachhuynh-dn/da7ad0dbb4719774b741e7aa4667885e to your computer and use it in GitHub Desktop.
Save mvn-bachhuynh-dn/da7ad0dbb4719774b741e7aa4667885e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# Simplistic RDS logfile downloader because AWS CLI + Botocore is broken. :-(
#
from __future__ import print_function
import argparse
import os.path
import sys
import boto3
from botocore.exceptions import NoRegionError, ClientError
parser = argparse.ArgumentParser(description='Simplistic RDS logfile downloader')
parser.add_argument('--region', default='us-west-2')
parser.add_argument('--rds-instance', required=True, help='The RDS name')
parser.add_argument('--rds-log-file', required=True, help='The log file to download')
parser.add_argument('--local-log-file', help='The path where to place the log file on the local file system')
args = parser.parse_args()
region = args.region
rds_instance = args.rds_instance
log_file = args.rds_log_file
if args.local_log_file:
local_log_file = args.local_log_file
else:
local_log_file = os.path.basename(log_file)
try:
rds = boto3.client('rds', region)
except NoRegionError:
rds = boto3.client('rds','us-east-1')
with open(local_log_file, 'w') as f:
print('downloading {rds} log file {file}'.format(rds=rds_instance, file=log_file))
token = '0'
try:
response = rds.download_db_log_file_portion(
DBInstanceIdentifier=rds_instance,
LogFileName=log_file,
Marker=token)
while response['AdditionalDataPending']:
f.write(response['LogFileData'])
token=response['Marker']
response = rds.download_db_log_file_portion(
DBInstanceIdentifier=rds_instance,
LogFileName=log_file,
Marker=token)
f.write(response['LogFileData'])
except ClientError as e:
print(e)
sys.exit(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment