aws cli - 在 bash 脚本中下载 rds postgres 日志
aws cli - download rds postgres logs in a bash script
我写了一个简单的 bash 脚本来下载我的 RDS postgres 文件。
但更重要的是,所有这些都可以正常工作,但是当我在脚本中尝试同样的事情时,我得到一个错误:
An error occurred (DBLogFileNotFoundFault) when calling the DownloadDBLogFilePortion operation: DBLog File: "error/postgresql.log.2017-11-05-23", is not found on the DB instance
有问题的命令是这样的:
aws rds download-db-log-file-portion --db-instance-identifier foobar --starting-token 0 --output text --log-file error/postgresql.log.2017-11-05-23 >> test.log
一切正常,但是当我在 bash 脚本中放入完全相同的行时,我收到错误消息,指出没有数据库日志文件 - 这是胡说八道,它们就在那里。
这是 bash 脚本:
download_generate_report() {
for filename in $( aws rds describe-db-log-files --db-instance-identifier | awk {'print '} | grep )
do
echo $filename
echo
aws rds download-db-log-file-portion --db-instance-identifier --starting-token 0 --output text --log-file $filename >> /home/ubuntu/pgbadger_script/postgres_logs/postgres_.log.
done
}
谢谢,
汤姆
我稍微重写了您的脚本,它似乎对我有用。它对 grep 咆哮。这使用 jq.
for filename in $( aws rds describe-db-log-files --db-instance-identifier | jq -r '.DescribeDBLogFiles[] | .LogFileName' )
do
aws rds download-db-log-file-portion --db-instance-identifier --output text --no-paginate --log-file $filename >> /tmp/postgres_.log.
done
谢谢 Ian,我有一个关于 aws cli 2.4 的问题,因为日志文件下载被截断了。
为了解决这个问题,我将 --no-paginate 更改为 --starting-token 0 更多信息在 RDS Reference
终于在 bash:
#/bin/bash
set -x
for filename in $( aws rds describe-db-log-files --db-instance-identifier | jq -r '.DescribeDBLogFiles[] | .LogFileName' )
do
aws rds download-db-log-file-portion --db-instance-identifier --output text --starting-token 0 --log-file $filename >> $filename
done
我写了一个简单的 bash 脚本来下载我的 RDS postgres 文件。 但更重要的是,所有这些都可以正常工作,但是当我在脚本中尝试同样的事情时,我得到一个错误:
An error occurred (DBLogFileNotFoundFault) when calling the DownloadDBLogFilePortion operation: DBLog File: "error/postgresql.log.2017-11-05-23", is not found on the DB instance
有问题的命令是这样的:
aws rds download-db-log-file-portion --db-instance-identifier foobar --starting-token 0 --output text --log-file error/postgresql.log.2017-11-05-23 >> test.log
一切正常,但是当我在 bash 脚本中放入完全相同的行时,我收到错误消息,指出没有数据库日志文件 - 这是胡说八道,它们就在那里。
这是 bash 脚本:
download_generate_report() {
for filename in $( aws rds describe-db-log-files --db-instance-identifier | awk {'print '} | grep )
do
echo $filename
echo
aws rds download-db-log-file-portion --db-instance-identifier --starting-token 0 --output text --log-file $filename >> /home/ubuntu/pgbadger_script/postgres_logs/postgres_.log.
done
}
谢谢, 汤姆
我稍微重写了您的脚本,它似乎对我有用。它对 grep 咆哮。这使用 jq.
for filename in $( aws rds describe-db-log-files --db-instance-identifier | jq -r '.DescribeDBLogFiles[] | .LogFileName' )
do
aws rds download-db-log-file-portion --db-instance-identifier --output text --no-paginate --log-file $filename >> /tmp/postgres_.log.
done
谢谢 Ian,我有一个关于 aws cli 2.4 的问题,因为日志文件下载被截断了。
为了解决这个问题,我将 --no-paginate 更改为 --starting-token 0 更多信息在 RDS Reference
终于在 bash:
#/bin/bash
set -x
for filename in $( aws rds describe-db-log-files --db-instance-identifier | jq -r '.DescribeDBLogFiles[] | .LogFileName' )
do
aws rds download-db-log-file-portion --db-instance-identifier --output text --starting-token 0 --log-file $filename >> $filename
done