Added verbose output

This commit is contained in:
Michael Krayer 2024-04-02 17:25:42 +02:00
parent 94fa4f5e72
commit 975280a456
1 changed files with 24 additions and 7 deletions

31
prsync
View File

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