Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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
paper2
新人SEが勉強を始めました.
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away