无法使用 rsync 3.0.9 版本复制多个文件?

无法使用 rsync 3.0.9 版本复制多个文件?

我正在尝试使用 rsync 从 a 复制两个文件,machineB但不知怎的,它总是只复制一个文件,但不复制第二个文件 -

这是我正在使用的语法 -

rsync -avz david@machineB:'/data/pe_t1_snapshot/20140317/t1_weekly_1680_0_200003_5.data :/data/pe_t1_snapshot/20140317/t1_weekly_1680_1_200003_5.data' /data01/primary

它仅将此文件复制到文件夹t1_weekly_1680_0_200003_5.data/data01/primary,并且没有复制第二个文件,即t1_weekly_1680_1_200003_5.data.

我使用的是 Ubuntu 12.04,rsync 版本是 -

rsync  version 3.0.9  protocol version 30

这是我收到的错误 -

receiving incremental file list
rsync: change_dir "/home/david/:/data/pe_t1_snapshot/20140317" failed: No such file or directory (2)
t1_weekly_1680_0_200003_5.data

sent 30 bytes  received 504982813 bytes  6196108.50 bytes/sec
total size is 1761988281  speedup is 3.49
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1536) [generator=3.0.9]

我开始阅读 rsync 手册,但不知何故我无法理解我做错了什么?

更新:-

如果我从控制台运行它,它在单个命令上运行良好,但我需要从 shell 脚本运行它,所以我在我的 shell 脚本中添加了您的建议。

我刚刚在下面的示例中运行了您的建议,但出现了错误。

下面是 shell 脚本,它只是尝试从 复制文件machineB,如果文件不存在,machineB那么它应该存在,machineC因此它将尝试从 复制machineCPRIMARY_PARTITION并将SECONDARY_PARTITION有文件编号。

下面是我正在运行的 shell 脚本machineA

#!/usr/bin/env bash

readonly PRIMARY=/data01/primary
readonly FILERS_LOCATION=(machineB machineC)
readonly MEMORY_MAPPED_LOCATION=/bexbat/data/be_t1_snapshot
PRIMARY_PARTITION=(0 548)
SECONDARY_PARTITION=(1101 1374)

dir1=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[0]} \
  ls -dt1 "$MEMORY_MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | 
  head -n1)
dir2=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[1]} \
  ls -dt1 "$MEMORY_MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] |
  head -n1)

echo $dir1
echo $dir2

## Build your list of filenames before the loop. 
for n in "${PRIMARY_PARTITION[@]}"
do
    primary_files="$primary_files :$dir1"/t1_weekly_1680_"$n"_200003_5.data
done

## Repeat for $SECONDARY_PARTITION
for n in "${SECONDARY_PARTITION[@]}"
do
    secondary_files="$secondary_files :$dir2"/t1_weekly_1680_"$n"_200003_5.data
done

echo "Primary: " $primary_files
echo "Secondary: " $secondary_files


if [ "$dir1" = "$dir2" ]
then
    find "$PRIMARY" -mindepth 1 -delete

    # this line is giving an exception somehow
    rsync -avz david@${FILERS_LOCATION[0]}${primary_files} $PRIMARY/
    rsync -avz david@${FILERS_LOCATION[1]}${primary_files} $PRIMARY/

fi

以下是我得到的错误 -

Unexpected remote arg: :/data/pe_t1_snapshot/20140320/t1_weekly_1680_0_200003_5.data
rsync error: syntax or usage error (code 1) at main.c(1232) [sender=3.0.9]
Unexpected remote arg: :/data/pe_t1_snapshot/20140320/t1_weekly_1680_0_200003_5.data
rsync error: syntax or usage error (code 1) at main.c(1232) [sender=3.0.9]
Unexpected remote arg: :/data/pe_t1_snapshot/20140320/t1_weekly_1680_1101_200003_5.data
rsync error: syntax or usage error (code 1) at main.c(1232) [sender=3.0.9]
Unexpected remote arg: :/data/pe_t1_snapshot/20140320/t1_weekly_1680_1101_200003_5.data
rsync error: syntax or usage error (code 1) at main.c(1232) [sender=3.0.9]

答案1

从表面上看,您所需要做的就是删除引号(为了清楚起见添加了换行符):

 rsync -avz \
   david@machineB:/data/pe_t1_snapshot/20140317/t1_weekly_1680_0_200003_5.data \
   :/data/pe_t1_snapshot/20140317/t1_weekly_1680_1_200003_5.data \
   /data01/primary

rsync手册页:

The  syntax  for requesting multiple files from a remote host is done by
specifying additional remote-host args in the same style as the first, or with
the hostname omitted.  For instance, all these work:

          rsync -av host:file1 :file2 host:file{3,4} /dest/

复制示例中的前两个文件使用与您相同的语法,但它们是单独的参数(引用它们将它们连接成一个参数)。如果您的路径包含需要引用的字符,您可以执行以下操作:

rsync -avz \
  'user@host:dodgy path/file_with_asterix*' \
  ':some_other/dodgy\\path' \
  /dest

更新

我认为让脚本工作的最简单方法就是使用数组 forprimary_filessecondary_files。相关变更为primary_files

for n in "${PRIMARY_PARTITION[@]}"
do
  primary_files+=( ":$dir1/t1_weekly_1680_${n}_200003_5.data" )
done

....

echo "Primary: ${primary_files[@]}"

...

rsync -avz "david@${FILERS_LOCATION[0]}${primary_files[@]}" "$PRIMARY/"

无论引用如何,都会[@]将数组拆分为不同的参数。否则,请注意您的变量引用,您所拥有的某些内容可能会或可能不会导致问题。

相关内容