From e544342fae2c26908bbaf239dbc5fd9cadfee1ce Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Thu, 3 Nov 2022 13:41:00 +0200 Subject: [PATCH] rsync copy filter --- bin/rsync-copy-filter | 1 + files/rsync-copy-filter | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 120000 bin/rsync-copy-filter create mode 100755 files/rsync-copy-filter diff --git a/bin/rsync-copy-filter b/bin/rsync-copy-filter new file mode 120000 index 0000000..a608012 --- /dev/null +++ b/bin/rsync-copy-filter @@ -0,0 +1 @@ +../files/rsync-copy-filter \ No newline at end of file diff --git a/files/rsync-copy-filter b/files/rsync-copy-filter new file mode 100755 index 0000000..31befe4 --- /dev/null +++ b/files/rsync-copy-filter @@ -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"