Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit b3642ee

Browse files
author
Yury Lyakh
committed
add reading from env vars in pg_badger_parsing.sh
1 parent 760da0b commit b3642ee

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pg_badger_parsing.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@
88
#
99

1010
hostname=$(hostname -f)
11+
logfile=$NANCY_LOGFILE
12+
13+
[ "$logfile" = '' ] && logfile=$1
1114

1215
if [ ! -s ~/.s3cfg ]
1316
then
14-
s3cfg=$(psql -A -t postgres_ai -c 'select s3_access_key,s3_secret_key,s3_region from project;' | grep -v ^Tim)
17+
project=$NANCY_PROJECT
18+
[ "$(psql -X -A -t postgres_ai -c "select s3_access_key,s3_secret_key,s3_region from project where name='$project';" 2>/dev/null | wc -l)" -ne 1 ] && echo "FAIL: project=$project is invalid, exit" && exit 1
19+
s3cfg=$(psql -X -A -t postgres_ai -c "select s3_access_key,s3_secret_key,s3_region from project where name='$project';")
1520
(echo '[default]'
1621
echo "access_key = $(echo "$s3cfg" | awk -F '|' '{print $1}')"
1722
echo "secret_key = $(echo "$s3cfg" | awk -F '|' '{print $2}')"
1823
echo "region = $(echo "$s3cfg" | awk -F '|' '{print $3}')"
1924
) > ~/.s3cfg
2025
fi
2126

22-
if [ "$1" != '' ]
27+
if [ "$logfile" != '' ]
2328
then
24-
pgbadger -j 4 --prefix '%t [%p]: [%l-1] db=%d,user=%u (%a,%h)' "$1" -f stderr -o "$1.json" && gzip -vf "$1.json" && s3cmd put "$1.json.gz" s3://p-dumps/${hostname}-manual/
29+
[ ! -s $logfile ] && echo "FAIL: file=$file is empty or absent, exit" && exit 1
30+
pgbadger -j 4 --prefix '%t [%p]: [%l-1] db=%d,user=%u (%a,%h)' "$logfile" -f stderr -o "$logfile.json" && gzip -vf "$logfile.json" && s3cmd put "$logfile.json.gz" s3://p-dumps/${hostname}-manual/
2531
echo "Listing (on S3 storage):"
2632
s3cmd ls s3://p-dumps/${hostname}-manual/
2733
else

0 commit comments

Comments
 (0)