rsync copy filter

This commit is contained in:
Ville Rantanen
2022-11-03 13:41:00 +02:00
parent 40fed6563f
commit e544342fae
2 changed files with 33 additions and 0 deletions

1
bin/rsync-copy-filter Symbolic link
View File

@@ -0,0 +1 @@
../files/rsync-copy-filter

32
files/rsync-copy-filter Executable file
View File

@@ -0,0 +1,32 @@
#!/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"