Skip to content

Instantly share code, notes, and snippets.

@chrisdlangton
Created January 18, 2019 03:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrisdlangton/142fa3734bec15f34830ab120507c289 to your computer and use it in GitHub Desktop.
Save chrisdlangton/142fa3734bec15f34830ab120507c289 to your computer and use it in GitHub Desktop.
Script to dump the entire cert.sh database as CSV
#!/usr/bin/env bash
SCHEMA=public
DB=certwatch
HOST=crt.sh
PORT=5432
USER='guest --no-password'
DIR=$(pwd)
mkdir -p $DIR
psql -h $HOST -p $PORT -U $USER -Atc "select tablename from pg_tables where schemaname='$SCHEMA'" $DB |\
while read TBL; do
echo "Checking $TBL"
if [ ! -f "$DIR/$TBL.csv" ]; then
psql \
-h $HOST \
-p $PORT \
-U $USER \
-c "COPY $SCHEMA.$TBL TO STDOUT DELIMITER ',' CSV HEADER" $DB \
> $DIR/$TBL.csv.part && \
mv $DIR/$TBL.csv.part $DIR/$TBL.csv
else
echo "$TBL.csv Exists"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment