Modify Outlook export profile for Radium, per RT#74886
[sitka/sitka-tools.git] / marc_export_custom / sitka-full-export-parallel-ms.sh
CommitLineData
744e9cd4
RJ
1#!/bin/bash
2
e38e56a8
RJ
3DIR=$(readlink -f $(dirname $0))
4
744e9cd4
RJ
5#cd /srv/openils/bin
6
7PGUSER=evergreen
286b73a7 8PGHOST=prod-pg94-db2-sitka.sitka.bclibraries.ca
744e9cd4
RJ
9PSQL="psql -A -t -U $PGUSER -h $PGHOST"
10DATABASE=evergreen
11#FULL_QUERY="select distinct id from biblio.record_entry where not deleted"
12FULL_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"
13POSTSEC_QUERY="select distinct record FROM asset.call_number where owning_lib in (select distinct id from actor.org_unit_descendants(27)) and not deleted and label != '##URI##';"
14NONEXPORTED_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"
1649d461 15MARC_PARAMS="--config /srv/openils/conf/opensrf_core.xml --items --location SITKA --collapse_to_depth 2 --timeout 300 --force901 --encoding UTF-8 --onlyholdings --cap=12 --quiet"
744e9cd4
RJ
16MARC_EXPORT_BIN="${DIR}/marc_export_custom_ms"
17MARC_EXPORT="${MARC_EXPORT_BIN} ${MARC_PARAMS}"
18
19[ -z "${T}" ] && T=$(date -u +%Y%m%dT%H%M%SZ)
20[ -z "${OUTDIR}" ] && OUTDIR=$(mktemp --tmpdir -d outlook_export.XXXXXXX)
21
22process_batch() {
23 local f="$1" sql="$2" split_count="$3"
24 if [ ! -f ${OUTDIR}/${f}-${T}.id ]; then
25 echo "Getting IDs"
26 $PSQL -c "$sql" $DATABASE | sort | uniq >${OUTDIR}/${f}-${T}.id
27 fi
28 if [ ! -f ${OUTDIR}/${f}.id.targets ]; then
29 echo "Splitting work"
30 split_suffix ${OUTDIR}/${f}-${T}.id ${OUTDIR}/${f}-${T}-split. .id $split_count
31 echo "Making targets"
32 find ${OUTDIR} -name "${f}-${T}-split.[0-9]*[0-9].id" \
33 | sed 's,.id$,.marc,g' \
34 >${OUTDIR}/${f}.id.targets
35 fi
36
37 make ${MAKEOPTS} -f Makefile-marc_export \
38 MARC_EXPORT_BIN="${MARC_EXPORT_BIN}" \
39 MARC_PARAMS="$MARC_PARAMS --exclusion_ini ${f}.ini" \
40 $(<${OUTDIR}/${f}.id.targets)
41
42 find ${OUTDIR} -name "${f}-${T}-split*.marc" \
43 -exec cat \{} \; \
44 >${OUTDIR}/${f}-${T}.marc
45}
46
47split_suffix() {
48 local input="$1" output_prefix="$2" output_suffix="$3" split_count="$4"
49 split -a 7 -d -C ${split_count} ${input} ${output_prefix}
50 find $(dirname ${output_prefix}) -name "$(basename ${output_prefix})*" -exec mv -f \{\} \{\}${output_suffix} \;
51}
52
53# media for BC ELN post-secondary libraries
54export SPLIT_COUNT=10000
55F=bc_eln_media SQL="$POSTSEC_QUERY"
56process_batch "$F" "${SQL}" $SPLIT_COUNT
57
58# serials for BC ELN post-secondary libraries
59export SPLIT_COUNT=10000
60F=bc_eln_serials SQL="$POSTSEC_QUERY"
61process_batch "$F" "${SQL}" $SPLIT_COUNT
62
63export SPLIT_COUNT=100000
64# full dump for outlook public libraries
65F=sitka_full_outlook SQL="$FULL_QUERY"
66process_batch "$F" "${SQL}" $SPLIT_COUNT
67