install-eg.sh: fix setup of non-prod Apache includes
[sitka/sitka-tools.git] / marc_export_custom / sitka-full-export-bslw.sh
1 #!/bin/bash
2
3 DIR=$(readlink -f $(dirname $0))
4 #cd /srv/openils/bin
5
6 PGUSER=evergreen
7 PGHOST=prod-pg94-db2-sitka.sitka.bclibraries.ca
8 PSQL="psql -A -t -U $PGUSER -h $PGHOST"
9 DATABASE=evergreen
10 FULL_QUERY="select id from biblio.record_entry where not deleted"
11 MARC_PARAMS="--config /srv/openils/conf/opensrf_core.xml --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 backstage_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" \
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 export SPLIT_COUNT=100000
50 # full dump for all libraries
51 F=sitka_full_backstage SQL="$FULL_QUERY"
52 process_batch "$F" "${SQL}" $SPLIT_COUNT
53
54
55
56 #Separate file of 901s for BKCT
57 TNRD_ALLRECS="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 AND owning_lib IN (SELECT id FROM actor.org_unit_descendants(50)) and acn.label != '##URI##'"
58 $PSQL -t -A -c "$TNRD_ALLRECS" $DATABASE |sort|uniq > ${OUTDIR}/tnrd-all-recs.id
59
60 # Separate file of 901s for MB Leg Library 
61 MBLEG_ALLRECS="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 AND owning_lib IN (SELECT id FROM actor.org_unit_descendants(1100))"
62 $PSQL -t -A -c "$MBLEG_ALLRECS" $DATABASE |sort|uniq > ${OUTDIR}/mbleg-all-recs.id
63
64 # Separate file of 901s for av recs
65 AV_RECS="SELECT DISTINCT acn.record FROM asset.call_number acn JOIN asset.copy acp ON (acn.id = acp.call_number) JOIN biblio.record_entry bre ON (acn.record = bre.id) WHERE NOT bre.deleted AND bre.active AND not acn.deleted AND acp.circ_modifier IN ('3-week-videos','audio-cassette','audio-cds','audio-cds-cnib','audiobook-impaired','book-and-disk','cassette-and-book','cassette-and-book-in-bag','cassettebook','cassettebooks','cassettes','cd-and-book','cd-and-book-in-bag','cd-audiobook','cd-rom','cd-roms','compact-disc','compact-discs','digital-disc','dvd','dvd-feature','dvd-rom','dvd-short','dvdsd','film','juvenile-audio-cassette','juvenile-audio-visual','juvenile-video','kit','mp-3-audio-disc','nfb-videos','restricted-dvd','restricted-video','talking-books','talking-tape-cnib','video','video-cassette','video-collection','videos','videos-educational','videos-features','videosd')"
66 $PSQL -t -A -c "$AV_RECS" $DATABASE |sort|uniq > ${OUTDIR}/audiovisual-recs.id
67
68
69 # TNRD Outreach Records
70 TNRD_OUTREACHRECS="select record FROM asset.call_number acn join asset.copy acp on (acp.call_number = acn.id) where label ~ '^AB' and owning_lib in (64,65) and acp.circ_modifier = 'audiobook-impaired';"
71 $PSQL -t -A -c "$TNRD_OUTREACHRECS" $DATABASE |sort|uniq > ${OUTDIR}/tnrd-outreach-recs.id
72
73 # Electornic Records
74 ELECTONIC_RECS="select distinct record from asset.call_number where label = '##URI##' and not deleted and id not in (select call_number from asset.copy where not deleted);"
75 $PSQL -t -A -c "$ELECTRONIC_RECS" $DATABASE |sort|uniq > ${OUTDIR}/electronic-recs.id