Commit | Line | Data |
---|---|---|
a2926055 JD |
1 | #!/bin/bash |
2 | ||
3 | DIR=$(readlink -f $(dirname $0)) | |
4 | #cd /srv/openils/bin | |
5 | ||
6 | PGUSER=evergreen | |
7 | PGHOST=db1.sitka.bclibraries.ca | |
8 | PSQL="psql -A -t -U $PGUSER -h $PGHOST" | |
9 | DATABASE=evergreen | |
10 | MWPL_QUERY="select distinct record FROM asset.call_number where owning_lib in (select distinct id from actor.org_unit_descendants(1020)) and not deleted and label != '##URI##';" | |
11 | MARC_PARAMS="--config /srv/openils/conf/opensrf_core.xml --location MWPL --timeout 300 --force901 --encoding UTF-8 --quiet" | |
12 | MARC_EXPORT_BIN="${DIR}/marc_export_custom" | |
13 | MARC_EXPORT="${MARC_EXPORT_BIN} ${MARC_PARAMS}" | |
14 | ||
15 | [ -z "${T}" ] && T=$(date -u +%Y%m%dT%H%M%SZ) | |
16 | [ -z "${OUTDIR}" ] && OUTDIR=$(mktemp --tmpdir -d outlook_export.XXXXXXX) | |
17 | ||
18 | process_batch() { | |
19 | local f="$1" sql="$2" split_count="$3" | |
20 | if [ ! -f ${OUTDIR}/${f}-${T}.id ]; then | |
21 | echo "Getting IDs" | |
22 | $PSQL -c "$sql" $DATABASE | sort | uniq >${OUTDIR}/${f}-${T}.id | |
23 | fi | |
24 | if [ ! -f ${OUTDIR}/${f}.id.targets ]; then | |
25 | echo "Splitting work" | |
26 | split_suffix ${OUTDIR}/${f}-${T}.id ${OUTDIR}/${f}-${T}-split. .id $split_count | |
27 | echo "Making targets" | |
28 | find ${OUTDIR} -name "${f}-${T}-split.[0-9]*[0-9].id" \ | |
29 | | sed 's,.id$,.marc,g' \ | |
30 | >${OUTDIR}/${f}.id.targets | |
31 | fi | |
32 | ||
33 | make ${MAKEOPTS} -f Makefile-marc_export \ | |
34 | MARC_EXPORT_BIN="${MARC_EXPORT_BIN}" \ | |
35 | MARC_PARAMS="$MARC_PARAMS --exclusion_ini ${f}.ini" \ | |
36 | $(<${OUTDIR}/${f}.id.targets) | |
37 | ||
38 | find ${OUTDIR} -name "${f}-${T}-split*.marc" \ | |
39 | -exec cat \{} \; \ | |
40 | >${OUTDIR}/${f}-${T}.marc | |
41 | } | |
42 | ||
43 | split_suffix() { | |
44 | local input="$1" output_prefix="$2" output_suffix="$3" split_count="$4" | |
45 | split -a 7 -d -C ${split_count} ${input} ${output_prefix} | |
46 | find $(dirname ${output_prefix}) -name "$(basename ${output_prefix})*" -exec mv -f \{\} \{\}${output_suffix} \; | |
47 | } | |
48 | ||
49 | # media for BC ELN post-secondary libraries | |
50 | export SPLIT_COUNT=10000 | |
51 | F=mwpl SQL="$MWPL_QUERY" | |
52 | process_batch "$F" "${SQL}" $SPLIT_COUNT |