LoginSignup
1

More than 5 years have passed since last update.

download-db-log-file-portion でログファイルを一括ダウンロード

Last updated at Posted at 2018-02-24

download-db-log-file-portion の説明にこのように書いてあった

Downloads all or a portion of the specified log file, up to 1 MB in size.

1 MB 超えたらどうなるんだろう。
ということで越してた時のワーニングもつけよう。

参考

download-db-log-file-portion — AWS CLI 1.14.46 Command Reference

前提

  • Amazon Linux 2

説明にはこう書かれてた

In order to download the entire file, you need --starting-token 0 parameter:

aws rds download-db-log-file-portion --db-instance-identifier myinstance \
--log-file-name log.txt --starting-token 0 --output text > full.txt

スクリプト

download_rds_logs.sh
#!/bin/bash

set -u
: $1

DB_INSTANCE_IDENTIFIER=$1
OUTPUT="."

logs_json=`aws rds describe-db-log-files --db-instance-identifier ${DB_INSTANCE_IDENTIFIER} | jq ".DescribeDBLogFiles"`

len=$(echo $logs_json | jq length)
for i in $( seq 0 $(($len - 1)) )
do
        row=$(echo $logs_json | jq .[$i])
        logfilename=`echo $row | jq -r ".LogFileName"`
        size=`echo $row | jq -r ".Size"`
        if [ ${size} -gt 1000000 ]; then
                echo ""
                echo "WARN: ${logfilename} is over 1M ${size}. Please check this logfile is copmletion."
                echo ""
        else
                echo ${logfilename}
        fi

        # 保存用のファイル名用意
        savefile=`echo ${logfilename}| sed -e "s/\//-/g"`

        aws rds download-db-log-file-portion --db-instance-identifier ${DB_INSTANCE_IDENTIFIER} \
        --log-file-name ${logfilename} --starting-token 0 --output text \
        > ${OUTPUT}/${savefile}
done

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1