rmirror 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. usage () {
  3. cat <<EOF>&2
  4. Usage: ${0##*/} SOURCE DEST
  5. Use rsync to mirror SOURCE to DEST while showing progress.
  6. SOURCE does not need to be ending with a trailing slash. Only size is used for
  7. comparison. File perms and dates are mirrored by default.
  8. A dry-run is made by default.
  9. Options:
  10. -i: Ignore CVS files (e.g. .git and .gitignore'd files).
  11. -p: Process.
  12. -s: Ignore dates when comparing files.
  13. EOF
  14. }
  15. ## We use archive mode '-a' which preserves perms and dates. On non-POSIX
  16. ## filesystems, you might want to skip this and preserve symlinks only by
  17. ## replacing -a with -lr.
  18. flags="-a"
  19. opt_dry="-n"
  20. opt_cvs_ignore=""
  21. while getopts ":ihps" opt; do
  22. case $opt in
  23. i)
  24. opt_cvs_ignore="--cvs-exclude" ;;
  25. h)
  26. usage
  27. exit ;;
  28. p)
  29. opt_dry="" ;;
  30. s)
  31. flags="-rlpgoD"
  32. OPT_PROCESS=true ;;
  33. \?)
  34. usage
  35. exit 1 ;;
  36. esac
  37. done
  38. shift $(($OPTIND - 1))
  39. [ $# -ne 2 ] && usage && exit 1
  40. [ "$1" = "-h" ] && usage && exit
  41. [ "$1" = "--" ] && shift
  42. rsync $opt_dry -iv $flags --size-only --delete --exclude="/lost+found" --exclude="/.Trash*" $opt_cvs_ignore --progress -- "$1"/ "$2"