-
Notifications
You must be signed in to change notification settings - Fork 8
/
readlto
executable file
·61 lines (50 loc) · 1.81 KB
/
readlto
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
#!/usr/bin/env bash
# readlto
# This script transfers files from an LTO tape to another location.
SCRIPTDIR=$(dirname "${0}")
DEPENDENCIES=(gcp)
TAPE_MOUNT_POINT="/Volumes"
TAPE_SERIAL_REGEX="^[A-Z0-9]{6}$"
TAPE_EJECT="Y"
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ; }
unset VERSION
if [[ $(dirname $(command -v "${0}")) = "/usr/local/bin" || $(dirname $(command -v "${0}")) = "${HOME}/.linuxbrew/bin" ]] ; then
VERSION=$(TMP=$(brew info ltopers | grep ".*\*$" | grep -Eo "/ltopers/.* \(") ; echo "${TMP:9:(${#TMP}-11)}")
fi
_usage(){
cat <<EOF
$(basename "${0}") ${VERSION}
This script moves files from an LTO tape to another location.
Usage: $(basename "${0}") -t [-e] | -h
-t tape serial number
-e state yes (Y) or no (N) to ejecting the tape after migration, default
is yes
-x use barcode label as tape serial (caveat: this is not standard)
-h display this help
EOF
}
OPTIND=1
while getopts ":t:e:xh" opt ; do
case "${opt}" in
t) TAPE_SERIAL="${OPTARG}" ;;
e) TAPE_EJECT="${OPTARG}" ;;
x) TAPE_SERIAL_REGEX="^[A-Z0-9]{6}(L[5-9]|M8)$" ;;
h) _usage ; exit 0 ;;
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
*) echo "Bad option -${OPTARG}" ; _usage ; exit 1 ;;
esac
done
shift "$((OPTIND-1))"
TARGET="${1}"
if [[ ! $(echo "${TAPE_SERIAL}" | grep -E "${TAPE_SERIAL_REGEX}") ]] ; then
echo "${TAPE_SERIAL} is not valid. The tape id must be exactly 6 capital letters and/or numbers."
exit 1
fi
TAPE_PATH="${TAPE_MOUNT_POINT}/${TAPE_SERIAL}"
_checkdir "${TAPE_PATH}"
_checkdir "${TARGET}"
gcp --preserve=mode,timestamps -nRv "${TAPE_PATH}/"* "${TARGET}/"
case "${TAPE_EJECT}" in
y|Y) umount "${TAPE_PATH}" ;;
*) echo "Done migrating but not ejecting ${TAPE_SERIAL}." ;;
esac