This gives script with some good output, best if the target starts off empty (better put if the your backup job is setup such that at the end the space used by the target device and the space used the source device match, and if they match that means the job is complete well then all of the time estimates and remaining space to copy statuses in here will be correct), if that is not your type of backup job, like your only copying a small subset or something thus the target and source sizes at the end shouldnt match then you could still benefit from all of the speed/rate estimates.
To run this script you must run it like this:
./scriptwait 2 seconds./scriptwait 2 seconds
etc. OR:
watch -n2 ./script
OR with a while loop:
while true; do echo; echo “================”; ./script; sleep 2; done
Here is the script – red and highlighted yellow is the important stuff:
#!/bin/bash # NOTE THIS USES iostat SO IF YOU DONT HAVE THAT PLEASE INSTALL sysstat LIKE SO: # apt-get install sysstat # If you dont want to do that then Hash out the Line that uses iostat towards the bottom ######################## # VARIABLES SECTION ######################## # ALL OF THESE WILL BE GREPPED, THE GOAL IS TO SELECT A PHRASE THAT WILL # RETURN 1 GREP/EGREP RESULT AND SURROUND THAT PHRASE WITH DOUBLE QUOTES # TESTS CAN BE RUN TO SEE IF THE VARIABLES YOU SELECTED WORK # THE TESTS ARE AT THE COMMENTED SECTION BEFORE "END OF VARIABLES SECTION" # IF THE TESTS DIDNT RETURN WHAT IS NEEDED PICK A NEW PHRASE FOR YOUR VARIABLE # --SET VARIABLES SECTION-- SOURCE_PHRASE_FROM_DF="/dev/c" SOURCE_DEVICE_NAME="dm-0" TARGET_PHRASE_FROM_DF="mnt/usb1" TARGET_DEVICE_NAME="sdf2" # RUN ps aux AND SEE WHAT UNIQUE WORDS SURROUND YOUR RUNNING JOB # AS AN EXAMPLE IF MY COPY COMMAND WAS CALLED copy I WOULD PUT cop[y] SCRIPT1="cp -Rn[v]" # SIMILARLY YOU COULD PUT "[ ]c[p][ ]", THE BRACKETS FORCE THOSE CHARACTERS SCRIPT2="rsyn[c]" SCRIPT3="ta[r]" # --TEST VARIABLES SUBSECTION-- # RUN THE FOLLOWING COMMAND AND IF IT RETURNS WHAT IS ASKED FOR # THEN YOU PICKED GOOD PHRASES FOR YOUR VARIABLES - IF NOT CHOOSE AGAIN # df -Pm | egrep -i "$SOURCE_PHRASE_FROM_DF" # THIS SHOULD RETURN 1 LINE: df -Pm | egrep -i "$SOURCE_PHRASE_FROM_DF" # EXAMPLE RUNNING THIS: df -Pm | egrep -i "/dev/c" - RETURNS THIS: # /dev/c/c 4251332 2728498 1522835 65% /c # df -Pm | egrep -i "$TARGET_PHRASE_FROM_DF" # THIS SHOULD RETURN 1 LINE: df -Pm | egrep -i "$TARGET_PHRASE_FROM_DF" # EXAMPLE RUNNING THIS: df -Pm | egrep -i "mnt/usb1" - RETURNS THIS: # /dev/sdf2 2849795 395735 2311002 15% /mnt/usb1 # THIS SHOULD RETURN 3 LINES: iostat -m | egrep -i "Device|$TARGET_DEVICE_NAME|$SOURCE_DEVICE_NAME" # EXAMPLE RUNNING THIS: iostat -m | egrep "Device|sdf2|dm-0" - RETURNS THIS: # Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn # dm-0 102.77 1.87 0.00 353779 281 # sdf2 17.92 0.00 1.93 95 364969 # THE ps aux TESTS ARE OPTIONAL AS THE COMMANDS COULD POSSIBLY BE NOT RUNNING: # TECHNICALLY ONLY ONE OF THESE TESTS SHOULD RETURN A WORKING ONE - AS A PERSON WILL NOT HAVE COPY AND RSYNC RUNNING AT SAME TIME # ps aux | egrep -i "$SCRIPT1" | nl # THIS SHOULD RETURN 1 LINE (THE nl LISTS LINE NUMBER ON LEFT SIDE) # EXAMPLE RUNNING THIS: ps aux | egrep -i "cp -Rn[v]" | nl - RETURNS THIS: # 1 root 30884 17.7 0.0 2480 888 pts/3 R 20:27 18:50 cp -Rnv /c/lost+found/#106065442/media/ /mnt/usb1/media-backup/ # ps aux | egrep -i "$SCRIPT2" | nl # THIS SHOULD RETURN 1 LINE (THE nl LISTS LINE NUMBER ON LEFT SIDE) # EXAMPLE RUNNING THIS: ps aux | egrep -i "rsyn[c]" | nl - RETURNS THIS: # 1 root 5555 17.2 0.0 2480 333 pts/3 R 20:47 18:20 rsync -avh /c/lost+found/#106065442/media/ /mnt/usb1/media-backup/ ########################## # END OF VARIABLES SECTION ########################## # BEFORE ANYTHING PULL THE VALUES THAT WERE STORED LAST TIME, THIS IS FOR THE SPEED MEASUREMENTS TIME1=`cat /tmp/time1` TARGET1=`cat /tmp/target1` date echo echo "===JOB INFO:===" TARGET_KB=`df -P | egrep -i "$TARGET_PHRASE_FROM_DF" | awk '{print $3}'` TARGET=`df -Pm | egrep -i "$TARGET_PHRASE_FROM_DF" | awk '{print $3}'` TARGET_GB=`echo $TARGET | awk '{x=$0; y=x/1024; print y;}'` echo "TARGET: $TARGET MB, $TARGET_GB GB" SOURCE_KB=`df -P | egrep -i "$SOURCE_PHRASE_FROM_DF" | awk '{print $3}'` SOURCE=`df -Pm | egrep -i "$SOURCE_PHRASE_FROM_DF" | awk '{print $3}'` SOURCE_GB=`echo $SOURCE | awk '{x=$0; y=x/1024; print y;}'` echo "SOURCE: $SOURCE MB, $SOURCE_GB GB" DIFF_KB=`echo $SOURCE_KB $TARGET_KB | awk '{x=$1; y=$2; print x-y;}'` DIFF=`echo $SOURCE $TARGET | awk '{x=$1; y=$2; print x-y;}'` DIFF_GB=`echo $DIFF | awk '{x=$0; y=x/1024; print y;}'` PERC=`echo $SOURCE $TARGET | awk '{x=$1; y=$2; print y/x*100;}'` echo "REMAINING $DIFF MB, $DIFF_GB GB, $PERC %" echo echo "===SPEED AND TIME ANALYSIS ESTIMATIONS BETWEEN LAST 2 RUNS===" TARGET2=$TARGET_KB SIZE_DIFF=`echo $TARGET2 $TARGET1 | awk '{x=$1; y=$2; print x-y;}'` TARGET1=$TARGET2 TIME2=`date +%s` # CURRENT TIME IN SECONDS SINCE 1970 TIME_DIFF=`echo $TIME2 $TIME1 | awk '{x=$1; y=$2; print x-y;}'` TIME1=$TIME2 # CURRENT TIME BECOMES OLD TIME SPEED_KBYTES=`echo $SIZE_DIFF $TIME_DIFF | awk '{x=$1; y=$2; print x/y;}'` 2> /dev/null SPEED_KBITS=`echo $SPEED_KBYTES | awk '{x=$1; print x*8;}'` SPEED_MBYTES=`echo $SPEED_KBYTES | awk '{x=$1; print x/1024;}'` SPEED_MBITS=`echo $SPEED_MBYTES | awk '{x=$1; print x*8;}'` ETA_SECONDS=`echo $DIFF_KB $SPEED_KBYTES | awk '{x=$1; y=$2; print x/y;}'` 2> /dev/null TOTAL_SECONDS=`echo $TARGET_KB $SPEED_KBYTES | awk '{x=$1; y=$2; print x/y;}'` 2> /dev/null ETA_SECONDS_M=`echo $DIFF $SPEED_MBYTES | awk '{x=$1; y=$2; print x/y;}'` 2> /dev/null TOTAL_SECONDS_M=`echo $TARGET $SPEED_MBYTES | awk '{x=$1; y=$2; print x/y;}'` 2> /dev/null ETA_SECONDS_H=`echo $ETA_SECONDS | awk '{x=$1; print x/3600;}'` 2> /dev/null TOTAL_SECONDS_H=`echo $TOTAL_SECONDS | awk '{x=$1; print x/3600;}'` 2> /dev/null ETA_SECONDS_M_H=`echo $ETA_SECONDS_M | awk '{x=$1; print x/3600;}'` 2> /dev/null TOTAL_SECONDS_M_H=`echo $TOTAL_SECONDS_M | awk '{x=$1; print x/3600;}'` 2> /dev/null echo "IN THE LAST [$TIME_DIFF SECS] [$SIZE_DIFF KBYTES] WERE TRANSFERED @ A RATE OF [$SPEED_KBYTES KB/s = $SPEED_MBYTES MB/s = $SPEED_KBITS Kb/s = $SPEED_MBITS Mb/s]" echo echo "--TIME REPORTS IN SECONDS--" echo "ETA IS [$ETA_SECONDS s - calc from (KB)/(KBPS)] = [$ETA_SECONDS_M s - calc from (MB)/(MBPS)]" echo "RUNNING TIME IS [$TOTAL_SECONDS s - calc from (KB)/(KBPS)] = [$TOTAL_SECONDS_M s - calc from (MB)/(MBPS)]" echo echo "--TIME REPORTS IN HOURS--" echo "ETA IS [$ETA_SECONDS_H h - calc from (KB)/(KBPS)] = [$ETA_SECONDS_M_H h - calc from (MB)/(MBPS)]" echo "RUNNING TIME IS [$TOTAL_SECONDS_H h - calc from (KB)/(KBPS)] = [$TOTAL_SECONDS_M_H h - calc from (MB)/(MBPS)]" echo echo "===DISK INFO IN MB:===" iostat -m | egrep -i "Device|$TARGET_DEVICE_NAME|$SOURCE_DEVICE_NAME" 2> /dev/null echo echo "===CPU LOAD AVERAGES:===" cat /proc/loadavg; echo echo "===MEMORY(RAM & SWAP) in MB:===" free -m echo echo "===WHATS STILL RUNNING===" # DONT FORGET TO PUT LAST CHARACTER IN [] OR ELSE EGREP/GREP ALWAYS FINDS ITSELF echo -e "IS $SCRIPT1 STILL RUNNING:" `if ps aux | egrep -qi "$SCRIPT1" ; then echo "YES"; else echo "NO"; fi` echo -e "IS $SCRIPT2 STILL RUNNING:" `if ps aux | egrep -qi "$SCRIPT2" ; then echo "YES"; else echo "NO"; fi` echo -e "IS $SCRIPT3 STILL RUNNING:" `if ps aux | egrep -qi "$SCRIPT3" ; then echo "YES"; else echo "NO"; fi` echo $TIME1 > "/tmp/time1" echo $TARGET1 > "/tmp/target1"