Skip to content

Commit

Permalink
renameschemas: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dericed committed Oct 19, 2015
1 parent ab35aaf commit db70662
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions renameschemas
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

0 comments on commit db70662

Please sign in to comment.