update list of prod hosts
[sitka/sitka-tools.git] / marc_export_custom / sitka-full-export-parallel.sh
CommitLineData
a54b8f42
RJ
1#!/bin/bash
2
e38e56a8 3DIR=$(readlink -f $(dirname $0))
a54b8f42
RJ
4#cd /srv/openils/bin
5
6PGUSER=evergreen
9d5bf491 7PGHOST=dbprod-96-main-ndb2
a54b8f42
RJ
8PSQL="psql -A -t -U $PGUSER -h $PGHOST"
9DATABASE=evergreen
10#FULL_QUERY="select distinct id from biblio.record_entry where not deleted"
11FULL_QUERY="select distinct acn.record FROM asset.call_number acn join biblio.record_entry bre on (acn.record = bre.id) where not bre.deleted and bre.active and not acn.deleted"
77d28950 12NONEXPORTED_QUERY="select distinct acn.record FROM asset.call_number acn join biblio.record_entry bre on (acn.record = bre.id) where bre.deleted or not bre.active or acn.deleted"
9d5bf491 13MARC_PARAMS="--config /srv/openils/conf/opensrf_core.xml --items --location SITKA --collapse_to_depth 3 --timeout 300 --force901 --encoding UTF-8 --onlyholdings --quiet"
a54b8f42 14MARC_EXPORT_BIN="${DIR}/marc_export_custom"
e5fb4602
RJ
15# this lets us inject perl opts
16MARC_EXPORT="perl ${PERLOPT} -- ${MARC_EXPORT_BIN} ${MARC_PARAMS}"
a54b8f42 17
a54b8f42
RJ
18[ -z "${T}" ] && T=$(date -u +%Y%m%dT%H%M%SZ)
19[ -z "${OUTDIR}" ] && OUTDIR=$(mktemp --tmpdir -d outlook_export.XXXXXXX)
20
21process_batch() {
77d28950
RJ
22 local f="$1" sql="$2" split_count="$3"
23 if [ ! -f ${OUTDIR}/${f}-${T}.id ]; then
a54b8f42 24 echo "Getting IDs"
77d28950 25 $PSQL -c "$sql" $DATABASE | sort | uniq >${OUTDIR}/${f}-${T}.id
a54b8f42 26 fi
77d28950 27 if [ ! -f ${OUTDIR}/${f}.id.targets ]; then
a54b8f42 28 echo "Splitting work"
77d28950 29 split_suffix ${OUTDIR}/${f}-${T}.id ${OUTDIR}/${f}-${T}-split. .id $split_count
a54b8f42 30 echo "Making targets"
77d28950 31 find ${OUTDIR} -name "${f}-${T}-split.[0-9]*[0-9].id" \
a54b8f42 32 | sed 's,.id$,.marc,g' \
77d28950 33 >${OUTDIR}/${f}.id.targets
a54b8f42
RJ
34 fi
35
36 make ${MAKEOPTS} -f Makefile-marc_export \
37 MARC_EXPORT_BIN="${MARC_EXPORT_BIN}" \
77d28950
RJ
38 MARC_PARAMS="$MARC_PARAMS --exclusion_ini ${f}.ini" \
39 $(<${OUTDIR}/${f}.id.targets)
368b2926 40 make_rc=$?
a54b8f42 41
77d28950 42 find ${OUTDIR} -name "${f}-${T}-split*.marc" \
a54b8f42 43 -exec cat \{} \; \
77d28950 44 >${OUTDIR}/${f}-${T}.marc
368b2926 45 return $make_rc
a54b8f42
RJ
46}
47
48split_suffix() {
77d28950
RJ
49 local input="$1" output_prefix="$2" output_suffix="$3" split_count="$4"
50 split -a 7 -d -C ${split_count} ${input} ${output_prefix}
51 find $(dirname ${output_prefix}) -name "$(basename ${output_prefix})*" -exec mv -f \{\} \{\}${output_suffix} \;
a54b8f42
RJ
52}
53
77d28950 54export SPLIT_COUNT=100000
6f7b4d95
RJ
55# full dump for outlook public libraries
56F=sitka_full_outlook SQL="$FULL_QUERY"
77d28950 57process_batch "$F" "${SQL}" $SPLIT_COUNT
fe093894 58rc=$?
368b2926 59
368b2926 60exit $rc