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 개 박 파일에 파일을 병합이 scipt를 사용하여 로컬 컴퓨터로 다운로드됩니다.
# 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
Intresting !! 이것을 체크 할 것이다 =) – DL1