0

I want to use rsync for incremental backups. However it fails when I try it like this:

SRC="/"
TRG="/backup/"
LNK="/oldbackup/"
OPT="-a --exclude={/dev,/proc,/sys,/tmp,/run,/mnt,/media,/lost+found} --link-dest=$LNK"

rsync $OPT $SRC $TRG

But works like this:

SRC="/"
TRG="/backup/"
LNK="/oldbackup/"

rsync -a --exclude={/dev,/proc,/sys,/tmp,/run,/mnt,/media,/lost+found} --link-dest=$LNK $SRC $TRG

What did I do wrong?

4

1 回答 1

2

检查中的扩展顺序man bash:大括号扩展首先发生,变量扩展随后发生。因此,变量中的大括号不会展开。

您可以使用数组来捕获值,在分配中使用扩展:

opts=( -a --exclude={/dev,/proc,/sys,/tmp,/run,/mnt,/media,/lost+found} --link-dest="$LNK" )
rsync "${opts[@]}" "$SRC" "$TRG"
于 2016-08-27T20:20:49.333 回答