2017-11-15 7 views
-4

3つのフォルダを多くの宛先(600+)にコピーする必要があります。これを並列化する必要があります。 intance多くのディレクトリを多くの宛先にコピーする方法は? (大量のコピー)

C:\Data1 → D:\Data1 
C:\Data1 → D:\Data2 
C:\Data1 → D:\Data3 
D:\Data1 → \\\VM1\c$\Data1 
D:\Data2 → \\\VM1\c$\Data2 
D:\Data3 → \\\VM1\c$\Data3 
… 

については

は、私はそれぞれのカップルのためにRobocopy-仕事を呼び出すが、私はrobocopyを-スレッドのプロセスと多数のnomberを制限すること

[pscustomobject][ordered]@{ 
    Source = 'C:\Data1' 
    Dest = 'D:\Data1' 
}, 
[pscustomobject][ordered]@{ 
    Source = 'C:\Data1' 
    Dest = 'D:\Data2' 
}, 
[pscustomobject][ordered]@{ 
    Source = 'C:\Data1' 
    Dest = 'D:\Data3' 
}, 
… 
+1

なぜdownvoteのようにそれを呼び出します? – Alban

答えて

0

のためのオブジェクトを作成しました。

function Copy-AsParallelJod { 
    param (
     [Parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Mandatory = $true, Position = 0)] 
      [ValidateScript({ $_ | Test-Path })] 
       [string]$Source, 
     [Parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Mandatory = $true, Position = 1)] 
      [Alias('Dest')] 
       [string]$Destination, 
     $MaxRunningJob = 4, 
     $MaxThreadByJob = 8 
    ) 
    begin { 
     $Start = Get-Date 
     write-Host (get-date $Start -format 'yyyy/MM/dd HH:mm:ss') -back Magenta 
     # get-job | Remove-Job -Force 
    } 
    process { 
     while ((Get-Job -State Running | ?{$_.Name -like "Copy_*"}).count -ge $MaxRunningJob) { 
      # Write-host "Parallelisation CopyJob","Deja $MaxRunningJob en cour" 
      # Start-Sleep -Seconds 3 
      wait-Job -Name 'Copy_*' -Any | Receive-Job -AutoRemoveJob -Wait 
     } 
     $WorkName = (($Destination.split('\'))[-2..-1]) -join(' ') 
     Write-Color 'Start-Job',' : ',$Source.padleft(40),' => ',$Destination.padright(40),' @ ',(get-date -format 'yyyy/MM/dd HH:mm:ss') white,red,Magenta,red,yellow,red,green 
     Start-Job -ScriptBlock { 
      param($Source, $Dest, $log="/LOG+:C:\MAJ\SuiteExpert.log.txt", $MaxThread) 
      $Start = Get-Date 
      New-Item -Path $dest -type Directory -Force | Out-Null 
      [System.Threading.Thread]::CurrentThread.Priority = 'Lowest' 
      $PathIdentity = ($Dest.split('\')[-2..-1]) -join('\') 

      # write-host " +$([char]45)> Job RoboCopy Start [$(get-date $start -format 'yyyy/MM/dd HH:mm:ss')]",$PathIdentity 

      Robocopy $Source $Dest /E $log /TEE /MT:$MaxThread /S /DCOPY:DA /COPY:DAT /R:3 /W:2 | Out-Null 
      Start-Sleep -Seconds 1 

      $Time = (Get-Date) - $start 
      $Time = "$($time.Hours)h $("$($time.Minutes)".padleft(2,'0'))m $("$($time.Seconds)".padleft(2,'0'))s" 
      write-host "$dest ",(get-date $start -format 'yyyy/MM/dd HH:mm:ss'),"[$Time]" 
     } -ArgumentList $Source,$Destination,"/LOG+:$(split-path $Destination)\SuiteExpert($(get-date -format 'yyyy.MM.dd HH.mm'))-$WorkName.log.txt",$MaxThreadByJob -name Copy_$WorkName | Out-Null 
     Start-Sleep -Milliseconds 500 
    } 
    end { 
     Write-host 'Les deriere copies sont en cour','Encore quelques instants...' 
     Get-Job -Name 'Copy_*' | Receive-Job -AutoRemoveJob -Wait 
     $Time = (Get-Date) - $start 
     $Time = "$($time.Hours)h $("$($time.Minutes)".padleft(2,'0'))m $("$($time.Seconds)".padleft(2,'0'))s" 
     write-Host "$(get-date -format 'yyyy/MM/dd HH:mm:ss') [$Time]" -back Magenta 
    } 
} 

と私はその

[pscustomobject][ordered]@{ 
    Source = 'C:\Data1' 
    Dest = 'D:\Data1' 
}, 
[pscustomobject][ordered]@{ 
    Source = 'C:\Data1' 
    Dest = 'D:\Data2' 
}, 
[pscustomobject][ordered]@{ 
    Source = 'C:\Data1' 
    Dest = 'D:\Data3' 
} | Copy-AsParallelJod -MaxRunningJob 4 -MaxThreadByJob 8 
+0

警告!非常に強力なCPU、I/Oディスク、ネットワーク消費! – Alban

関連する問題