From 66ee96d96323b75b9a27da00f7128f7d183799c5 Mon Sep 17 00:00:00 2001 From: Andrew Weaver Date: Fri, 10 Feb 2017 10:50:04 -0500 Subject: [PATCH 1/5] create script --- ingestschemas.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 ingestschemas.sh diff --git a/ingestschemas.sh b/ingestschemas.sh new file mode 100755 index 00000000..5b3af285 --- /dev/null +++ b/ingestschemas.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ -d "${1}" ] ; then + cd "${1}" +else + Echo "Please use a valid directory for input - Exiting" && exit 0 +fi + +for i in *.schema ; do + +done \ No newline at end of file From dedc9e01aa774f4ccf470ae61f9ed603ead46b7b Mon Sep 17 00:00:00 2001 From: Andrew Weaver Date: Fri, 10 Feb 2017 11:27:11 -0500 Subject: [PATCH 2/5] add variables and functions --- ingestschemas.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ingestschemas.sh b/ingestschemas.sh index 5b3af285..f8869c2d 100755 --- a/ingestschemas.sh +++ b/ingestschemas.sh @@ -1,4 +1,6 @@ #!/bin/bash +SCRIPTDIR=$(dirname $(which "${0}")) +. "${SCRIPTDIR}/mmfunctions" if [ -d "${1}" ] ; then cd "${1}" @@ -6,6 +8,15 @@ else Echo "Please use a valid directory for input - Exiting" && exit 0 fi -for i in *.schema ; do +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 \ No newline at end of file From 1300d21899d0b173dfd37647cada93ecabb1c7d2 Mon Sep 17 00:00:00 2001 From: Andrew Weaver Date: Fri, 10 Feb 2017 11:27:18 -0500 Subject: [PATCH 3/5] add conditionals --- mmfunctions | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mmfunctions b/mmfunctions index c4b94a6e..f467bd48 100755 --- a/mmfunctions +++ b/mmfunctions @@ -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 @@ -53,7 +55,9 @@ _report_to_db(){ _report_schema_db(){ if [ "${PREMIS_DB}" = "Y" ] ; then table_name="ltoSchema" - xmlschema="$LTO_LOGS/${TAPE_SERIAL}.schema" + 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)" -n "${xmlschema}") schema_tape=$(basename "${xmlschema}" | cut -d'.' -f1) IFS=$(echo -en "\n\b") From 0779791b486f4eaed92848057f3e6527af4a539b Mon Sep 17 00:00:00 2001 From: Andrew Weaver Date: Fri, 10 Feb 2017 11:30:04 -0500 Subject: [PATCH 4/5] remove .sh --- ingestschemas.sh => ingestschemas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename ingestschemas.sh => ingestschemas (98%) diff --git a/ingestschemas.sh b/ingestschemas similarity index 98% rename from ingestschemas.sh rename to ingestschemas index f8869c2d..9aa7e8c9 100755 --- a/ingestschemas.sh +++ b/ingestschemas @@ -19,4 +19,4 @@ eventType="ingest" _report_to_db _report_schema_db _eventoutcome_update -done \ No newline at end of file +done From 71e99ba21e99067bfb1b75da6663f139c0705563 Mon Sep 17 00:00:00 2001 From: Andrew Weaver Date: Fri, 10 Feb 2017 15:15:10 -0500 Subject: [PATCH 5/5] changed tables --- createpremisdb | 4 ++-- mmfunctions | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/createpremisdb b/createpremisdb index 3ba367ab..e79f045c 100755 --- a/createpremisdb +++ b/createpremisdb @@ -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 diff --git a/mmfunctions b/mmfunctions index f467bd48..5b973dba 100755 --- a/mmfunctions +++ b/mmfunctions @@ -58,14 +58,15 @@ _report_schema_db(){ 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)" -n "${xmlschema}") + 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 @@ -140,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"