2016-11-28 13 views
1

私はscpを使ってファイルをネットワーク経由で送信するシェルスクリプトを持っています。このスクリプトはイベント駆動方式で動作します。つまり、ファイルが変更されるたびにscpを使用してネットワーク経由で送信されます。スクリプトを最適化して、ファイルを送信するたびに、「新しい追加/新規書き込みデータ」を送信して、もう一方のエンドポイントのファイルに追加するようにします。ネットワーク上でSCPを最適化する

スクリプトは次のとおりです

while true 
do 
inotifywait -e close_write,moved_to,create . | 
while read -r directory events filename; do 
    if [ "$filename" = "keylog.txt" ]; then 
    sshpass -p "password" scp -o StrictHostKeyChecking=no keylog.txt [email protected]:/home/machine/keylog.txt 
    fi 
done 
sleep 0.00001 
done 
+0

[Scp through ssh tunnel opened]の重複の可能性があります(http://stackoverflow.com/questions/33735624/scpthrough-ssh-tunnel-opened) – Jakuje

+0

これは参照されているものと重複している可能性があります質問 ?。私はそれが事実である場合、質問を取り下げたいと思う。 –

+0

タイトルが誤解を招くこれは、リモートサーバへのより速い分離した 'scp'要求をより速くしようとしています。ファイルを転送するのではなく、サーバーに接続するのに費やしている時間のほとんどです!したがって、それを通してあなたのために読むことは面白いかもしれません。明らかに、あなたは 'rsync 'でもそれを再利用して、差分転送と高速転送の両方を達成することができます。 – Jakuje

答えて

0

rsyncをご覧ください。 このような目的のために設計されています。 man rsyncから引用:scpをサポートするサーバー上で

Rsync is a fast and extraordinarily versatile file copying tool. It can 
    copy locally, to/from another host over any remote shell, or to/from a 
    remote rsync daemon. It offers a large number of options that control 
    every aspect of its behavior and permit very flexible specification of the 
    set of files to be copied. It is famous for its delta-transfer algorithm, 
    which reduces the amount of data sent over the network by sending only the 
    differences between the source files and the existing files in the desti- 
    nation. Rsync is widely used for backups and mirroring and as an improved 
    copy command for everyday use. 

、 は通常rsyncがあまりにも動作します。 これを試してみてください:

sshpass -p "password" rsync keylog.txt [email protected]:/home/machine/keylog.txt 

でもパラメータを調整することなく、 rsyncは、転送されるデータの量を最小限にしようとします。 宛先ファイルがすでに存在する場合、 は必要な差異だけを転送します。

+0

私はtimeオプションでコマンドを実行しました。 rsyncの所要時間は0.328msですが、scpコマンドは0.283msです。 –

+0

@AbhimanyuKhanna、このベンチマークは短すぎて関連性がありません。 – Setop

+0

@AbhimanyuKhanna - 'rsync'は' -S'でスパースファイルの効率的な処理をサポートします。私はいつも圧縮オプション '-z'を使います。 – alvits

関連する問題