ambevar-dotfiles/.local/bin/rmirror

53 lines
1.1 KiB
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:
-i: Ignore CVS files (e.g. .git and .gitignore'd files).
-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"
opt_cvs_ignore=""
while getopts ":ihps" opt; do
case $opt in
i)
opt_cvs_ignore="--cvs-exclude" ;;
h)
usage
exit ;;
p)
opt_dry="" ;;
s)
flags="-rlpgoD"
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*" $opt_cvs_ignore --progress -- "$1"/ "$2"