-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
# mountlto | ||
|
||
SCRIPTDIR=$(dirname "${0}") | ||
|
||
_usage(){ | ||
echo "renameschemas" | ||
echo "Currently this script only works with in -u mode. It 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." | ||
echo "Usage:" | ||
echo " -u [change dir-named schema files to the tape uuid]" | ||
exit 1 | ||
} | ||
|
||
. "${SCRIPTDIR}/ltofunctions" || { echo "Missing '${SCRIPTDIR}/ltofunctions'. Exiting." ; exit 1 ;}; | ||
|
||
[ "${#}" = 0 ] && _usage | ||
# command-line options | ||
OPTIND=1 | ||
while getopts ":un" opt ; do | ||
case "${opt}" in | ||
u) RENAME2UUID="Y" ;; | ||
n) RENAME2NAME="Y" ;; | ||
*) echo "bad option -${OPTARG}" ; usage ;; | ||
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;; | ||
esac | ||
done | ||
shift $(( ${OPTIND} - 1 )) | ||
|
||
LTO_LOGS="${HOME}/Documents/lto_indexes" | ||
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\}" | 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 |