Commit | Line | Data |
---|---|---|
744e9cd4 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 | NONEXPORTED_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" | |
14 | MARC_PARAMS="--config /srv/openils/conf/opensrf_core.xml --items --location SITKA --collapse_to_depth 2 --timeout 300 --force901 --encoding UTF-8 --onlyholdings --cap=12" | |
15 | MARC_EXPORT_BIN="${DIR}/marc_export_custom_ms" | |
16 | MARC_EXPORT="${MARC_EXPORT_BIN} ${MARC_PARAMS}" | |
17 | ||
18 | [ -z "${T}" ] && T=$(date -u +%Y%m%dT%H%M%SZ) | |
19 | [ -z "${OUTDIR}" ] && OUTDIR=$(mktemp --tmpdir -d outlook_export.XXXXXXX) | |
20 | ||
21 | process_batch() { | |
22 | local f="$1" sql="$2" split_count="$3" | |
23 | if [ ! -f ${OUTDIR}/${f}-${T}.id ]; then | |
24 | echo "Getting IDs" | |
25 | $PSQL -c "$sql" $DATABASE | sort | uniq >${OUTDIR}/${f}-${T}.id | |
26 | fi | |
27 | if [ ! -f ${OUTDIR}/${f}.id.targets ]; then | |
28 | echo "Splitting work" | |
29 | split_suffix ${OUTDIR}/${f}-${T}.id ${OUTDIR}/${f}-${T}-split. .id $split_count | |
30 | echo "Making targets" | |
31 | find ${OUTDIR} -name "${f}-${T}-split.[0-9]*[0-9].id" \ | |
32 | | sed 's,.id$,.marc,g' \ | |
33 | >${OUTDIR}/${f}.id.targets | |
34 | fi | |
35 | ||
36 | make ${MAKEOPTS} -f Makefile-marc_export \ | |
37 | MARC_EXPORT_BIN="${MARC_EXPORT_BIN}" \ | |
38 | MARC_PARAMS="$MARC_PARAMS --exclusion_ini ${f}.ini" \ | |
39 | $(<${OUTDIR}/${f}.id.targets) | |
40 | ||
41 | find ${OUTDIR} -name "${f}-${T}-split*.marc" \ | |
42 | -exec cat \{} \; \ | |
43 | >${OUTDIR}/${f}-${T}.marc | |
44 | } | |
45 | ||
46 | split_suffix() { | |
47 | local input="$1" output_prefix="$2" output_suffix="$3" split_count="$4" | |
48 | split -a 7 -d -C ${split_count} ${input} ${output_prefix} | |
49 | find $(dirname ${output_prefix}) -name "$(basename ${output_prefix})*" -exec mv -f \{\} \{\}${output_suffix} \; | |
50 | } | |
51 | ||
52 | # media for BC ELN post-secondary libraries | |
53 | export SPLIT_COUNT=10000 | |
54 | F=bc_eln_media SQL="$POSTSEC_QUERY" | |
55 | process_batch "$F" "${SQL}" $SPLIT_COUNT | |
56 | ||
57 | # serials for BC ELN post-secondary libraries | |
58 | export SPLIT_COUNT=10000 | |
59 | F=bc_eln_serials SQL="$POSTSEC_QUERY" | |
60 | process_batch "$F" "${SQL}" $SPLIT_COUNT | |
61 | ||
62 | export SPLIT_COUNT=100000 | |
63 | # full dump for outlook public libraries | |
64 | F=sitka_full_outlook SQL="$FULL_QUERY" | |
65 | process_batch "$F" "${SQL}" $SPLIT_COUNT | |
66 |