-
Notifications
You must be signed in to change notification settings - Fork 1
/
irods_backoff_move.sh
executable file
·71 lines (66 loc) · 2.01 KB
/
irods_backoff_move.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
#Script to call iphymv with exponential back-off
# Moves one object from SOURCE to DEST
# Call thus:
# irods_backof_move.sh SOURCE DEST object
# Copyright (C) 2020,2021 Genome Research Limited
#
# Author: Matthew Vernon <mv3@sanger.ac.uk>
#
# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
if [ "$#" -ne "3" ]; then
echo "Usage: irods_backoff_move.sh SOURCE DEST object"
exit 1
fi
# Must run as a rodsadmin user
if [ ! -O /etc/irods/server_config.json ]; then
echo "Must be run as the rodsadmin user"
exit 1
fi
# Function that does the work
phym()
{
for i in $(seq 0 8); do
# iphymv return value isn't very useful, so inspect stderr
msg=$(iphymv "$@" 2>&1)
rv="$?"
if [ "$rv" -eq 0 ]; then
if [ "$i" -gt 0 ]; then
echo "Took $i retries to do $*"
fi
return
else
echo "$msg"
if [[ "$msg" =~ "No space left on device" ]]; then
echo "Target full, stopping parallel"
# TERM means "do not start any new jobs"
kill -TERM "$PARALLEL_PID"
return "$rv"
# checksum mismatch or absent src not worth retrying
elif [[ "$msg" =~ "USER_CHKSUM_MISMATCH" ]] ||
[[ "$msg" =~ srcPath.*does\ not\ exist ]]; then
return "$rv"
# Assume other failures are transient, try to backoff
elif [ "$i" -lt 8 ]; then
sleep "$((2**i))"
else
echo "giving up on $*"
exit 1
fi
fi
done
echo "!!! This code is impossible to reach !!!"
exit 2
}
phym -M -S "$1" -R "$2" "$3"