#!/bin/sh # This script reorders database dumps generated by db_converter.py for # efficient consumption by Postgres. fail() { echo "$@" 1>&2 exit 1 } db_gz=$1 drop_indexes_sql=$2 if [ -z "$db_gz" ] || [ -z "$drop_indexes_sql" ] ; then fail "Usage: $0 database.sql.gz drop_indexes.sql" fi # Capture all text up to the first occurence of 'SET CONSTRAINTS' preamble=$(gzip -cd "$db_gz" | sed '/SET CONSTRAINTS/q') if [ -z "$preamble" ] ; then fail "Could not read preamble" fi drop_indexes=$(cat "$drop_indexes_sql") if [ -z "$drop_indexes" ] ; then fail "Could not read DROP INDEXES file" fi # Print preamble and drop indexes cat <