远程Linux服务器到远程Linux服务器目录的复制。 如何?

发布于 2024-07-05 09:40:49 字数 1476 浏览 11 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

青衫儰鉨ミ守葔 2024-07-12 09:40:49

我会修改之前建议的回复:

rsync -avlzp /path/to/sfolder [email protected]:/path/to/remote/dfolder

如下:

-a (用于存档)意味着 -rlptgoD,因此上面的 l 和 p 是多余的。 我还喜欢包含 -H,它复制硬链接。 默认情况下它不是 -a 的一部分,因为它很昂贵。 现在我们有了这个:

rsync -aHvz /path/to/sfolder [email protected]:/path/to/remote/dfolder

您还必须小心尾随斜杠。 您可能希望这样做

rsync -aHvz /path/to/sfolder/ [email protected]:/path/to/remote/dfolder

如果希望源“sfolder”的内容出现在目标“dfolder”中, 。 如果没有尾部斜杠,将在目标“dfolder”中创建一个“sfolder”子目录。

I would modify a previously suggested reply:

rsync -avlzp /path/to/sfolder [email protected]:/path/to/remote/dfolder

as follows:

-a (for archive) implies -rlptgoD so the l and p above are superfluous. I also like to include -H, which copies hard links. It is not part of -a by default because it's expensive. So now we have this:

rsync -aHvz /path/to/sfolder [email protected]:/path/to/remote/dfolder

You also have to be careful about trailing slashes. You probably want

rsync -aHvz /path/to/sfolder/ [email protected]:/path/to/remote/dfolder

if the desire is for the contents of the source "sfolder" to appear in the destination "dfolder". Without the trailing slash, an "sfolder" subdirectory would be created in the destination "dfolder".

流殇 2024-07-12 09:40:49

我通常有两种方法来做到这一点,都使用 ssh:

scp -r sourcedir/ [email protected]:/dest/dir/

或者,更强大和更快(就传输速度而言)的方法:

rsync -auv -e ssh --progress sourcedir/ [email protected]:/dest/dir/

如果您想了解有关它们如何工作的更多详细信息,请阅读每个命令的手册页。

There are two ways I usually do this, both use ssh:

scp -r sourcedir/ [email protected]:/dest/dir/

or, the more robust and faster (in terms of transfer speed) method:

rsync -auv -e ssh --progress sourcedir/ [email protected]:/dest/dir/

Read the man pages for each command if you want more details about how they work.

复古式 2024-07-12 09:40:49
scp -r <directory> <username>@<targethost>:<targetdir>
scp -r <directory> <username>@<targethost>:<targetdir>
温柔少女心 2024-07-12 09:40:49

rsync -avlzp /path/to/folder [电子邮件受保护]:/path /到/远程/文件夹

rsync -avlzp /path/to/folder [email protected]:/path/to/remote/folder

戏蝶舞 2024-07-12 09:40:49

登录一台机器

$ scp -r /path/to/top/目录用户@服务器:/path/to/copy

Log in to one machine

$ scp -r /path/to/top/directory user@server:/path/to/copy

薆情海 2024-07-12 09:40:49

scp 可以完成这项工作,但有一个问题:到第二个远程目标的连接将使用第一个远程目标上的配置,因此如果您在本地环境上使用 .ssh/config,并且您期望 rsa 和 dsa 密钥工作时,您必须将代理转发到第一个远程主机。

scp will do the job, but there is one wrinkle: the connection to the second remote destination will use the configuration on the first remote destination, so if you use .ssh/config on the local environment, and you expect rsa and dsa keys to work, you have to forward your agent to the first remote host.

徒留西风 2024-07-12 09:40:49

理想情况下,作为非 root 用户:

scp -r src $host:$path

如果您已经有了 $host 上的一些内容,请考虑使用 rsync 和 ssh 作为隧道。

/艾伦

As non-root user ideally:

scp -r src $host:$path

If you already some of the content on $host consider using rsync with ssh as a tunnel.

/Allan

So尛奶瓶 2024-07-12 09:40:49

我想你可以尝试:(

rsync -azvu -e ssh user@host1:/directory/ user@host2:/directory2/

我假设你在host0上,并且你想直接从host1复制到host2)

如果上面的方法不起作用,你可以尝试:

ssh user@host1 "/usr/bin/rsync -azvu -e ssh /directory/ user@host2:/directory2/"

在这个中,如果你已经有设置,它会起作用从host1到host2的无密码SSH登录

I think you can try with:

rsync -azvu -e ssh user@host1:/directory/ user@host2:/directory2/

(and I assume you are on host0 and you want to copy from host1 to host2 directly)

If the above does not work, you could try:

ssh user@host1 "/usr/bin/rsync -azvu -e ssh /directory/ user@host2:/directory2/"

in the this, it would work, if you already have setup passwordless SSH login from host1 to host2

池木 2024-07-12 09:40:49

查看 scprsync,
man scp
手动rsync

scp file1 file2 dir3 user@remotehost:path

Check out scp or rsync,
man scp
man rsync

scp file1 file2 dir3 user@remotehost:path
梦断已成空 2024-07-12 09:40:49

好吧,快速的答案是查看“scp”联机帮助页,或者可能是 rsync - 完全取决于您需要复制的内容。 如果必须的话,你甚至可以通过 ssh 执行 tar-over-ssh:

tar cvf - | ssh server tar xf -

Well, quick answer would to take a look at the 'scp' manpage, or perhaps rsync - depending exactly on what you need to copy. If you had to, you could even do tar-over-ssh:

tar cvf - | ssh server tar xf -
晨与橙与城 2024-07-12 09:40:49

如果任务是重复出现的,请尝试一致。
http://www.cis.upenn.edu/~bcpierce/unison/

Try unison if the task is recurring.
http://www.cis.upenn.edu/~bcpierce/unison/

焚却相思 2024-07-12 09:40:49

我使用 rdiffbackup http://www.nongnu.org/rdiff-backup/index.html 因为它可以满足您的所有需求,无需任何花哨的选项。 它基于 rsync 算法。
如果您只需要复制一次,稍后可以删除目标主机上的 rdiff-backup-data 目录。

rdiff-backup user1@host1::/source-dir user2@host2::/dest-dir

来自文档:

rdiff-backup 还保留
子目录、硬链接、开发文件、
权限、uid/gid 所有权、
修改时间,延长
属性、ACL 和资源分支。

这是 scp -p 提案的一个好处,因为 -p 选项不会保留

ubuntu 上的所有安装(例如,目录权限设置错误):

sudo apt-get install rdiff-backup

I used rdiffbackup http://www.nongnu.org/rdiff-backup/index.html because it does all you need without any fancy options. It's based on the rsync algorithm.
If you only need to copy one time, you can later remove the rdiff-backup-data directory on the destination host.

rdiff-backup user1@host1::/source-dir user2@host2::/dest-dir

from the doc:

rdiff-backup also preserves
subdirectories, hard links, dev files,
permissions, uid/gid ownership,
modification times, extended
attributes, acls, and resource forks.

which is an bonus to the scp -p proposals as the -p option does not preserve all (e.g. rights on directories are set badly)

install on ubuntu:

sudo apt-get install rdiff-backup
段念尘 2024-07-12 09:40:49

使用 rsync 以便在连接中断时可以继续。 如果发生变化,您也可以更快地复制它们!

Rsync 与 SSH 配合使用,因此您的复制操作是安全的。

Use rsync so that you can continue if the connection gets broken. And if something changes you can copy them much faster too!

Rsync works with SSH so your copy operation is secure.

薄情伤 2024-07-12 09:40:49

如上所述的 scp 通常是最好的方法,但不要忘记远程目录规范中的冒号,否则您将在本地计算机上获得源目录的副本。

scp as mentioned above is usually a best way, but don't forget colon in the remote directory spec otherwise you'll get copy of source directory on local machine.

鲜肉鲜肉永远不皱 2024-07-12 09:40:49

我喜欢通过 ssh 通过管道传输 tar。

tar cf - [目录] | ssh [用户名]@[主机名] tar xf - -C [远程主机上的目标]

此方法为您提供了很多选项。 由于您应该禁用 root ssh,因此为多个用户帐户复制文件很困难,因为您是以普通用户身份登录远程服务器。 为了解决这个问题,您可以在远程机器上创建一个 tar 文件,该文件仍然保留所有权。

tar cf - [目录] | ssh [用户名]@[主机名] "cat > output.tar"

对于慢速连接,您可以添加压缩,z 用于 gzip,j 用于 bzip2。

tar cjf - [目录] | ssh [用户名]@[主机名] "cat > output.tar.bz2"

tar czf - [目录] | ssh [用户名]@[主机名] "cat > output.tar.gz"

tar czf - [目录] | ssh [用户名]@[主机名] tar xzf - -C [远程机器上的目标]

I like to pipe tar through ssh.

tar cf - [directory] | ssh [username]@[hostname] tar xf - -C [destination on remote box]

This method gives you lots of options. Since you should have root ssh disabled copying files for multiple user accounts is hard since you are logging into the remote server as a normal user. To get around this you can create a tar file on the remote box that still hold that preserves ownership.

tar cf - [directory] | ssh [username]@[hostname] "cat > output.tar"

For slow connections you can add compression, z for gzip or j for bzip2.

tar cjf - [directory] | ssh [username]@[hostname] "cat > output.tar.bz2"

tar czf - [directory] | ssh [username]@[hostname] "cat > output.tar.gz"

tar czf - [directory] | ssh [username]@[hostname] tar xzf - -C [destination on remote box]

泪冰清 2024-07-12 09:40:49

如果您真的想要一个精确的副本,您可能还想使用 scp 的 -p 开关(如果您正在使用它)。 我发现 scp 从设备读取,并且我在 cpio 方面遇到了问题,所以我个人总是使用 tar,如下所示:

cd /origin; find . -xdev -depth -not -path ./lost+found -print0 \
| tar --create --atime-preserve=system --null --files-from=- --format=posix \
--no-recursion --sparse | ssh targethost 'cd /target; tar --extract \
--overwrite --preserve-permissions --sparse'

我将这个咒语保留在文件与各种其他方式复制文件。 这个用于通过 SSH 进行复制; 其他的用于复制到压缩存档、在同一台计算机内复制以及在 SSH 太慢时通过未加密的 TCP 套接字进行复制。

If you are serious about wanting an exact copy, you probably also want to use the -p switch to scp, if you're using that. I've found that scp reads from devices, and I've had problems with cpio, so I personally always use tar, like this:

cd /origin; find . -xdev -depth -not -path ./lost+found -print0 \
| tar --create --atime-preserve=system --null --files-from=- --format=posix \
--no-recursion --sparse | ssh targethost 'cd /target; tar --extract \
--overwrite --preserve-permissions --sparse'

I keep this incantation around in a file with various other means of copying files around. This one is for copying over SSH; the other ones are for copying to a compressed archive, for copying within the same computer, and for copying over an unencrypted TCP socket when SSH is too slow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文