简体   繁体   English

PowerShell RoboCopy 从一台服务器到另一台服务器的特定文件

[英]PowerShell RoboCopy Specific Files From 1 Server to Another Server

Consider a scenario:考虑一个场景:

  1. Server A has one File_Folder where there are 100K + files, and some files might be super huge服务器A有一个File_Folder,里面有100K+个文件,有些文件可能超级大
  2. I have a .csv File for each user(which has a complete set of files list to be copied from Server A File_Folder) to Server B(where there is a directory for this each User)我为每个用户都有一个 .csv 文件(其中有一组完整的文件列表要从服务器 A File_Folder 复制到服务器 B(每个用户都有一个目录)

My logic is 1) Read each CSV files for each user 1 by 1 2) put the list for RoboCopy to copy files from Server A to Server B each user folder 3) it works for me but it is super slow.我的逻辑是 1) 为每个用户 1 个 1 读取每个 CSV 文件 2) 将 RoboCopy 的列表放在每个用户文件夹中将文件从服务器 A 复制到服务器 B 3) 它对我有用,但速度非常慢。 I want to make it faster.我想让它更快。

Note: Mandatory to use PowerShell注意:必须使用 PowerShell

My Code look like this我的代码看起来像这样

$Get_CSV_File_INFO = @(Get-Content $Full_CSV_Path )
$SourcePath = "z:\"

foreach($a in $Get_CSV_File_INFO)
    {

    if($a -match '.zip')
     {
     $RS_Report_Name.add($a) |Out-Null
     }
}

$RS_Report_Name | % { Robocopy $SourcePath  $path $_} | Out-Null

Destionation Path is like Y:\\UserA, Y:\\UserB etc.....目标路径就像 Y:\\UserA, Y:\\UserB 等.....

Any suggestion might help.任何建议都可能有所帮助。

I am not logging and not showing any output;我没有记录,也没有显示任何输出; it improved the speed but still Copying total of "2.57 MB" files took around 9 minutes which is not good in a real life scenario.它提高了速度,但仍然复制“2.57 MB”文件总共需要大约 9 分钟,这在现实生活中并不好。

Assuming $RS_Report_Name is an array filtered to only the files you want to copy changing the robocopy to copy all files instead of one by one should have a big impact.假设$RS_Report_Name是一个仅过滤到要复制的文件的数组,将robocopy更改为复制所有文件而不是一个一个地复制应该会产生很大的影响。

robocopy $SourcePath $path $RS_Report_Name

If that still exceeds the max command length, split the array into smaller groups say 10-50 and run Robocopy on each.如果仍然超过最大命令长度,将数组分成更小的组,比如 10-50,并在每个组上运行Robocopy

Thanks Matthew Wetmore for the suggestion to run PowerShell Script on Destination server and Thanks Travis for the Suggestions to divide the arraylist感谢 Matthew Wetmore 建议在目标服务器上运行 PowerShell 脚本并感谢 Travis 建议划分数组列表

$Report_array2 = $Report_array[$Initial_Counter .. $Counter] $Report_array2 = $Report_array[$Initial_Counter .. $Counter]

Robocopy "$SourcePath" "$path" $Report_array2 /MT /Z |out-Null Robocopy "$SourcePath" "$path" $Report_array2 /MT /Z |out-Null

Also I use /MT for Multi Threading and /Z(Restart Mode) performance increased from Minutes to few Seconds我还使用 /MT 进行多线程和 /Z(重启模式)性能从几分钟增加到几秒钟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM