-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Output csvs for all views in db export Co-authored-by: Alexandru Gartner <[email protected]>
- Loading branch information
1 parent
6c320bb
commit 3181fd5
Showing
4 changed files
with
65 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
printf -v now '%(%Y-%m-%d %H:%M:%S)T\n' -1 | ||
echo "Started at $now" | ||
|
||
mkdir -p database/csv | ||
|
||
tables=$(docker exec -t postgres-container psql -t -U postgres -d hapi -c \ | ||
"select table_name from INFORMATION_SCHEMA.views WHERE table_schema = ANY (current_schemas(false))") | ||
|
||
for table in $tables | ||
do | ||
table=${table::-1} | ||
if [[ -z "$table" ]]; then | ||
continue | ||
fi | ||
|
||
echo "Saving $table" | ||
|
||
docker exec -t postgres-container psql -U postgres -d hapi -c \ | ||
"\copy (select * from ${table}_view) TO STDOUT (FORMAT csv, DELIMITER ',', HEADER);" \ | ||
| tee \ | ||
>(gzip > database/csv/${table}.csv.gz) \ | ||
>(md5sum | awk '{print $1}' > database/csv/${table}.hash) \ | ||
>/dev/null | ||
done | ||
|
||
docker exec -t postgres-container pg_dump -U postgres -Fc hapi -f hapi_db.pg_restore | ||
docker cp postgres-container:/hapi_db.pg_restore database/hapi_db.pg_restore | ||
|
||
printf -v now '%(%Y-%m-%d %H:%M:%S)T\n' -1 | ||
echo "Ended at $now" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters