将约 300GB 的文件从一台服务器传输到另一台服务器

将约 300GB 的文件从一台服务器传输到另一台服务器

我今天要将大约 200,000 个文件传输到新服务器。我以前从未做过如此大规模的工作,想获得一些关于如何进行此操作的建议。我正在两个 Centos 6 发行版之间移动它们,它们位于该国的不同位置。原始服务器上的硬盘空间不足以将所有目录和文件打包成一个巨大的 tarball,所以我的问题是我应该如何传输所有这些文件?rsync?使用 rsync 的一些特殊方法?任何关于如何操作的意见/建议都将非常棒。

谢谢

screen编辑:对于那些想知道的人,我强烈建议在运行这样的大型命令时使用rsync。尤其是当发生一些愚蠢的事情并且您失去与运行命令的服务器 A 的连接时rsync。然后只需断开屏幕并稍后恢复即可。

答案1

只是为了充实西蒙的回答rsync是完成这项工作的完美工具:

   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 algo‐
   rithm,  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 destination.  Rsync is widely used
   for backups and mirroring and as an improved copy command  for
   everyday use.

假设您有远程机器的 ssh 访问权限,您可能想要执行以下操作:

rsync -hrtplu path/to/local/foo [email protected]:/path/to/remote/bar

这会将目录复制path/to/local/foo/path/to/remote/bar远程服务器上。bar/foo将创建一个名为的新子目录。如果您只想复制内容目录,而不在目标上创建该名称的目录,请添加尾随斜杠:

rsync -hrtplu path/to/local/foo/ [email protected]:/path/to/remote/bar

这会将的内容复制foo/到远程目录中bar/

一些相关的选项:

 -h,                         output numbers in a human-readable format 
 -r                          recurse into directories
 -t, --times                 preserve modification times
 -p, --perms                 preserve permissions
 -l, --links                 copy symlinks as symlinks
 -u, --update                skip files that are newer on the receiver
 --delete                    delete extraneous files from dest dirs
 -z, --compress              compress file data during the transfer
 -C, --cvs-exclude           auto-ignore files in the same way CVS does
 --progress                  show progress during transfer
 --stats                     give some file-transfer stats

答案2

这取决于需要复制的速度以及可用的带宽量。

对于较差的网络连接,请考虑一辆装满磁带的卡车的带宽。(阅读:邮寄 2.5 英寸硬盘,或者自己开车去那里。300 千兆位驱动器应该很容易找到)。

如果时间要求不是很高或者您有足够的带宽,那么 rsync 就很不错。如果出现错误,您可以继续,而不必重新复制较早的文件。

[编辑] 我忘了补充一点,如果在复制过程中使用了数据,您可以多次运行 rsync。

示例:
1) 数据正在使用。Rsync -> 所有数据都已复制。这可能需要一些时间。2
) 再次运行 rsync,只复制已更改的文件。这应该很快。

您可以多次执行此操作,直到没有任何变化,或者您可以通过在复制期间将数据设为只读来以智能/安全的方式执行此操作。(例如,如果它位于已使用的共享集上,则该共享设置为只读。或者 rsync 数据,然后在晚上第二次运行时将共享设置为只读)。

答案3

我会选择 rsync!我用它将我的服务器备份到异地服务器,它工作得很好。通常需要复制几 MB,但有时它会达到 20-30GB,而且它总是正常工作。

答案4

首次使用 NFS 和 tar/untar(在这种情况下,NFS 是最快的协议,tar 通过更多的 CPU 利用率来节省网络带宽)

tar cf - * | ( cd /target; tar xfp -)

下次使用 rsync

相关内容