Compare commits
8 Commits
aacd713265
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d8d23ab2ff | |||
| 5707dc659a | |||
| 819abd9d24 | |||
| 1e73ad7590 | |||
| 6d1c2172ab | |||
| ff54e1e74a | |||
| 91205d200c | |||
| e766f4030b |
19
Readme.md
Normal file
19
Readme.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# CLI for Atempo Miria tape archive
|
||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||
|
||||
Command line tools to interact with an Atempo Miria tape archive.
|
||||
All commands rely on the Miria Webservices API, and assume that the user
|
||||
has a `.miria` file in their home directory following the template
|
||||
```
|
||||
url <url>
|
||||
agent <hostname>
|
||||
```
|
||||
where `<url>` is the API URL generated with
|
||||
```
|
||||
ada_service -build_url | -build_url_s -identity <user>:<password>
|
||||
```
|
||||
(e.g. `http://adadoc:85/meta/BD117E7D5CF0912AEA17B4DF33D63F7E/721b766531/ADA/WS`)
|
||||
and `<hostname>` is the host name of the Miria agent mounting the local
|
||||
filesystem.
|
||||
|
||||
*It is strongly recommended to have the `.miria` file with mode 640 or 600 since the URL allows control of the archive without additional authentication.*
|
||||
43
functions.sh
43
functions.sh
@@ -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
|
||||
@@ -90,6 +111,18 @@ miria_xml_get_string() {
|
||||
echo "${xml}" | xmllint --xpath "string(${xpath})" -
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Get XML string(s) from last answer
|
||||
#
|
||||
# Arguments:
|
||||
# XPath of string
|
||||
#######################################
|
||||
miria_last_get_string() {
|
||||
local xpath="$1"
|
||||
|
||||
miria_xml_get_string "${miria_last_xml}" "//${xpath}"
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Get XML attribute value(s)
|
||||
#
|
||||
|
||||
@@ -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 -
|
||||
echo "${miria_last_xml}"
|
||||
|
||||
81
miria-archive
Executable file
81
miria-archive
Executable 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
|
||||
@@ -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
|
||||
|
||||
38
miria-info
Executable file
38
miria-info
Executable file
@@ -0,0 +1,38 @@
|
||||
################################################################################
|
||||
# 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
|
||||
hash="$(cd ${script_dir}; git rev-parse --short HEAD)"
|
||||
branch="$(cd ${script_dir}; git rev-parse --abbrev-ref HEAD)"
|
||||
status="$(git diff --quiet || echo '(dirty)')"
|
||||
miria_get_url
|
||||
echo "Miria CLI ${branch}@${hash} ${status}"
|
||||
echo 'Copyright 2022 Antonin Portelli'
|
||||
echo 'GNU General Public License v3'
|
||||
echo ''
|
||||
echo '-- Server info -------------'
|
||||
miria_api_cmd getServerInfo
|
||||
printf '%s:%s\n' "$(miria_last_get_string '//SERVER_NAME')" \
|
||||
"$(miria_last_get_string '//SERVER_PORT')"
|
||||
miria_last_get_string '//TPE'
|
||||
miria_last_get_string '//ADA'
|
||||
echo '----------------------------'
|
||||
Reference in New Issue
Block a user