首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在bash脚本中下载rds postgres日志

在bash脚本中下载rds postgres日志
EN

Stack Overflow用户
提问于 2017-11-06 15:54:54
回答 2查看 1.7K关注 0票数 4

我编写了一个简单的bash脚本来下载我的RDS postgres文件。但关键是,所有这些都可以正常工作,但是当我在脚本中尝试相同的内容时,我会得到一个错误:

代码语言:javascript
复制
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

有关命令如下:

代码语言:javascript
复制
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脚本中放置完全相同的一行时,我会得到错误消息,即没有db日志文件--这是胡说八道,它们就在那里。

这是bash脚本:

代码语言:javascript
复制
download_generate_report() {

for filename in $( aws rds describe-db-log-files --db-instance-identifier $1 | awk {'print $2'} | grep $2 )
do

echo $filename
echo $1

aws rds download-db-log-file-portion --db-instance-identifier $1 --starting-token 0 --output text --log-file $filename  >> /home/ubuntu/pgbadger_script/postgres_logs/postgres_$1.log.$2
done

}

Tnx,Tom

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-19 18:23:23

我重写了你的剧本,它似乎对我有用。它在grep附近吠叫。这使用了jq。

代码语言:javascript
复制
for filename in $( aws rds describe-db-log-files --db-instance-identifier $1 | jq -r '.DescribeDBLogFiles[] | .LogFileName' )
do

aws rds download-db-log-file-portion --db-instance-identifier $1 --output text --no-paginate --log-file $filename  >> /tmp/postgres_$1.log.$2
done
票数 4
EN

Stack Overflow用户

发布于 2021-12-23 13:01:45

谢谢伊恩,我有一个问题,aws cli 2.4,因为日志文件下载截断。

为了解决这个问题,我更改了--使用不分页的--启动令牌0RDS参考中的更多信息。

最后,在bash:

代码语言:javascript
复制
#/bin/bash
set -x
for filename in $( aws rds describe-db-log-files --db-instance-identifier $1 | jq -r '.DescribeDBLogFiles[] | .LogFileName' ) 
do 
    aws rds download-db-log-file-portion --db-instance-identifier $1 --output text --starting-token 0  --log-file $filename  >> $filename 
done 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47140873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档