我编写了一个简单的 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
Run Code Online (Sandbox Code Playgroud)
有问题的命令是这样的:
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
Run Code Online (Sandbox Code Playgroud)
一切正常,但是当我在 bash 脚本中放入完全相同的行时,我收到错误消息,没有数据库日志文件 - 这是无稽之谈,它们就在那里。
这是 bash 脚本:
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
}
Run Code Online (Sandbox Code Playgroud)
Tnx,汤姆
小智 5
我稍微重写了你的脚本,它似乎对我有用。它咆哮着 grep。这里使用jq。
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
Run Code Online (Sandbox Code Playgroud)