Commit | Line | Data |
---|---|---|
a54b8f42 RJ |
1 | #!/bin/bash |
2 | ||
3 | DIR=`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 | #FULL_QUERY="select distinct id from biblio.record_entry where not deleted" | |
11 | FULL_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" | |
12 | POSTSEC_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##';" | |
13 | MARC_PARAMS="--config /srv/openils/conf/opensrf_core.xml --items --location SITKA --collapse_to_depth 2 --timeout 300 --force901 --encoding UTF-8" | |
14 | MARC_EXPORT_BIN="${DIR}/marc_export_custom" | |
15 | MARC_EXPORT="${MARC_EXPORT_BIN} ${MARC_PARAMS}" | |
16 | SPLIT_COUNT=50000 | |
17 | ||
18 | ||
19 | [ -z "${T}" ] && T=$(date -u +%Y%m%dT%H%M%SZ) | |
20 | [ -z "${OUTDIR}" ] && OUTDIR=$(mktemp --tmpdir -d outlook_export.XXXXXXX) | |
21 | ||
22 | process_batch() { | |
23 | F="$1" SQL="$2" | |
24 | if [ ! -f ${OUTDIR}/${F}-${T}.id ]; then | |
25 | echo "Getting IDs" | |
26 | $PSQL -c "$SQL" $DATABASE >${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 | |
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 | ||
47 | split_suffix() { | |
48 | INPUT="$1" OUTPUT_PREFIX="$2" OUTPUT_SUFFIX="$3" | |
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 | # full dump for outlook public libraries | |
54 | F=sitka_full_outlook SQL="$FULL_QUERY" | |
55 | #process_batch "$F" "${SQL}" | |
56 | ||
57 | # media for BC ELN post-secondary libraries | |
58 | F=bc_eln_media SQL="$POSTSEC_QUERY" | |
59 | #process_batch "$F" "${SQL}" | |
60 | ||
61 | # serials for BC ELN post-secondary libraries | |
62 | F=bc_eln_serials SQL="$POSTSEC_QUERY" | |
63 | process_batch "$F" "${SQL}" |