Commit 11c3a591 authored by Jonathan Schaeffer's avatar Jonathan Schaeffer

Integritycheck after transfer

parent 492cc4b8
......@@ -49,6 +49,7 @@ format_report(){
# If everything goes fine, then validate staging data
irods_push(){
KEY=$1
LOCAL_SHA=$2
SIZE=$(stat -c %s $RESIFDD_WORKDIR/$KEY.tar)
SIZEMB=$(($SIZE/1024/1024))
......@@ -63,7 +64,7 @@ irods_push(){
irm -f $KEY/staging.tar > /dev/null 2>&1
echo "[$KEY] Sending data to iRODS ($SIZEMB MB)"
COMMAND="iput --retries 5 -T -K -f -X $RESIFDD_WORKDIR/${KEY}.restart $RESIFDD_WORKDIR/${KEY}.tar $KEY/staging.tar"
COMMAND="iput --retries 5 -T -f -X $RESIFDD_WORKDIR/${KEY}.restart $RESIFDD_WORKDIR/${KEY}.tar $KEY/staging.tar"
start=$(date +%s)
eval $COMMAND
IPUTRC=$?
......@@ -77,6 +78,14 @@ irods_push(){
else
duration=$(($(date +%s)-$start))
throughput=$(($SIZEMB / $duration ))
# Check integrity.
# We do it separately from transfer because for big files it can be very long, and the network can cut
irods_sha=$(ichksum $KEY/staging.tar | awk -F':' '/sha2:/ {print $2; exit;}')
if [[ "$LOCAL_SHA" != "$irods_sha" ]]; then
echo "[$KEY] Error 012 distant file is corrupted (localsha $LOCAL_SHA irodssha $irods_sha). Rollback"
irods_rollback $KEY
zabbix_err "${KEY}:Error 012"
fi
echo "[$KEY] staging.tar data sent, let's commit everything on irods server"
format_report $KEY $SIZEMB $(date +%Y-%m-%dT%H:%M:%S --date=@$start) $duration $throughput 'OK' >> $LOCAL_REPORT
irods_commit $KEY
......@@ -95,6 +104,7 @@ irods_push(){
# Argument is the distant directory to work with
irods_rollback(){
KEY=$1
irm -f ${KEY}/staging.tar
echo "[$KEY] Rollback : try to recover latest.tar from previous"
ils ${KEY}/previous.tar 2>/dev/null && (
imv ${KEY}/previous.tar ${KEY}/latest.tar
......@@ -200,7 +210,7 @@ pack_and_send() {
fi
fi
# Send latest archive file to IRODS
irods_push $KEY
irods_push $KEY $local_sha
rm $RESIFDD_WORKDIR/$KEY*
}
......@@ -280,7 +290,8 @@ else
zabbix_err "${KEY}:Error 001"
exit 1
fi
irods_push $KEY
local_sha=$(sha256sum $RESIFDD_WORKDIR/$KEY.tar | awk '{print $1}' | xxd -r -p | base64)
irods_push $KEY $local_sha
echo "[$KEY] Dump terminated :"
ils -l $KEY
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment