Skip to content

Instantly share code, notes, and snippets.

@adam704a
Last active October 8, 2018 21:13
Show Gist options
  • Save adam704a/f0f224826e4063cd49cef5b4830c85ae to your computer and use it in GitHub Desktop.
Save adam704a/f0f224826e4063cd49cef5b4830c85ae to your computer and use it in GitHub Desktop.
export postgres query to s3 as CSV
#!/bin/sh
psql -h localhost hhis -U hhis -c "\copy (SELECT * FROM _view_events) to './dhis2-export.tsv' WITH NULL AS ''"
aws s3 cp dhis2-export.tsv s3://spla-dhis2/dhis2-export.tsv
@adam704a
Copy link
Author

adam704a commented Oct 4, 2017

  • create a .pgpass in ~ to automate the authentication (this is the format hostname:port:database:username:password)
  • schedule with cron (i.e. 0 0 * * * /home/dhis_ro/utils/export.sh)
  • configure aws cli like this: aws configure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment