DATE_LONG=`date +%Y%m%d`
PSQL="/usr/bin/psql"
PSQL_USER="mydbuser"
-SQL_FILE="$WORKDIR/get_ids.sql"
DB_HOST="mydbhost"
DB_NAME="mydbname"
OUTDIR="$WORKDIR/bib_ids"
OUTFILE="bib_ids_`date +%F`.out"
-if [ -e last_export_date ]; then
-BIBDATE=`cat last_export_date`
+if [ -e $WORKDIR/last_export_date ]; then
+BIBDATE=`cat $WORKDIR/last_export_date`
fi
EXPORT="DATA.D$DATE"
LABEL="LABEL.D$DATE"
CHUNKSIZE=50000
SPLIT_BIB_DIR="$OUTDIR/split"
FTP_HOST="my.ftp.host"
-FTP_USER="myftpuser"
+FTP_USER="myftpusr"
FTP_PASS="myftppass"
-FTP_PATH="myftppath"
-ADMIN_EMAIL="admin@example.org"
+FTP_PATH="myftpfilepath"
+ADMIN_EMAIL="admins@myactualdomain.org"
+
# Do we have the required directories? If not, create them
CheckEnv () {
exit 1;
fi
fi
-
-$PSQL -U $PSQL_USER -h $DB_HOST -A -t -o $OUTDIR/$OUTFILE -v bibdate="'$BIBDATE'" -f $SQL_FILE $DB_NAME
+read -d '' SQL <<EOF
+select distinct bre.id
+ from biblio.record_entry bre
+ join asset.call_number acn on (
+ acn.record = bre.id
+ ) join asset.copy acp on (
+ acp.call_number = acn.id and
+ not acp.deleted
+ and acp.create_date::date > '$BIBDATE'
+ )
+ where bre.id > 0 -- we don't want -1
+ and not bre.deleted
+ -- exclude too-large records
+ and bre.id not in (`grep -v ^# toolong | sed ':a;N;$!ba;s/\n/, /g'`)"
+ order by id;"
+EOF
+$PSQL -U $PSQL_USER -h $DB_HOST -A -t -o $OUTDIR/$OUTFILE -c "$SQL" $DB_NAME
}
# Branch here: if we have an $OUTFILE of under $CHUNKSIZE bib ids, just treat it as a single file
ExportBibsSingleFile () {
cat $OUTDIR/$OUTFILE | /openils/bin/marc_export --items --encoding UTF-8 > $EXPORT_DIR/$EXPORT
-date +%F > last_export_date
+date +%F > $WORKDIR/last_export_date
}
CountBibsSingleFile () {
i="1"
for bibfile in `ls bib_ids_*`; do
echo "Processing $bibfile..."
- cat $bibfile | /openils/bin/marc_export --items --encoding UTF-8 > $OUTDIR/DATA.D$DATE.FILE$i
- RECORDCOUNT=`$MARC_COUNT $OUTDIR/DATA.D$DATE.FILE$i`
+ cat $bibfile | /openils/bin/marc_export --items --encoding UTF-8 > $EXPORT_DIR/DATA.D$DATE.FILE$i
+ RECORDCOUNT=`$MARC_COUNT $EXPORT_DIR/DATA.D$DATE.FILE$i`
echo "DATA.D$DATE.FILE$i contains $RECORDCOUNT records"
- cat << EOF > $OUTDIR/LABEL.D$DATE.FILE$i
+ cat << EOF > $EXPORT_DIR/LABEL.D$DATE.FILE$i
DAT ${DATE_LONG}0000000.0
RBF $RECORDCOUNT
DSN DATA.D$DATE.FILE$i
EOF
i=$[$i+1] # set up counter here
done
-date +%F > last_export_date
+date +%F > $WORKDIR/last_export_date
}
FTPMultiFile () {
# FIXME: It's actually unlikely that a monthly export will exceed 50K
# but if it does, and it becomes a burden to do this manually, we
# can add something here to automate multiple file FTP. ;-)
+echo "FTP multifile support is not yet implemented."
}
echo "OCLC bib export began at `date`." | mutt -s "OCLC Export Begun" $ADMIN_EMAIL
ExportBibsMultiFile
# FTPMultiFile
else
- ExportBibsSingleFile
+ ExportBibsSingleFile
CountBibsSingleFile
CreateLabelSingleFile
FTPSingleFile