0

我们的公司备份垃圾软件让我失望了,我正在滚动我自己的备份/存档脚本,计划每周运行一次。

到目前为止,我所拥有的是:

$dst = "S:\VM-Bak"
$src = "D:\Work\Projects\CPS\MR4"
$fileName = "CPS-MR4.tar.gz"
$archive = $fileNam + "-" + (Get-Date -Format "yyyyMMdd")
$sigName = $fileName + ".sig"
$errorLog = (Join-Path -Path $dst -ChildPath ($fileName + ".err"))


Start-Process powershell -Verb runAs -WindowStyle Hidden 

Get-ChildItem -Exclude *.vmem -Recurse -Path $src -ErrorAction SilentlyContinue `
| Write-Tar -OutputPath (Join-Path -Path $dst -ChildPath $archive) -EntryPathRoot`
 $src | Write-GZip -Level 9 | Get-Hash | Format-Table -Property Path, Algorithm,`
 HashString, @{Label ="Date"; Expression ={(Get-Date -Format "dd/MMM/yyyy")}} `
-AutoSize -ErrorAction SilentlyContinue | Out-File -FilePath (Join-Path -Path $dst `
-ChildPath $sigName) -Append

现在,无论如何,我不能被认为是非常精通powershell,但我可以谷歌并弄清楚事情。话虽如此,这个脚本的目的是抓取我的虚拟机,跳过任何 vmem 文件(在无法访问时总是出错),将文件夹的全部内容收集到一个 tar 文件中,然后将输出压缩到不同的驱动器。它做了很多艰苦的工作,然后过了一段时间(它是一个 150GB 的虚拟机),我有了我的盖章、tar 过的压缩虚拟机。

注意事项。尝试使用 winzip 或 7zip 检查存档,这两个程序都声称它不是存档(我出于沮丧尝试了 winzip)。我试图将它作为 tar 存档打开,同样的事情。我得到的确切错误是:

Cannot open {path:\to\real file name} as archive

我不知道出了什么问题。我在一些帖子上读到我应该在 write-tar 上使用 -passthru,但不存在这样的开关(这是 PSCX 3.0.0)

如果您还可以帮助我处理签名文件,则可以加分,以便它附加到表格并从以下脚本中输出表格(未在上述脚本中实现)

Get-Hash | Format-Table -AutoSize -Property Path, Algorithm, Hashstring, `
@{Label="Date";Expression={(Get-Date -Format "dd/MMM/yyyy")}} 
4

0 回答 0