2

我有一个脚本,它find遍历带有路径列表的外部文件,以便为rsync. 这些路径具有可变数量的路径排除(包括根本没有)。我正在尝试扩展一个find基于此构建排除项的变量。我已经研究了很多并且很难过。说:

cat backuplist.conf

/mnt/some/dir1 /mnt/some/dir1/exclude/dirA /mnt/some/dir1/exclude/dirB
/mnt/some/dir2 

主备份脚本的相关部分是:

cat backupscript.sh

while read backuppath excludedir1 excludedir2 excludedir3; do
    exclude=("${excludedir1}" "${excludedir2}" "${excludedir3}")  
    find ${backuppath} -not \( -path "*${exclude[0]}" "${exclude[@]:1}") -mtime -10 > file.list
    rsync -vPaz --files-from=file.list --otheroptions
  done < backuplist.conf 

我知道我的数组示例全错了(除其他外),但我什至不知道构建数组是否是正确的解决方案,因为它不知道会有多少排除项。谁能指出我正确的方向?重击/CentOS 6

4

1 回答 1

0

将排除的目录存储在一个数组中,然后用于在命令printf中将它们打印出来。find

while read backuppath excludeDirs; do
    excludeArr=( $excludeDirs )
    if [[ ${#excludeArr[@]} == 0 ]]
    then
        find "${backuppath}" -mtime -10 > file.list
    elif [[ ${#excludeArr[@]} == 1 ]]
    then
        find "${backuppath}" -mtime -10 -not -path "${excludeArr[0]}"  > file.list
    else
        find "${backuppath}" -mtime -10  -not \( -path "${excludeArr[0]}" $(printf -- '-o -path "%s" ' "${excludeArr[@]:1}") \) > file.list
    fi
    rsync -vPaz --files-from=file.list --otheroptions
done < backuplist.conf
于 2013-03-05T12:19:10.603 回答