Last active
August 3, 2017 12:21
-
-
Save maxfischer2781/f47df36bf299b336112ae0ac4ac1835f to your computer and use it in GitHub Desktop.
Script to launch a migration of an XROOTD namespace conforming to the ALICE VO conventions
This file contains hidden or 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
NAMESPACE=${NAMESPACE:-"/export/xrootd/"} | |
RSYNC_ADDR=${RSYNC_ADDR:-"rsync://f01-120-179/alice-xrootd/"} | |
NS_START=${NS_START:-"00"} | |
NS_STOP=${NS_STOP:-"15"} | |
#!/bin/bash | |
if [[ "$*" =~ " -h" ]] || [[ "$*" =~ ^-h ]] || [[ "$*" =~ "--help" ]] | |
then | |
echo "usage:" >&2 | |
echo " <script> [NAMESPACE [RSYNC_ADDR [NS_START NS_STOP]]]" >&2 | |
echo "" >&2 | |
echo "Migrate an ALICE namespace rooted at NAMESPACE to an rsync daemon at RSYNC_ADDR" >&2 | |
echo "If NS_START and NS_STOP are defined, move the respective subdirectories only" | |
echo "" >&2 | |
echo "This launches a sequence of rsync processes to transfer" >&2 | |
echo "the namespace to the remote daemon. Note that the target" >&2 | |
echo "environment must have been set up properly for writing." >&2 | |
echo "" >&2 | |
echo "The rsync processes are launched in a screen session." >&2 | |
echo "" >&2 | |
echo "Defaults:" >&2 | |
echo " NAMESPACE ${NAMESPACE}" >&2 | |
echo " RSYNC_ADDR ${RSYNC_ADDR}" >&2 | |
echo " NS_START ${NS_START}" >&2 | |
echo " NS_STOP ${NS_STOP}" >&2 | |
exit | |
fi | |
SCREEN_NAME='alice-migration' | |
if screen -S "${SCREEN_NAME}" -X select . 2>/dev/null 1>&2 | |
then | |
echo "Screen '${SCREEN_NAME}' already exists" >&2 | |
exit 1 | |
fi | |
NAMESPACE=${1:-${NAMESPACE}} | |
RSYNC_ADDR=${2:-${RSYNC_ADDR}} | |
NS_START=${3:-${NS_START}} | |
NS_STOP=${4:-${NS_STOP}} | |
# make sure this is an ALICE namespace | |
for SEGMENT in $(seq -f '%02.0f' 0 15) | |
do | |
if [[ ! -d "${NAMESPACE}/${SEGMENT}" ]] | |
then | |
echo '$1 must point to the namespace root, but there' >&2 | |
echo "is no segment ${SEGMENT} in \$1=${NAMESPACE}" >&2 | |
exit | |
fi | |
done | |
echo "Migrating namespace ${NAMESPACE} to ${RSYNC_ADDR}" >&2 | |
# create screen session, set all windows to remain | |
screen -dmS "${SCREEN_NAME}" bash -c "echo 'Migrating from ${NAMESPACE} to ${RSYNC_ADDR}'; sleep 30" | |
screen -XS "${SCREEN_NAME}" zombie kr | |
# start a separate transfer for each segment of the SE | |
for SEGMENT in $(seq -f '%02.0f' ${NS_START} ${NS_STOP}) | |
do | |
LOG_FILE="${NAMESPACE}/${SCREEN_NAME}-${SEGMENT}.log" | |
screen -XS "${SCREEN_NAME}" screen -t "rsync ${SEGMENT}" bash -c "until rsync --recursive --copy-links --times --omit-dir-times --whole-file --relative --itemize-changes --log-file='${LOG_FILE}' '${NAMESPACE}/./${SEGMENT}' '${RSYNC_ADDR}';do echo 'rsync quit unexpectedly, retrying in 10 seconds...' >&2; sleep 10; done" | |
echo "Migrating ${SEGMENT} log-file=${LOG_FILE}" | |
done | |
echo "Launched migration of all segments" >&2 | |
echo "Run" >&2 | |
echo " screen -rdS '${SCREEN_NAME}'" >&2 | |
echo "to monitor progress" >&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment