Skip to content

Commit

Permalink
Merge pull request #130 from mediamicroservices/add-import-schema-script
Browse files Browse the repository at this point in the history
Add ingestschemas script
  • Loading branch information
privatezero authored Feb 10, 2017
2 parents d7704f6 + 71e99ba commit 27b7bde
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions createpremisdb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ echo "CREATE TABLE object (objectIdentifierValueID bigint NOT NULL AUTO_INCREMEN
echo "CREATE TABLE event (eventIdentifierValue bigint NOT NULL AUTO_INCREMENT,objectIdentifierValue varchar(1000) NOT NULL,eventType varchar(100) NOT NULL,eventDateTime datetime NOT NULL DEFAULT NOW(),eventDetail varchar(30) NOT NULL,eventOutcome varchar(30),eventDetailOPT varchar(1000),eventDetailCOMPNAME varchar(50) NOT NULL,linkingAgentIdentifierValue varchar(30) NOT NULL,PRIMARY KEY (eventIdentifierValue),FOREIGN KEY (objectIdentifierValue) REFERENCES object(objectIdentifierValue))" | mysql --login-path=tempsetting "$DB_NAME"
echo "CREATE TABLE fixity (fixityIdentifierValue bigint NOT NULL AUTO_INCREMENT,eventIdentifierValue bigint NOT NULL, objectIdentifierValue varchar(1000),eventDateTime datetime NOT NULL DEFAULT NOW(),eventDetail varchar(30) NOT NULL,messageDigestAlgorithm varchar (20) NOT NULL,messageDigestPATH varchar (8000) NOT NULL,messageDigestFILENAME varchar (8000) NOT NULL,messageDigestHASH varchar (32) NOT NULL,PRIMARY KEY (fixityIdentifierValue),FOREIGN KEY (eventIdentifierValue) REFERENCES event(eventIdentifierValue), FOREIGN KEY (objectIdentifierValue) REFERENCES object(objectIdentifierValue))" | mysql --login-path=tempsetting "$DB_NAME"
echo "CREATE TABLE objectCharacteristics (objectCharacteristicValueID bigint NOT NULL AUTO_INCREMENT, objectIdentifierValue varchar(1000) NOT NULL,mediaInfo MEDIUMTEXT, PRIMARY KEY (objectCharacteristicValueID),FOREIGN KEY (objectIdentifierValue) REFERENCES object(objectIdentifierValue))" | mysql --login-path=tempsetting "$DB_NAME"
echo "CREATE TABLE ltoSchema (ltoSchemaValueID bigint NOT NULL AUTO_INCREMENT, ltoID varchar(10) NOT NULL,fileName varchar(200),fileSize varchar(100),fileDate varchar(40),PRIMARY KEY (ltoSchemaValueID))" | mysql --login-path=tempsetting "$DB_NAME"
echo "CREATE UNIQUE INDEX lto_column_index ON ltoSchema(ltoID,fileName,fileSize,fileDate)" | mysql --login-path=tempsetting "$DB_NAME"
echo "CREATE TABLE ltoSchema (ltoSchemaValueID bigint NOT NULL AUTO_INCREMENT, ltoID varchar(10) NOT NULL,fileName varchar(200),filePath varchar(400),fileSize varchar(100),modifyTime varchar(40),PRIMARY KEY (ltoSchemaValueID))" | mysql --login-path=tempsetting "$DB_NAME"
echo "CREATE UNIQUE INDEX lto_column_index ON ltoSchema(ltoID,fileName,filePath,fileSize,modifyTime)" | mysql --login-path=tempsetting "$DB_NAME"
_error_check
#remove root config
mysql_config_editor remove --login-path=tempsetting
Expand Down
22 changes: 22 additions & 0 deletions ingestschemas
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
SCRIPTDIR=$(dirname $(which "${0}"))
. "${SCRIPTDIR}/mmfunctions"

if [ -d "${1}" ] ; then
cd "${1}"
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
15 changes: 10 additions & 5 deletions mmfunctions
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ _cleanup_mount_dir(){
_report_to_db(){
if [ "${PREMIS_DB}" = "Y" ] ; then
eventDetail=$(basename "${0}")
MEDIA_ID=$(basename "${INPUT}")
if [ -z "${MEDIA_ID}" ] ; then
MEDIA_ID=$(basename "${INPUT}")
fi
LOGDIR="${OUTDIR_INGESTFILE}/${MEDIAID}/metadata/logs"
INGESTLOG="${LOGDIR}/capture.log"
if [ -f "${INGESTLOG}" ] ; then
Expand Down Expand Up @@ -53,15 +55,18 @@ _report_to_db(){
_report_schema_db(){
if [ "${PREMIS_DB}" = "Y" ] ; then
table_name="ltoSchema"
xmlschema="$LTO_LOGS/${TAPE_SERIAL}.schema"
schema_sorted=$(xml sel -t -m "/ltfsindex/directory/contents/directory/contents/file" -v "concat(name,'|',length, '|', modifytime)" -n "${xmlschema}")
if [ -z "${xmlschema}" ] ; then
xmlschema="$LTO_LOGS/${TAPE_SERIAL}.schema"
fi
schema_sorted=$(xml sel -t -m "/ltfsindex/directory/contents/directory/contents/file" -v "concat(name,'|',length, '|', modifytime)" -o "|" -m "ancestor-or-self::directory" -v "name" -o "/" -b -n "${xmlschema}")
schema_tape=$(basename "${xmlschema}" | cut -d'.' -f1)
IFS=$(echo -en "\n\b")
(for i in ${schema_sorted}; do LINE=$i;
schema_name=$(echo "${LINE}" | cut -d'|' -f1)
schema_path=$(echo "${LINE}" | cut -d'|' -f4)
schema_length=$(echo "${LINE}" | cut -d'|' -f2)
schema_date=$(echo "${LINE}" | cut -d'|' -f3)
echo "INSERT IGNORE INTO ltoSchema (ltoID,fileName,fileSize,fileDate) VALUES ('${schema_tape}','${schema_name}','${schema_length}','$schema_date')" | mysql --login-path="${PREMIS_PROFILE}" "${PREMIS_NAME}" 2> /dev/null
echo "INSERT IGNORE INTO ltoSchema (ltoID,fileName,fileSize,modifyTime,filePath) VALUES ('${schema_tape}','${schema_name}','${schema_length}','$schema_date','${schema_path}${schema_name}')" | mysql --login-path="${PREMIS_PROFILE}" "${PREMIS_NAME}" 2> /dev/null
done)
unset IFS
_db_error_check
Expand Down Expand Up @@ -136,7 +141,7 @@ _db_error_check(){
echo "echo \"INSERT IGNORE INTO objectCharacteristics (objectIdentifierValue,mediaInfo) VALUES ('${MEDIA_ID}','${MEDIAINFO}')\" | mysql --login-path=\"${PREMIS_PROFILE}\" \"$PREMIS_NAME\"" >> ~/Desktop/"$MEDIA_ID"_dbreport.txt
fi
if [ "${table_name}" = "ltoSchema" ] ; then
echo "echo \"INSERT INTO ltoSchema (ltoID,fileName,fileSize,fileDate) VALUES ('${schema_tape}','${schema_name}','${schema_length}','$schema_date')\" | mysql --login-path=\"${PREMIS_PROFILE}\" \"${PREMIS_NAME}\"" >> ~/Desktop/"$MEDIA_ID"_dbreport.txt
echo "echo \"INSERT INTO ltoSchema (ltoID,fileName,fileSize,modifyTime,filePath) VALUES ('${schema_tape}','${schema_name}','${schema_length}','$schema_date','${schema_path}${schema_name}')\" | mysql --login-path=\"${PREMIS_PROFILE}\" \"${PREMIS_NAME}\"" >> ~/Desktop/"$MEDIA_ID"_dbreport.txt
fi
else
echo -e "\033[1;103;95mSuccessfully reported infomation to the "${table_name}" table in the database "${PREMIS_NAME}"\033[0m"
Expand Down

0 comments on commit 27b7bde

Please sign in to comment.