Xenith Orb avatar Xenith Orb committed ba66f8f

Added case for single volume, port availability checking, and other various checks.

Comments (0)

Files changed (1)

 	while [[ $count -lt $rows ]]; do
 		vol_name[$count]="${table[(2*$count)]}"
 		vol_size[$count]="${table[(2*$count)+1]}"
-		count=$(($count+1))
+		((count++))
 	done
 }
 print_sizes () {
 	echo -e "-----------\t\t----"
 	while [[ $count -lt $rows ]]; do
 		echo -e "${vol_name[$count]}\t\t${vol_size[$count]}GB"
-		count=$(($count+1)) 
+		((count++))
 	done
 }
 create_snaps () {
 	local count=0
 	for lvname in ${vol_name[@]}; do 
 		ssh root@${REMOTE_HOST} "lvcreate -L \"${vol_size[$count]}G\" -n ${lvname} ${TARGET_VGNAME}"
-		count=$(($count+1))
+		((count++))
 	done 
 }
+mk_port () { 
+	PORT=$(awk 'BEGIN{srand();print int(rand()*(63000-2000))+2000 }')
+}
+check_port () {
+	while [[ $( lsof -i :${PORT} ) ]]; do mk_port; done
+} 
+clone_single_lvolume () {
+	for lvname in $1; do
+		mk_port
+		for (( check=1; check == 1; ));  do
+			check_port
+			echo -e "Starting clone of: ${lvname}-${SUFFIX}" 
+			ssh -f root@${REMOTE_HOST} "nc -l -p ${PORT} | gunzip -c | dd conv=notrunc,noerror bs=${BYTE_SIZE} of=/dev/${TARGET_VGNAME}/${lvname}"
+			sleep 2
+			dd conv=notrunc,noerror bs=${BYTE_SIZE} if="/dev/${SOURCE_VGNAME}/${lvname}-${SUFFIX}" | gzip -c | nc -q5 ${REMOTE_HOST} ${PORT}
+			check="$?"
+		done 
+	done
+}
 clone_lvolumes () {
 	for lvname in ${vol_name[@]}; do
-		PORT=$(awk 'BEGIN{srand();print int(rand()*(63000-2000))+2000 }') 
-		echo -e "Starting clone of: ${lvname}-${SUFFIX}" 
-		ssh -f root@${REMOTE_HOST} "nc -l -p ${PORT} | gunzip -c | dd conv=notrunc,noerror bs=${BYTE_SIZE} of=/dev/${TARGET_VGNAME}/${lvname}"
-		sleep 2 
-		dd conv=notrunc,noerror bs=${BYTE_SIZE} if="/dev/${SOURCE_VGNAME}/${lvname}-${SUFFIX}" | gzip -c | nc -q5 ${REMOTE_HOST} ${PORT} 
+		mk_port
+		for (( check=1; check == 1; ));  do
+			check_port
+			echo -e "Starting clone of: ${lvname}-${SUFFIX}" 
+			ssh -f root@${REMOTE_HOST} "nc -l -p ${PORT} | gunzip -c | dd conv=notrunc,noerror bs=${BYTE_SIZE} of=/dev/${TARGET_VGNAME}/${lvname}"
+			sleep 2
+			dd conv=notrunc,noerror bs=${BYTE_SIZE} if="/dev/${SOURCE_VGNAME}/${lvname}-${SUFFIX}" | gzip -c | nc -q5 ${REMOTE_HOST} ${PORT}
+			check="$?"
+		done 
 	done
 }
-########### Older function for using with a presetup NBD device 
-#	clone_lvolumes () {
-#		for lvname in ${vol_name[@]}; do
-#			dd if="/dev/${SOURCE_VGNAME}/${lvname}-${SUFFIX}" of="/dev/${TARGET_VGNAME}/${lvname}" \
-#			ibs=1024 conv=noerror 
-#		done
-#	}
 show_help () { 
 	echo -ne "\nUsage:\t ${SCRIPTNAME}  -r, create-remote\t	Create remote volumes.\n"
 	echo -ne "	 ${SCRIPTNAME}  -c, create-snaps\t	Create local snapshots.\n"
 	    get_names_and_sizes
 	    clone_lvolumes
 	;;
+	(clone' '[[:alnum:]]*|-s' '[[:alnum:]]*)
+	    get_names_and_sizes
+	    clone_single_lvolume $2
+	;;
 	view|-v)
 	    get_names_and_sizes
 	    print_sizes
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.