Compare commits

..

3 Commits

Author SHA1 Message Date
ff54e1e74a archive command 2022-03-26 00:25:17 +00:00
91205d200c miria-find path syntax fix 2022-03-26 00:15:34 +00:00
e766f4030b API call improvement 2022-03-26 00:10:40 +00:00
4 changed files with 109 additions and 6 deletions

View File

@@ -33,12 +33,31 @@ miria_error() {
#
# Arguments:
# None
# Output:
# miria_url : Miria API URL
#######################################
miria_get_url() {
if [ -e ~/.miria-url ]; then
miria_url="$(cat ~/.miria-url)"
if [ -e ~/.miria ]; then
miria_url="$(grep -E ' *url +' ~/.miria | awk '{print $2}')"
else
miria_error 'file ~/.miria-url not found'
miria_error 'file ~/.miria not found'
exit 1
fi
}
#######################################
# Get Mira agent
#
# Arguments:
# None
# Output:
# miria_agent : Miria agent name
#######################################
miria_get_agent() {
if [ -e ~/.miria ]; then
miria_agent="$(grep -E ' *agent +' ~/.miria | awk '{print $2}')"
else
miria_error 'file ~/.miria not found'
exit 1
fi
}
@@ -56,6 +75,8 @@ miria_get_url() {
# miria_last_status : last return code
# miria_last_error : last error message
#######################################
miria_api_error_fatal='true'
miria_api_cmd() {
local url_args=()
local cmd="$1"
@@ -63,13 +84,13 @@ miria_api_cmd() {
miria_get_url
shift
for a in "$@"; do
url_args+=('--data-urlencode')
url_args+=('--data')
url_args+=("${a}")
done
miria_last_xml="$(curl -sG "${url_args[@]}" "${miria_url}/${cmd}")"
miria_last_status="$(miria_xml_get_attribute "${miria_last_xml}" '//ReturnCode' 'ADARetCode')"
miria_last_error="$(miria_xml_get_string "${miria_last_xml}" '//ErrorMsg')"
if [[ "${miria_last_status}" != "1" ]]; then
if [[ "${miria_last_status}" != '1' ]] && [[ "${miria_api_error_fatal}" == 'true' ]]; then
miria_error "Miria API call returned status ${miria_last_status}"
miria_error "${miria_last_error}"
exit 1

View File

@@ -33,5 +33,6 @@ if (( $# < 1 )); then
fi
cmd="$1"
shift
miria_api_error_fatal='false'
miria_api_cmd "${cmd}" "$@"
echo ${miria_last_xml} | xmllint --format -

81
miria-archive Executable file
View File

@@ -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 <https://www.gnu.org/licenses/>.
################################################################################
#!/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 <project> -s <path> [-x -d <directory>]" 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

View File

@@ -60,7 +60,7 @@ dir="$(dirname "${pattern}")"
if [[ "${dir}" == "." ]]; then
dir=''
fi
miria_api_cmd fileSearch "filename=${base}" "path=${project}@/${dir}"
miria_api_cmd fileSearch "filename=${base}" "path=${project}@${dir}"
if [[ "${xml}" == "true" ]]; then
echo "${miria_last_xml}"
else