Advertisement
devinteske

ddrescue-loop.sh

Sep 25th, 2020
1,773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.06 KB | None | 0 0
  1. #!/bin/sh
  2. # NB: Must run with -1 for until full first pass is complete
  3. firstrun=
  4. sleep=$(( 60 * 60 * 6 )) # 6h
  5. #?sleep=300 # 5m
  6. while getopts 1hs: flag; do
  7.         case "$flag" in
  8.         1) firstrun=1 ;;
  9.         s) sleep="$OPTARG" ;;
  10.         *) echo "$0 [-1h] [from [to [log]]]" >&2
  11.            exit 1
  12.         esac
  13. done
  14. shift $(( $OPTIND - 1 ))
  15. : "${from:=${1:-/dev/ada1}}"
  16. : "${to:=${2:-/dev/ada2}}"
  17. : "${log:=${3:-Recovery.log}}"
  18. n=0
  19. set -e
  20. while :; do
  21.         set -- -f -v -v -n -r1
  22.         n=$(( $n + 1 ))
  23.         if [ "$firstrun" ]; then
  24.                 set -- "$@" -a 1048576
  25.         elif [ $(( $n % 2 )) -eq 0 ]; then
  26.                 set -- "$@" -M -R -C
  27. #?              set -- "$@" -R -C
  28.         else
  29.                 set -- "$@" -M -C
  30. #?              set -- "$@" -C
  31.         fi
  32.         set -- ddrescue "$@" -d "$from" "$to" "$log"
  33.         date
  34.         echo "$@"
  35.         time "$@"
  36.         sleep $sleep
  37.         date | tee -a "$log.loop"
  38.         diff -pu "$log.bak" "$log" | tee -a "$log.loop"
  39.         cp "$log" "$log.bak"
  40.         firstrun=
  41. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement