2017-11-22 18 views
0

Powershellを使用してファイルを分割して再接続するときに、破損したファイルを取得する際にいくつかの問題が発生しました。Powershellを使用してデータベースバックアップファイルを分割して後でマージします

44GBのサイズの.bakファイルをダウンロードする必要があるリモートサーバーがあります。これを行うには、このスクリプトを使用して、ファイルをより小さな(100MB)に分割しています。この後

$from = "D:\largebakfile\largefile.bak" 
$rootName = "D:\foldertoplacelargebakfile\part" 
$ext = "PART_" 
$upperBound = 100MB 


$fromFile = [io.file]::OpenRead($from) 
$buff = new-object byte[] $upperBound 
$count = $idx = 0 
try { 
    do { 
     "Reading $upperBound" 
     $count = $fromFile.Read($buff, 0, $buff.Length) 
     if ($count -gt 0) { 
      $to = "{0}{1}{2}" -f ($rootName, $idx, $ext) 
      $toFile = [io.file]::OpenWrite($to) 
      try { 
       "Writing $count to $to" 
       $tofile.Write($buff, 0, $count) 
      } finally { 
       $tofile.Close() 
      } 
     } 
     $idx ++ 
    } while ($count -gt 0) 
} 
finally { 
    $fromFile.Close() 
} 

が行われ、「PART_」のファイルが私は戻ってtogheter 1つの.BAKファイルにファイルをマージするために、このザ・スクリプトを使用してローカルコンピュータにダウンロードされています。

# replace with the location of the "PARTS" file 
Set-Location "C:\Folderwithsplitfiles\Parts" 

# replace with the SQL backup folder in your computer. 
$outFile = "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\newname.bak" 

#The prefix for all PARTS files 
$infilePrefix ="C:\Folderwithsplitfiles\Parts\PART_" 


$ostream = [System.Io.File]::OpenWrite($outFile) 
$chunkNum = 1 
$infileName = "$infilePrefix$chunkNum" 
$offset = 0 
while(Test-Path $infileName) { 
     $bytes = [System.IO.File]::ReadAllBytes($infileName) 
     $ostream.Write($bytes, 0, $bytes.Count) 
     Write-Host "read $infileName" 
     $chunkNum += 1 
     $infileName = "$infilePrefix$chunkNum" 
} 
$ostream.close(); 

#Get-FileHash $outfile | Format-List 

SSMSでデータベースを復元しようとすると、基本的にファイルが破損して復元できないというエラーが表示されます。

私は数日前にこれに苦労していましたが、私の頭が正しいとは思われません。

すべては機能しているようですが、何かが私にこれらのエラーを引き起こしています。誰にもアイデアはありますか?事前に

おかげ /D

答えて

0

は、私はあなたがBackground Intelligent Transfer Serviceを見てお勧めかもしれませんが、あなたは何を複雑にわたり保存するために一枚でファイル全体をダウンロードすることができるはずです。 (転送開始/停止などもサポート)

+0

Intresting !!それをチェックする=) – DL1

関連する問題