diff --git a/miria-archive b/miria-archive new file mode 100755 index 0000000..78699d1 --- /dev/null +++ b/miria-archive @@ -0,0 +1,81 @@ +################################################################################ +# Copyright 2022 Antonin Portelli +# +# This file is part of miria-cli. +# +# miria-cli is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# miria-cli is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# miria-cli. If not, see . +################################################################################ + +#!/usr/bin/env bash + +set -uoe pipefail + +script_dir=$(dirname $(readlink -f $0)) +source ${script_dir}/functions.sh +miria_get_url +miria_get_agent + +print_usage() { + echo "usage: $(basename $0) -p -s [-x -d ]" 1>&2 + echo "" 1>&2 + echo "flags:" 1>&2 + echo " -p: destination project" 1>&2 + echo " -d: destination directory (default: /)" 1>&2 + echo " -s: source local directory (global path, must be available in Miria)" + echo " -x: show raw XML answer" 1>&2 +} + +project='' +src='' +dest='/' +xml='false' +while getopts 'xp:s:d:' flag; do + case "${flag}" in + p) project="${OPTARG}" ;; + s) src="${OPTARG}" ;; + d) dest="${OPTARG}" ;; + x) xml='true' ;; + *) print_usage + exit 1 ;; + esac +done +if [[ -z "${project}" ]]; then + miria_error "missing -p flag" + print_usage + exit 1 +fi +if [[ -z "${src}" ]]; then + miria_error "missing -s flag" + print_usage + exit 1 +fi +# TODO: the /mnt/lustre prefix is here to fix path mismatch +# between tursa-login1 and tursa-dt1 and should be removed +if [[ -d "/mnt/lustre/${src}" ]]; then + miria_api_cmd archiveFolder "src=${miria_agent}@${src}" \ + "dst=${project}@${dest}" \ + "archiving_policy=Project%20Archive" +elif [[ -f "/mnt/lustre/${src}" ]]; then + miria_api_cmd archiveFile "src=${miria_agent}@${src}" \ + "dst=${project}@${dest}" \ + "archiving_policy=Project%20Archive" +else + miria_error "path ${src} invalid" + exit 1 +fi +if [[ "${xml}" == "true" ]]; then + echo "${miria_last_xml}" +else + job="$(miria_xml_get_string "${miria_last_xml}" '//job_id')" + echo "archive task submission successful, job ID ${job}" +fi