Files
q-tools/files/rsync-copy-filter
Ville Rantanen e544342fae rsync copy filter
2022-11-03 13:41:00 +02:00

33 lines
710 B
Bash
Executable File

#!/bin/bash
set -e
function helpexit() {
echo Usage: $( basename "$0" ) source/ target/ [include] [[include]]
echo Copy files with a glob inclusion, keeping folder structure.
echo Example: fromfolder/ to/folder/ '*.jpg' '*.png'
echo This command always
echo '* recurses to folders!'
echo '* overwrites existing files'
exit
}
for ((i=1; i<=${#@}; i++)) {
[[ "${!i}" = "-h" ]] && helpexit
[[ "${!i}" = "--help" ]] && helpexit
}
if [[ -z "$3" ]]; then
helpexit
fi
SRC="$1"
TGT="$2"
for ((i=3; i<=${#@}; i++)) {
includes="$includes --include=\"${!i}\""
}
eval rsync -av --no-i-r --prune-empty-dirs \
--include="*/" "$includes" --exclude="*" \
"$SRC" "$TGT"