-
Notifications
You must be signed in to change notification settings - Fork 8
/
renameschemas
executable file
·65 lines (53 loc) · 2.09 KB
/
renameschemas
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
#!/usr/bin/env bash
# renameschemas
SCRIPTDIR=$(dirname "${0}")
. "${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 finds all .schema LTFS indexes in the LTO_LOGS directory and renames
them to use the top-level file system directory name rather than the UUID. Any
conflicting filenames are moved to another folder if needed.
Usage: $(basename "${0}") -u | -h
-u change dir-named schema files to the tape UUID
-h display this help
EOF
}
[[ -z "${#}" ]] && { _usage ; exit 1 ; }
OPTIND=1
while getopts ":uh" opt ; do
case "${opt}" in
u) RENAME2UUID="Y" ;;
h) _usage ; exit 0 ;;
*) echo "Error: Bad option -${OPTARG}" ; _usage ; exit 1 ;;
esac
done
shift "$((OPTIND-1))"
_check_for_lto_index_dir
LTO_LOGS="${LTO_INDEX_DIR}"
OLD_LOGS="${LTO_LOGS}/old/"
if [[ ! -d "${OLD_LOGS}" ]] ; then
mkdir -p "${OLD_LOGS}"
fi
if [[ "${RENAME2UUID}" = "Y" ]] ; then
ls -1t "${LTO_LOGS}" | grep "[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}.schema" | while read UUID_NAME ; do
UUID_PATH="${LTO_LOGS}/${UUID_NAME}"
NAME_PATH="${LTO_LOGS}/$(xml sel -t -m "/ltfsindex" -v directory[1]/name "${LTO_LOGS}/${UUID_NAME}").schema"
if [[ -f "${NAME_PATH}" ]] ; then
UUID_UPDATETIME=$(xml sel -t -m "/ltfsindex" -v updatetime "${UUID_PATH}")
NAME_UPDATETIME=$(xml sel -t -m "/ltfsindex" -v updatetime "${NAME_PATH}")
if [[ "$UUID_UPDATETIME" < "$NAME_UPDATETIME" ]] ; then
mv -v "${UUID_PATH}" "${OLD_LOGS}"
else
mv -v "${NAME_PATH}" "${OLD_LOGS}"
mv -v -n "${UUID_PATH}" "${NAME_PATH}"
fi
else
mv -v -n "${UUID_PATH}" "${NAME_PATH}"
fi
done
fi