#!/bin/bash ############################ # Variables # ############################ # User's ID USRID=`id -un` # Source Shamu server for copy SOURCE_SVR=login.shamu.utsa.edu # Destination Arc server for copy DEST_SVR=arc.utsa.edu ############################ # Functions # ############################ display_usage_and_exit () { echo -e "\nUsage: $ migrate-shamu2arc [help] home|work|both\n" exit } display_help () { echo -e "\nThis script is meant to help users move their data from the Shamu HPC environment" echo -e "to the Arc HPC environment using rsync. The script will move either the user's " echo -e "home, work or both directories from Shamu to Arc. It accepts one argument " echo -e "indicating which option to use." echo echo -e "If subdirectories or paths other than /home/abc123 or /work/abc123 need to be copied" echo -e "or other rsync options are needed, use the rsync linux utility directly." echo -e "See https://hpcsupport.utsa.edu/foswiki/bin/view/ARC/MigratingDataToArc" echo -e "for more information." display_usage_and_exit } get_final_approval () { echo -e "\nRsync will copy..." if [ $1 = "home-new" -o $1 = "work" ] then echo -e "From: ${USRID}@${SOURCE_SVR}:/$1/${USRID}" echo -e "To: ${USRID}@${DEST_SVR}:/$1/${USRID}\n" echo -e "Note that you will be prompted for your Shamu credentials to start the copy.\n" else echo -e "From: ${USRID}@${SOURCE_SVR}:/home-new/${USRID}" echo -e "To: ${USRID}@${DEST_SVR}:/home-new/${USRID}" echo -e " And" echo -e "From: ${USRID}@${SOURCE_SVR}:/work/${USRID}" echo -e "To: ${USRID}@${DEST_SVR}:/work/${USRID}\n" echo -e "Note that you will be prompted for your Shamu credentials twice for the copies." echo -e "Once for the \"home\" directory and the other for the \"work\" directory.\n" fi echo -e "Also, note that any files from Shamu that already exist on Arc will not be copied over.\n" read -n 1 -r -p "Enter Y|y to proceed, any other key to cancel:" echo if [[ ! $REPLY =~ ^[Yy]$ ]] then echo -e "\nCancelled per user request." exit 1 fi } do_rsync () { get_final_approval $1 if [ $1 = "home-new" ] then rsync -avtr --ignore-existing -e 'ssh -p 1209' ${USRID}@${SOURCE_SVR}:/$1/${USRID}/ /home/${USRID}/testrsync elif [ $1 = "work" ] then rsync -avtr --ignore-existing -e 'ssh -p 1209' ${SOURCE_PORT_OPTION} ${USRID}@${SOURCE_SVR}:/$1/${USRID}/ /$1/${USRID} else rsync -avtr --ignore-existing -e 'ssh -p 1209' ${SOURCE_PORT_OPTION} ${USRID}@${SOURCE_SVR}:/home-new/${USRID}/ /home/${USRID} rsync -avtr --ignore-existing -e 'ssh -p 1209' ${SOURCE_PORT_OPTION} ${USRID}@${SOURCE_SVR}:/work/${USRID}/ /work/${USRID} fi } ############################ # MAIN # ############################ # Validate argument - there should only be one [ $# -lt 1 -o $# -gt 2 ] && display_usage_and_exit # Verify script is being run on Arc RUNLOCATION=`sacctmgr -n show cluster format=cluster` if [[ ! $RUNLOCATION =~ "arc_clust+" ]] then echo -e "\nThis script is ony meant to be run on nodes in the Arc cluster.\n" exit 1 fi # Process through the arguments for arg in "$@" do case $arg in help) display_help ;; home) # Setup to rsync home directory do_rsync home-new ;; work) # Setup to copy work directory do_rsync work ;; both) # Copy both home & work directory do_rsync both ;; *) echo -e "\nError: Received an invalid argument\n" display_help echo -e "\nExiting." esac done