diff --git a/copy_directories.sh b/copy_directories.sh deleted file mode 100644 index 96fcfc58304c63a406c8f7657c7d6bfd8ccbd148..0000000000000000000000000000000000000000 --- a/copy_directories.sh +++ /dev/null @@ -1,71 +0,0 @@ -source mount_nfs.sh - -MKDIR="mkdir -p"; -COPY_DIR="cp -rp"; - -mount_nfs - -i=1; # first arg is script -j=$#; -while [ $i -le $j ] # iterate through arguments -do - DESTINATION_DATA_PATH="$TEST_MOUNT_PATH/$1"; - SOURCE_DATA_PATH="$PROD_MOUNT_PATH/$1"; - - if [ "$PROD" = "true" ] - then - DESTINATION_DATA_PATH="$PROD_MOUNT_PATH/$1"; - SOURCE_DATA_PATH="$TEST_MOUNT_PATH/$1"; - fi - - echo "$i: $DESTINATION_DATA_PATH"; - - if [ -d "$DESTINATION_DATA_PATH" ] # directory exists - then - - if [ -z "$(ls -A $DESTINATION_DATA_PATH)" ] # is directory empty - then - if [ -d "$SOURCE_DATA_PATH" ] # source path exists - then - if [ "$COPY_FILES" = "true" ] - then - DESTINATION_DATA_PATH="$(dirname "$DESTINATION_DATA_PATH")" - echo "copying $SOURCE_DATA_PATH to $DESTINATION_DATA_PATH" - $MKDIR $DESTINATION_DATA_PATH; - $COPY_DIR "$SOURCE_DATA_PATH" $DESTINATION_DATA_PATH; - echo "copied source $SOURCE_DATA_PATH to $DESTINATION_DATA_PATH" - else - echo "COPY_FILES is false; skipping copy" - fi - else - echo "cannot copy, source $SOURCE_DATA_PATH does not exist; skipping"; - fi - else - echo "$DESTINATION_DATA_PATH is not empty; skipping copy data."; - fi - - else - if [ -d "$SOURCE_DATA_PATH" ] # source path exists - then - if [ "$COPY_FILES" = "true" ] - then - DESTINATION_DATA_PATH="$(dirname "$DESTINATION_DATA_PATH")" - echo "copying $SOURCE_DATA_PATH to $DESTINATION_DATA_PATH" - $MKDIR $DESTINATION_DATA_PATH; - $COPY_DIR "$SOURCE_DATA_PATH" $DESTINATION_DATA_PATH; - echo "copied source $SOURCE_DATA_PATH to $DESTINATION_DATA_PATH" - else - $MKDIR $DESTINATION_DATA_PATH - echo "COPY_FILES is false; created empty dir" - fi - else - $MKDIR $DESTINATION_DATA_PATH - echo "cannot copy, source $SOURCE_DATA_PATH does not exist; empty folder created"; - fi - fi - - i=$((i + 1)); - shift 1; -done - -unmount_nfs diff --git a/copy_directory.sh b/copy_directory.sh new file mode 100644 index 0000000000000000000000000000000000000000..76933ab6c53664dce89bf5648078b76667ce36a0 --- /dev/null +++ b/copy_directory.sh @@ -0,0 +1,29 @@ +if [ $PROD = "true" ] +then + echo "test to prod copy not supported" + exit 1 +fi + +path=$1; + +directory_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "$directory_path/variables/path_variables.sh" "$path" +source "$directory_path/variables/ssh_variables.sh" + +source="$source_host:$source_path" +destination="$destination_host:$destination_path" +destination_host_ip="$(grep 'HostName' ${destination_ssh_config} | awk '{print $2}')" +destination_username="$(grep 'User' ${destination_ssh_config} | awk '{print $2}')" + +echo "PROD: $PROD" + +if ssh -F $source_ssh_config $source_host "[ -d $source_path ]" +then + copy_destination_path=$(dirname "$destination_path") + echo "copying $path from $source_host to $destination_host" + ssh -A -F $source_ssh_config $source_host rsync -avP $source_path $destination_username@$destination_host_ip:$copy_destination_path +else + echo "$path does not exist in $source_host, creating empty directory in $destination_host" + bash "$directory_path/create_empty_directory.sh" "$path" +fi diff --git a/create_empty_directory.sh b/create_empty_directory.sh new file mode 100644 index 0000000000000000000000000000000000000000..b1483b6f755ed2677eab3d65b79371a96551c34b --- /dev/null +++ b/create_empty_directory.sh @@ -0,0 +1,8 @@ +path=$1; + +directory_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "$directory_path/variables/path_variables.sh" "$path" +source "$directory_path/variables/ssh_variables.sh" + +ssh -F $destination_ssh_config $destination_host "mkdir -p $destination_path" diff --git a/variables/path_variables.sh b/variables/path_variables.sh new file mode 100644 index 0000000000000000000000000000000000000000..403ca3c1183a6cfd4ee97e64cc9413bf9039000a --- /dev/null +++ b/variables/path_variables.sh @@ -0,0 +1,13 @@ +path=$1; + +test_path="${TEST_NFS_PATH%%+(/)}$path" +prod_path="${PROD_NFS_PATH%%+(/)}$path" + +source_path=$prod_path +destination_path=$test_path + +if [ $PROD = "true" ] +then + source_path=$test_path + destination_path=$prod_path +fi diff --git a/variables/ssh_variables.sh b/variables/ssh_variables.sh new file mode 100644 index 0000000000000000000000000000000000000000..c5f7ac452434d744d47099a607b8e2a51c875f54 --- /dev/null +++ b/variables/ssh_variables.sh @@ -0,0 +1,15 @@ +test_host="testcluster" +prod_host="prodcluster" + +source_host=$prod_host +destination_host=$test_host +source_ssh_config=$PROD_SSH_CONFIG +destination_ssh_config=$TEST_SSH_CONFIG +if [ $PROD = "true" ] +then + source_host=$test_host + destination=$prod_host + + source_ssh_config=$TEST_SSH_CONFIG + destination_ssh_config=$PROD_SSH_CONFIG +fi