`scp` 与 `rsync` 有何不同? [英] How does `scp` differ from `rsync`?

查看:45
本文介绍了`scp` 与 `rsync` 有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一篇关于设置Ghost的文章blogging 说使用 scp 从我的本地机器复制到远程服务器:

An article about setting up Ghost blogging says to use scp to copy from my local machine to a remote server:

scp -r ghost-0.3 root@*your-server-ip*:~/

但是,Railscast 339:Chef Solo Basics 使用 scp 反方向复制(从远程服务器到本地机器):

However, Railscast 339: Chef Solo Basics uses scp to copy in the opposite direction (from the remote server to the local machine):

scp -r root@178.xxx.xxx.xxx:/var/chef .

在同一个Railscast中,当作者想将文件复制到远程服务器时(与第一个例子方向相同),他使用了rsync:

In the same Railscast, when the author wants to copy files to the remote server (same direction as the first example), he uses rsync:

rsync -r . root@178.xxx.xxx.xxx:/var/chef

如果 scp 会双向复制,为什么要使用 rsync 命令?scprsync 有何不同?

Why use the rsync command if scp will copy in both directions? How does scp differ from rsync?

推荐答案

这些工具之间的主要区别在于它们复制文件的方式.

The major difference between these tools is how they copy files.

scp 基本上读取源文件并将其写入目标.它在本地或通过网络执行纯线性复制.

scp basically reads the source file and writes it to the destination. It performs a plain linear copy, locally, or over a network.

rsync 还可以在本地或通过网络复制文件.但它采用了一种特殊的增量传输算法和一些优化来使操作更快.考虑一下这个电话.

rsync also copies files locally or over a network. But it employs a special delta transfer algorithm and a few optimizations to make the operation a lot faster. Consider the call.

rsync A host:B

  • rsync 将检查 AB 的文件大小和修改时间戳,如果它们匹配,则跳过任何进一步的处理.

    • rsync will check files sizes and modification timestamps of both A and B, and skip any further processing if they match.

      如果目标文件 B 已经存在,增量传输算法将确保只发送 AB 之间的差异在电线上.

      If the destination file B already exists, the delta transfer algorithm will make sure only differences between A and B are sent over the wire.

      rsync 将数据写入临时文件 T,然后将目标文件 B 替换为 T 使更新对于可能正在使用 B 的进程看起来是原子的".

      rsync will write data to a temporary file T, and then replace the destination file B with T to make the update look "atomic" to processes that might be using B.

      它们之间的另一个区别涉及调用.rsync 有大量命令行选项,允许用户微调其行为.它支持复杂的过滤规则,以批处理模式、守护进程模式等运行.scp只有几个开关.

      Another difference between them concerns invocation. rsync has a plethora of command line options, allowing the user to fine tune its behavior. It supports complex filter rules, runs in batch mode, daemon mode, etc. scp has only a few switches.

      总而言之,将 scp 用于您的日常任务.您在交互式 shell 上偶尔键入的命令.它使用起来更简单,在这些情况下,rsync 优化不会有太大帮助.

      In summary, use scp for your day to day tasks. Commands that you type once in a while on your interactive shell. It's simpler to use, and in those cases rsync optimizations won't help much.

      对于重复性任务,例如 cron 作业,请使用 rsync.如前所述,在多次调用时,它将利用已传输的数据,执行速度非常快并节省资源.这是在网络上保持两个目录同步的绝佳工具.

      For recurring tasks, like cron jobs, use rsync. As mentioned, on multiple invocations it will take advantage of data already transferred, performing very quickly and saving on resources. It is an excellent tool to keep two directories synchronized over a network.

      另外,在处理大文件时,使用带有 -P 选项的 rsync.如果传输被中断,您可以通过重新发出命令从它停止的地方恢复它.请参阅 Sid Kshatriya 的答案.

      Also, when dealing with large files, use rsync with the -P option. If the transfer is interrupted, you can resume it where it stopped by reissuing the command. See Sid Kshatriya's answer.

      这篇关于`scp` 与 `rsync` 有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆