我需要使用powershell将数据库.bak拆分为多个文件。怎么做得最好? 有什么例子吗?
答案 0 :(得分:1)
这样的事可能有用:
$filename = "C:\path\to\your.bak"
$chunksize = 20480
$totalsize = (Get-Item $filename).Length
$stream = New-Object IO.FileStream($filename, [IO.FileMode]::Open)
$reader = New-Object IO.BinaryReader($stream)
$chunk = New-Object byte[] $chunksize
$size = $chunksize
$i = 0
do {
$rest = $totalsize - ($i * $chunksize)
$i++
if ($chunksize -gt $rest) {
$size = $rest
$chunk = New-Object byte[] $size
}
$reader.Read($chunk, 0, $size) | Out-Null
[IO.File]::WriteAllBytes(({0}.{1:d3}" -f ($filename, $i)), $chunk)
} until ($chunksize -gt $rest)
$reader.Close()
$stream.Close()