From 5d374909d4b34892f71b82641393e84208baaee4 Mon Sep 17 00:00:00 2001 From: Pierre CLEMENT Date: Tue, 6 May 2014 22:33:29 +0200 Subject: [PATCH] add option to exclude files or directories from a file and bug fix in tree_list --- files.exclude | 5 +++++ osync.sh | 14 ++++++++++++-- sync.conf | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 files.exclude diff --git a/files.exclude b/files.exclude new file mode 100644 index 0000000..b56e6ae --- /dev/null +++ b/files.exclude @@ -0,0 +1,5 @@ +.localized +.AppleDouble/ +._* +.DS_Store +Thumbs.db diff --git a/osync.sh b/osync.sh index a6f784f..1a3c1a2 100755 --- a/osync.sh +++ b/osync.sh @@ -735,6 +735,14 @@ function RsyncExcludePattern IFS=$OLD_IFS } +function RsyncExcludeFrom +{ + if [ ! -z $RSYNC_EXCLUDE_FROM ] && [ -e $RSYNC_EXCLUDE_FROM ] + then + RSYNC_EXCLUDE="$RSYNC_EXCLUDE --exclude-from=\"$RSYNC_EXCLUDE_FROM\"" + fi +} + function WriteLockFiles { echo $SCRIPT_PID > "$MASTER_LOCK" @@ -909,7 +917,7 @@ function tree_list ESC=$(EscapeSpaces "$1") rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" -rlptgoDE8 $RSYNC_ARGS --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE -e \"$RSYNC_SSH_CMD\" --list-only $REMOTE_USER@$REMOTE_HOST:\"$ESC/\" | grep \"^-\|^d\" | awk '{\$1=\$2=\$3=\$4=\"\" ;print}' | awk '{\$1=\$1 ;print}' | (grep -v \"^\.$\" || :) | sort > \"$RUN_DIR/osync_$2_$SCRIPT_PID\" &" else - rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" -rlptgoDE8 $RSYNC_ARGS --exclude \"$OSYNC_DIR\" $RSNYC_EXCLUDE --list-only \"$1/\" | grep \"^-\|^d\" | awk '{\$1=\$2=\$3=\$4=\"\" ;print}' | awk '{\$1=\$1 ;print}' | (grep -v \"^\.$\" || :) | sort > \"$RUN_DIR/osync_$2_$SCRIPT_PID\" &" + rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" -rlptgoDE8 $RSYNC_ARGS --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --list-only \"$1/\" | grep \"^-\|^d\" | awk '{\$1=\$2=\$3=\$4=\"\" ;print}' | awk '{\$1=\$1 ;print}' | (grep -v \"^\.$\" || :) | sort > \"$RUN_DIR/osync_$2_$SCRIPT_PID\" &" fi LogDebug "RSYNC_CMD: $rsync_cmd" ## Redirect commands stderr here to get rsync stderr output in logfile @@ -1558,7 +1566,9 @@ function Init fi ## Add Rsync exclude patterns - RsyncExcludePattern + RsyncExcludePattern + ## Add Rsync exclude from file + RsyncExcludeFrom } function Main diff --git a/sync.conf b/sync.conf index 0b70a49..d0e1d82 100755 --- a/sync.conf +++ b/sync.conf @@ -25,6 +25,9 @@ LOGFILE="" ## List of directories to exclude from sync on both sides (rsync patterns, wildcards work). ## Paths are relative to sync dirs. List elements are separated by a semicolon. RSYNC_EXCLUDE_PATTERN="tmp;archives" +## File that containes the list of directories or files to exclude from sync on both sides. +## Paths are relative to sync dirs. One element per line. +RSYNC_EXCLUDE_FROM="files.exclude" ## List elements separator char. You may set an alternative seperator char for your directories lists above. PATH_SEPARATOR_CHAR=";"