Created
April 30, 2016 00:28
-
-
Save robbwagoner/3bc90a9d65a741db598ce610bf1dbc22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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