Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CSchloss385 committed Feb 22, 2017
1 parent 5b2b463 commit 0b9121f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions migratelto
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

#migratelto
#This script transfers files from an LTO tape. Script uses gcp.

SCRIPTDIR=$(dirname "${0}")
TAPE_MOUNT_POINT="/Volumes"
TAPE_EJECT="Y"

. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ; }

_usage(){
echo
echo "This script moves files from an lto tape to another location."
echo "Usage: $(basename "${0}") -t [-e]"
echo " -e state yes (Y) or no (N) to ejecting the tape after migration, default"
echo " is yes"
echo
}

OPTIND=1
while getopts ":t:e" opt ; do
case "${opt}" in
t) TAPE_SERIAL="${OPTARG}" ;;
e) TAPE_EJECT="${OPTARG}" ;;
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
*) echo "Bad option -${OPTARG}" ; _usage ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))

SOURCE_DIR="${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, possibly followed by 'L5', 'L6' or 'L7' specifying the LTO generation."
_usage
fi

TAPE_PATH="${TAPE_MOUNT_POINT}/${TAPE_SERIAL}"
_checkdir "${TAPE_PATH}"

gcp --preserve=mode,timestamps -nRv "${TAPE_PATH}" "${SOURCE_DIR}/"*

case "${TAPE_EJECT}" in
y|Y) umount "${TAPE_PATH}" ;;
*) echo "Done migrating but not ejecting ${TAPE_SERIAL}." ;;
esac

0 comments on commit 0b9121f

Please sign in to comment.