ambevar-dotfiles/.local/bin/rmirror

49 lines
959 B
Bash
Executable File

#!/bin/sh
usage () {
cat <<EOF>&2
Usage: ${0##*/} SOURCE DEST
Use rsync to mirror SOURCE to DEST while showing progress.
SOURCE does not need to be ending with a trailing slash. Only size is used for
comparison. File perms and dates are mirrored by default.
A dry-run is made by default.
Options:
-p: Process.
-s: Ignore dates when comparing files.
EOF
}
## We use archive mode '-a' which preserves perms and dates. On non-POSIX
## filesystems, you might want to skip this and preserve symlinks only by
## replacing -a with -lr.
flags="-a"
opt_dry="-n"
while getopts ":hps" opt; do
case $opt in
h)
usage
exit ;;
p)
opt_dry="" ;;
s)
flags="-lr"
OPT_PROCESS=true ;;
\?)
usage
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
[ $# -ne 2 ] && usage && exit 1
[ "$1" = "-h" ] && usage && exit
[ "$1" = "--" ] && shift
rsync $opt_dry -iv $flags --size-only --delete --exclude="/lost+found" --exclude="/.Trash*" --progress -- "$1"/ "$2"