Skip to content
Snippets Groups Projects
Commit 0dfc9ef6 authored by Andri Joos's avatar Andri Joos :blush:
Browse files

use rsync to copy directories

parent a600a5d5
No related branches found
No related tags found
No related merge requests found
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
test_host="testcluster"
prod_host="prodcluster"
path=$1;
test_path="${TEST_NFS_PATH%%+(/)}$path"
prod_path="${PROD_NFS_PATH%%+(/)}$path"
source_host=$prod_host
destination_host=$test_host
source_path=$prod_path
destination_path=$test_path
source_ssh_config=$PROD_SSH_CONFIG
destination_ssh_config=$TEST_SSH_CONFIG
if [ $PROD = "true" ]
then
# source_host=$test_host
# destination=$prod_host
# source_path=$test_path
# destination_path=$prod_path
# source_ssh_config=$TEST_SSH_CONFIG
# destination_ssh_config=$PROD_SSH_CONFIG
echo "test to prod copy not supported"
exit 1
fi
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"
ssh -F $destination_ssh_config $destination_host "mkdir -p $destination_path"
fi
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment