--- /dev/null
+#!/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
+