简体   繁体   中英

rsync with --exclude flag is not working?

I've been struggling with this issue where I want to exclude a directory while doing rsync but it doesn't get excluded. Could you please help in this case and where is the issue and how it can be resolved? Thank you

#!/bin/bash
SRC="/home/nnice/Desktop/Scripts/"
DST="/home/nnice/Desktop/Personal/Linux/Notes/My_Fedora_Desktop/Scripts/"
EXCLUDE="{'*.log','/home/nnice/Desktop/Scripts/XDM/'}"
rsync --delete -P -arcvzh --exclude=${EXCLUDE} $SRC $DST
#rsync --delete -P -arcvzh --exclude={'*.log','/home/nnice/Desktop/Scripts/XDM/'} $SRC $DST

The XDM directory is still getting synced. And I don't want to use --exclude-from flag. I am getting below output which shows the XDM directory is getting synced.

sending incremental file list
./
XDM/
XDM/install.sh
         55.35M 100%  338.16MB/s    0:00:00 (xfr#1, to-chk=6/96)
XDM/readme.txt
            650 100%    4.07kB/s    0:00:00 (xfr#2, to-chk=5/96)
XDM/xdm-setup-7.2.11.tar.xz
         55.34M 100%  165.46MB/s    0:00:00 (xfr#3, to-chk=4/96)

sent 110.71M bytes  received 116 bytes  221.43M bytes/sec
total size is 110.75M  speedup is 1.00

rsync does not understand braces in exclude filters. Each exclude takes a single rule.

The braces are actually interpreted by bash as brace expansion . However this expansion does not happen inside a quoted string.

It would be simpler just to list multiple exclude options.

However if you want to use the brace shortcut, you could do something like:

#!/bin/bash
SRC="/home/nnice/Desktop/Scripts/"
DST="/home/nnice/Desktop/Personal/Linux/Notes/My_Fedora_Desktop/Scripts/"
EXCLUDE=( --exclude={'*.log','/home/nnice/Desktop/Scripts/XDM/'} )
rsync --delete -P -arcvzh "${EXCLUDE[@]}" $SRC $DST

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM