Linux

無法使用 rsync 3.0.9 版本複制多個文件?

  • March 21, 2014

我正在嘗試使用 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]

從外觀上看,您需要做的就是刪除引號(為清楚起見添加了換行符):

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/"

無論引用如何,[@]都會將數組拆分為不同的參數。否則,請注意您的變數引用,您所擁有的某些內容可能會或可能不會導致問題。

引用自:https://unix.stackexchange.com/questions/120841