Added verbose output
This commit is contained in:
parent
94fa4f5e72
commit
975280a456
31
prsync
31
prsync
|
|
@ -14,16 +14,18 @@ Options:
|
|||
-h, --help Print this message.
|
||||
-n, --dry-run Do not transfer any data.
|
||||
-r, --recursive Copy directories recursively
|
||||
-v, --verbose List files as they are transferred.
|
||||
EOF
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
declare -a positional flags_rsync flags_du
|
||||
positional=()
|
||||
flags_rsync=()
|
||||
flags_rsync=('-R' '-v' '--info=stats0,misc0,flist0')
|
||||
flags_du=('-b')
|
||||
flag_copy_links=0
|
||||
flag_recursive=0
|
||||
flag_verbose=0
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
'-h'|'--help')
|
||||
|
|
@ -47,6 +49,10 @@ while [[ $# -gt 0 ]]; do
|
|||
flag_recursive=1
|
||||
shift
|
||||
;;
|
||||
'-v'|'--verbose')
|
||||
flag_verbose=1
|
||||
shift
|
||||
;;
|
||||
-*|--*)
|
||||
echo "Invalid option: $1" >&2
|
||||
exit 1
|
||||
|
|
@ -110,7 +116,7 @@ src=($(echo "$tmp" | awk '{print $2}'))
|
|||
totalsize=$(IFS=+; echo "$((${filesize[*]}))")
|
||||
|
||||
# Create file lists
|
||||
dir_temp=$(mktemp -dt rsync.XXXXX)
|
||||
dir_temp=$(mktemp -dt prsync.XXXXX)
|
||||
for ((istream=0;istream<num_streams;istream++)); do
|
||||
file_temp="${dir_temp}/rsync-stream-${istream}.files"
|
||||
echo -n > $file_temp
|
||||
|
|
@ -120,13 +126,16 @@ for ((istream=0;istream<num_streams;istream++)); do
|
|||
done
|
||||
|
||||
# Transfer data
|
||||
declare -a rsync_pids
|
||||
declare -a rsync_pids tail_pids
|
||||
declare -i timer dt_transfer
|
||||
function rsync_sigint {
|
||||
echo "Sending SIGINT to remaining streams..."
|
||||
for pid in ${rsync_pids[@]}; do
|
||||
kill -s SIGINT ${pid}
|
||||
done
|
||||
for pid in ${tail_pids[@]}; do
|
||||
kill -s SIGINT ${pid}
|
||||
done
|
||||
}
|
||||
rsync_pids=()
|
||||
timer=$(date +%s%N)
|
||||
|
|
@ -135,15 +144,23 @@ trap rsync_sigint SIGINT
|
|||
for ((istream=0;istream<num_streams;istream++)); do
|
||||
file_temp="${dir_temp}/rsync-stream-${istream}.files"
|
||||
file_log="${dir_temp}/rsync-stream-${istream}.log"
|
||||
rsync -v ${flags_rsync[@]} $(cat $file_temp) $dest > $file_log &
|
||||
rsync ${flags_rsync[@]} $(cat $file_temp) $dest > $file_log &
|
||||
rsync_pids+=($!)
|
||||
if [ $flag_verbose -gt 0 ]; then
|
||||
tail -F $file_log 2>/dev/null &
|
||||
tail_pids+=($!)
|
||||
fi
|
||||
echo "Started stream #${istream}... pid=${rsync_pids[istream]}, log=${file_log}"
|
||||
done
|
||||
for pid in ${rsync_pids[@]}; do
|
||||
wait $pid
|
||||
for ((istream=0;istream<num_streams;istream++)); do
|
||||
wait ${rsync_pids[istream]}
|
||||
ec_=$?
|
||||
echo "Process ${pid} finished with exit code $ec_"
|
||||
echo "Process ${rsync_pids[istream]} finished with exit code $ec_"
|
||||
[[ $ec_ -ne 0 ]] && flag_fail=1
|
||||
if [ $flag_verbose -gt 0 ]; then
|
||||
kill ${tail_pids[istream]}
|
||||
wait ${tail_pids[istream]} 2>/dev/null
|
||||
fi
|
||||
done
|
||||
if [ $flag_fail -ne 0 ]; then
|
||||
echo "Transfer failed."
|
||||
|
|
|
|||
Loading…
Reference in New Issue