Adding export/ftp script for pushing periodic updates to GALILEO/EDS.
authorChris Sharp <csharp@georgialibraries.org>
Wed, 15 Oct 2014 21:38:07 +0000 (17:38 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Wed, 15 Oct 2014 21:38:07 +0000 (17:38 -0400)
galileo/bib_ids/.gitignore [new file with mode: 0644]
galileo/export_and_ftp.sh [new file with mode: 0755]
galileo/get_ids.sql [new file with mode: 0644]
galileo/out/.gitignore [new file with mode: 0644]

diff --git a/galileo/bib_ids/.gitignore b/galileo/bib_ids/.gitignore
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/galileo/export_and_ftp.sh b/galileo/export_and_ftp.sh
new file mode 100755 (executable)
index 0000000..739ca2a
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+WORKDIR="$PWD"
+PSQL="/usr/bin/psql"
+PSQL_USER="mydbuser"
+SQL_FILE="get_ids.sql"
+DB_HOST="mydbhostname"
+DB_NAME="mydbname"
+OUTDIR="bib_ids"
+OUTFILE="bib_ids_`date +%F`.out"
+BIBDATE=`cat last_export_date`
+EXPORT="pines_bib_update_`date +%F`.mrc"
+EXPORT_DIR="out"
+FTP_HOST="tld.example.com"
+FTP_USER="myftpuser"
+FTP_PASS="myftppath"
+FTP_PATH="myftpremotedirectory"
+ADMIN_EMAIL="my-sys-admins@example.com"
+
+CreateBibList () {
+if [ -z $BIBDATE ]; then
+    read -p "No last export date known.  Please provide the date at which you want to begin export (YYYY-MM-DD): " BIBDATE
+    echo "$BIBDATE" | egrep '^20[0-9][0-9]-[0-1][0-9]-[0-3][0-9]$' > /dev/null
+    if [ $? -ne 0 ]; then
+        echo "$BIBDATE is not a valid date.  Please start over."
+        exit 1;
+    fi
+fi
+
+$PSQL -U $PSQL_USER -h $DB_HOST -A -t -o $OUTDIR/$OUTFILE -v bibdate="'$BIBDATE'" -f $SQL_FILE $DB_NAME
+}
+
+
+ExportBibs () {
+cat $OUTDIR/$OUTFILE | /openils/bin/marc_export --items --encoding UTF-8 > $EXPORT_DIR/$EXPORT
+date +%F > last_export_date
+}
+
+FTPBibFile () {
+cd $EXPORT_DIR
+pftp -n -v $FTP_HOST <<EOT
+user $FTP_USER $FTP_PASS
+cd $FTP_PATH
+put $EXPORT
+bye
+EOT
+cd $WORKDIR
+}
+
+echo "GALILEO EDS bib export began at `date`." | mutt -s "GALILEO EDS Export Begun" $ADMIN_EMAIL
+CreateBibList
+ExportBibs
+FTPBibFile
+echo "GALILEO EDS bib export completed at `date`." | mutt -s "GALILEO EDS Export Completed" $ADMIN_EMAIL
diff --git a/galileo/get_ids.sql b/galileo/get_ids.sql
new file mode 100644 (file)
index 0000000..780f092
--- /dev/null
@@ -0,0 +1,20 @@
+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 (
+        (
+            -- we want both bibs for newly created items since bibdate...
+            not acp.deleted 
+            and acp.create_date::date > :bibdate
+            ) or (
+            -- ...and bibs for items deleted since bibdate
+            acp.deleted 
+            and acp.edit_date > :bibdate
+            )
+        )
+    ) 
+    where bre.id > 0 -- we don't want -1     
+    and not bre.deleted
+    order by id;
diff --git a/galileo/out/.gitignore b/galileo/out/.gitignore
new file mode 100644 (file)
index 0000000..e69de29