Skip to content

Commit

Permalink
Merge pull request #68 from amiaopensource/add-ltosearch
Browse files Browse the repository at this point in the history
Add ltosearch
  • Loading branch information
privatezero authored Feb 27, 2017
2 parents 4b453ef + 18c4f3d commit 0de0249
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 14 deletions.
33 changes: 33 additions & 0 deletions ingestcollectionchecksum
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
SCRIPTDIR=$(dirname $(which "${0}"))
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ; }

if [ -z "${PREMIS_NAME}" ] || [ "${PREMIS_DB}" != "Y" ] ; then
echo "Please configure database options in mmconfig. Exiting"
fi
user_input="${*}"

if [ -d "${1}" ] ; then
BATCH_CHECK="Y"
cd "${1}"
for i in *.md5 ; do
db_source="${i}"
db_fixity=$(cat "${i}")
MEDIA_ID=$(basename "${i}" | cut -d'_' -f1)
eventType="ingest"
_report_to_db
_eventoutcome_update
_report_fixity_db
done
elif [ -f "${1}" ] ; then
db_fixity=$(cat "${1}")
db_source="${1}"
MEDIA_ID=$(basename "${1}" | cut -d'.' -f1)
eventType="ingest"
_report_to_db
_eventoutcome_update
_report_fixity_db
else
echo "Please use a valid directory for input. Exiting" && exit 1
fi

35 changes: 21 additions & 14 deletions ingestschemas
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
#!/bin/bash
#!/usr/bin/env bash
SCRIPTDIR=$(dirname $(which "${0}"))
. "${SCRIPTDIR}/mmfunctions"
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ; }

if [ -z "${PREMIS_NAME}" ] || [ "${PREMIS_DB}" != "Y" ] ; then
echo "Please configure database options in mmconfig. Exiting"
fi

if [ -d "${1}" ] ; then
cd "${1}"
for i in *.schema ; do
xmlschema="${i}"
MEDIA_ID=$(basename "${xmlschema}" | cut -d'.' -f1)
eventType="ingest"
_report_to_db
_report_schema_db
_eventoutcome_update
done
elif [ -f "${1}" ] ; then
xmlschema="${1}"
MEDIA_ID=$(basename "${xmlschema}" | cut -d'.' -f1)
eventType="ingest"
_report_to_db
_report_schema_db
_eventoutcome_update
else
Echo "Please use a valid directory for input - Exiting" && exit 0
fi

if [ -z "${PREMIS_NAME}" ] || [ "${PREMIS_DB}" != "Y" ] ; then
echo "Please configure database options in mmconfig. Exiting"
fi

for i in *.schema ; do
xmlschema="${i}"
MEDIA_ID=$(basename "${xmlschema}" | cut -d'.' -f1)
eventType="ingest"
_report_to_db
_report_schema_db
_eventoutcome_update
done
86 changes: 86 additions & 0 deletions searchlto
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash
SCRIPTDIR=$(dirname $(which "${0}"))
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ; }

_usage(){
echo -e "Usage: ltosearch [Tape ID or Media ID]\n-h display this help\n-c compare input to database\n-f show full results (as opposed to only .mov files)"
exit 0
}

_compare_file(){
if [ -f "${INPUT}" ] ; then
DATE=$(date -u -r "$INPUT" +%Y-%m-%dT%H:%M:%S.000000000Z)
SIZE=$(wc -c "${INPUT}")
SQL_RESULTS=$(mysql --login-path="${PREMIS_PROFILE}" "${PREMIS_NAME}" -B -e "SELECT modifyTime,fileSize,fileName FROM ltoSchema WHERE fileName LIKE '%${SEARCH_TERM}%'")
LTO_SIZE=$(echo ${SQL_RESULTS} | cut -d ' ' -f5)
LTO_DATE=$(echo ${SQL_RESULTS} | cut -d ' ' -f4)

if [ -n "${SQL_RESULTS}" ] ; then
if [ "${DATE}" != "${LTO_DATE}" ] ; then
echo -e "\033[1;31mWARNING: Date mismatch between file data and file records in LTO database\033[0m"
fi
if [ $(echo "${SIZE}" | sed -e 's/^[[:space:]]*//' | cut -d' ' -f1) != "${LTO_SIZE}" ] ; then
echo -e "\033[1;31mWARNING: Size mismatch between file data and file records in LTO database\033[0m"
fi
if [ "${DATE}" = "${LTO_DATE}" ] && [ $(echo "${SIZE}" | sed -e 's/^[[:space:]]*//' | cut -d' ' -f1) = "${LTO_SIZE}" ] ; then
echo -e "\033[1;92mMatching File(s) Found\033[0m"
fi
echo "Information from Schema"
echo "------"
echo "${SQL_RESULTS}"
echo ""
echo "Information From File"
echo "------"
echo "${DATE} ${SIZE}"
else
echo -e "\033[1;31mFile with that name not found. Checking for files of similar size and modification date\033[0m"
SQL_RESULTS=$(mysql --login-path="${PREMIS_PROFILE}" "${PREMIS_NAME}" -B -e "SELECT modifyTime,fileSize,fileName FROM ltoSchema WHERE fileSize='$(echo "${SIZE}" | sed -e 's/^[[:space:]]*//' | cut -d' ' -f1)' OR modifyTime='${DATE}'")
if [ -n "${SQL_RESULTS}" ] ; then
echo -e "\033[1;92mFollowing possible matches were found:\033[0m"
echo "${SQL_RESULTS}"
echo "Information from file"
echo "${DATE} ${SIZE}"
else
echo -e "\033[1;31mNo potential matches found\033[0m"
fi
fi

else
echo "Input is not a valid file. Exiting"
exit 1
fi
}

OPTIND=1
while getopts ":hcf" OPT; do
case "${OPT}" in
h) _usage ;;
c) RUNMODE="compare" ;;
f) RUNMODE="full" ;;
*) echo "bad option -${OPTARG}" ; _usage ;;
esac
done

shift $(( ${OPTIND} - 1 ))

SEARCH_INPUT="${*}"

if [ "${*}" = "" ] ; then
echo "Enter the mediaid(s) or lto tape number(s) to search"
read SEARCH_INPUT
fi
for INPUT in $(echo "${SEARCH_INPUT}") ; do
SEARCH_TERM="${INPUT}"
if [ "${RUNMODE}" = "compare" ] ; then
SEARCH_TERM=$(basename "${INPUT}")
_compare_file
else
SQL_RESULTS=$(mysql --login-path="${PREMIS_PROFILE}" "${PREMIS_NAME}" -B -e "SELECT ltoID,filePath FROM ltoSchema WHERE ltoID='${SEARCH_TERM}' OR filePath LIKE '%${SEARCH_TERM}%'")
if [ "${RUNMODE}" = "full" ] ; then
echo "${SQL_RESULTS}"
else
echo "${SQL_RESULTS}" | grep ".mov" | grep -v "fileMeta" | grep -v "access"
fi
fi
done

0 comments on commit 0de0249

Please sign in to comment.