From f4da9b7ffb414a522f531e437b0c492a444eeb93 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 8 Jan 2015 08:12:20 -0800 Subject: [PATCH] JBAS-255 schema exporter script Signed-off-by: Bill Erickson --- KCLS/sql/dev-data/tools/export-db-schema.sh | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 KCLS/sql/dev-data/tools/export-db-schema.sh diff --git a/KCLS/sql/dev-data/tools/export-db-schema.sh b/KCLS/sql/dev-data/tools/export-db-schema.sh new file mode 100755 index 0000000000..5b3342cf30 --- /dev/null +++ b/KCLS/sql/dev-data/tools/export-db-schema.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# ------------------------------------------------------------------- +# KCLS database schema exporter. +# Author: Bill Erickson +# +# Exports the full 'evergreen' database schema. +# +# Usage: +# 1. Log on to the database server of choice +# 2. ./export-db-schema.sh +# +# This will create one file in the working directory. +# ------------------------------------------------------------------- + +pg_dump --schema-only -U evergreen evergreen > tmp-schema.sql + +echo " + +-- Generated $(date +'%F %T') on $(hostname) + +-- These custom users may already exist... errors are OK. + +CREATE USER bbonner; +CREATE USER biblio; +CREATE USER kclsreporter; +CREATE USER kclsreporter2; + +BEGIN; + +\set ON_ERROR_STOP on + +" > tmp-schema2.sql + +cat tmp-schema.sql >> tmp-schema2.sql + +echo -e "\nCOMMIT;\n" >> tmp-schema2.sql + +# we have to comment out the pg_prewarm stuff, since +# we're not installing that extension on new databases. + +line1=$(grep -n -m1 pg_prewarm tmp-schema2.sql) +pos1=$(echo "$line1" | cut -d':' -f1) +pos1=$((($pos1 - 1))) +sed "${pos1}i/*" tmp-schema2.sql > tmp-schema3.sql + +line2=$(grep -n pg_prewarm tmp-schema3.sql | tail -n1) +pos2=$(echo "$line2" | cut -d':' -f1) +pos2=$((($pos2 + 1))) + +sed "${pos2}i*/" tmp-schema3.sql > kcls-eg-db-schema.sql + +rm tmp-schema*.sql + -- 2.11.0