From cdfc32edfe5a94d94088d2a86af0abd43ad927d5 Mon Sep 17 00:00:00 2001
From: Steven Murray <Steven.Murray@cern.ch>
Date: Thu, 13 Jul 2017 19:40:14 +0200
Subject: [PATCH] Added the retrieve_archive_file EOS wfe script

---
 eos_wfe_scripts/retrieve_archive_file | 39 +++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100755 eos_wfe_scripts/retrieve_archive_file

diff --git a/eos_wfe_scripts/retrieve_archive_file b/eos_wfe_scripts/retrieve_archive_file
new file mode 100755
index 0000000000..a68f81af21
--- /dev/null
+++ b/eos_wfe_scripts/retrieve_archive_file
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+EINVAL=22
+ECANCELED=125
+export XrdSecPROTOCOL=sss
+export XrdSecSSSKT=/etc/cta/cta-cli.sss.keytab
+
+if test $# -ne 9; then
+  echo "Wrong number of command-line arguments"
+  echo "Usage: retrieve_archive_file wf_tag rusername rgroupname archive_file_id turl disk_username disk_groupname metadata_base64 file_path"
+  exit ${EINVAL}
+fi
+
+WF_TAG="$1"
+RUSERNAME="$2"
+RGROUPNAME="$3"
+ARCHIVE_FILE_ID="$4"
+TURL="$5"
+DISK_USERNAME="$6"
+DISK_GROUPNAME="$7"
+METADATA_BASE64="$8"
+FILE_PATH="$9"
+
+DST_URL=${TURL}'\&eos.ruid=0&eos.rgid=0\&eos.injection=1\&eos.workflow=CTA_retrieve'
+
+LOG_FILE="/var/log/eos/wfe/${WF_TAG}.log"
+
+if test UNDEF = ${ARCHIVE_FILE_ID}; then
+  echo `date +%s` `date`" $0 Cannot retrieve an archive file without the sys.archiveFileId attribute being set: rusername=${RUSERNAME} rgroupname=${RGROUPNAME} archiveFileId=${ARCHIVE_FILE_ID} dsturl=${DST_URL} disk_username=${DISK_USERNAME} disk_groupname=${DISK_GROUPNAME} path=${FILE_PATH}" >> ${LOG_FILE}
+  exit ${ECANCELED}
+fi
+
+if RESULT=`2>&1 /usr/bin/cta retrieve --user ${RUSERNAME} --group ${RGROUPNAME} --id ${ARCHIVE_FILE_ID} --dsturl ${DST_URL} --diskfilepath ${FILE_PATH} --diskfileowner ${DISK_USERNAME} --diskfilegroup ${DISK_GROUPNAME} --recoveryblob:base64 ${METADATA_BASE64}`; then
+  echo `date +%s` `date`" $0 Queued retrieve request: rusername=${RUSERNAME} rgroupname=${RGROUPNAME} archiveFileId=${ARCHIVE_FILE_ID} dsturl=${DST_URL} disk_username=${DISK_USERNAME} disk_groupname=${DISK_GROUPNAME} path=${FILE_PATH}" >> ${LOG_FILE}
+  exit 0
+else
+  echo `date +%s` `date`" $0 Failed to queue retrieve request: error=${RESULT} rusername=${RUSERNAME} rgroupname=${RGROUPNAME} archiveFileId=${ARCHIVE_FILE_ID} dsturl=${DST_URL} disk_username=${DISK_USERNAME} disk_groupname=${DISK_GROUPNAME} path=${FILE_PATH}" >> ${LOG_FILE}
+  exit ${ECANCELED}
+fi
-- 
GitLab