0

Our corporate backup crap ware has failed me and I am rolling my own backup/archival script to be scheduled to run on a weekly basis.

What I have so far is:

$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

Now, by no stretch of the imagination can I be considered supremely well versed in powershell, but I can google and figure things out. Having said that the intent of this script is to grab my VM, skip over any vmem files (which always err out on not having access), collect the entire contents of the folder into a tar file then compress the output to a different drive. It does a lot of hard work and then after some time (its a 150GB VM) I have my stamped, tar-ed compressed VM.

The caveats. Trying to check the archive with winzip or 7zip, both programs claim that it is not an archive (I tried winzip out of frustration). I tried to open it as a tar archive, same thing. The exact error I get is:

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

I can't figure out what's wrong. I read on some post that I should use -passthru on write-tar, but no such switch exists (this is PSCX 3.0.0)

Bonus points if you can also help me with the signature file so that it appends to a table and outputs the table from the follwing (not implemented in the above script)

Get-Hash | Format-Table -AutoSize -Property Path, Algorithm, Hashstring, `
@{Label="Date";Expression={(Get-Date -Format "dd/MMM/yyyy")}} 
SteveMustafa
  • 621
  • 2
  • 8
  • 19
  • Looks like there is a typo in this line: `$archive = $fileNam + "-" + (Get-Date -Format "yyyyMMdd")` – andyb Mar 13 '14 at 02:49
  • Possible issue with PCSX 3 GZIP and 'standard' zip apps: http://pscx.codeplex.com/workitem/35029 – andyb Mar 13 '14 at 03:19
  • @andyb several questions. 1. I'm not using XP but 7, would this hhave significance? 2. I'm using Write-GZip, but this does seem to be a similar issue, I'll copy to linux and confirm. 3. I'm using PSCX 3.0 but I just saw 3.1, will upgrade and see if things are affected and post back – SteveMustafa Mar 13 '14 at 15:07
  • Not familiar with PSCX, but I would suggest you start with a simple script along the lines of `get-item $pathToFile | write-tar -outputPath $pathToTar`. Test to see if you get a valid TAR. Then add on `| write-gzip -level 9`. Test for valid GZIP. You get the idea. Once it's working, wrap it up as a function and use it in a `foreach` construction. – andyb Mar 13 '14 at 22:53
  • @andyb Sorry, got sidetracked with issues at a client. I did just that and I tested it on a smaller folder for speed. I tried tar-ing then gzipping, each independently and then as a chain. When it is independent everything is fine, as a chain, something goes wrong. I am now utterly confused. – SteveMustafa Mar 20 '14 at 13:56
  • Can you post output from `get-help write-tar -full` and `get-help write-gzip -full` to http://pastebin and post links in original post or comment? I don't have PS3 so cannot install PSCX 3. PSCX documentation is non-existent on website. – andyb Mar 20 '14 at 22:17
  • @andyb Sorry, got tied up with work on site over the weekend. Write-Tar: http://pastebin.com/GGpLmVKa Write-Gzip: http://pastebin.com/ELDu4z8g – SteveMustafa Mar 24 '14 at 15:40
  • have you tried the example shown in the help? This would at least give confidence that the functions do work and produce workable ZIP files. `dir c:\logs\ -rec -inc *.log | write-tar -output logs.tar | write-gzip -level 9 | move-item c:\archived_logs` – andyb Mar 24 '14 at 23:09
  • @andyb Hi guy, sorry, work got in the way of fun. I tried the example on a smaller sample size, that worked like a dream, but trying it on a 200 GB VM resulted in this question – SteveMustafa Mar 28 '14 at 19:39
  • Possibly some limit on size of file that can be compressed then. – andyb Mar 29 '14 at 02:21
  • @andyb that defeats the purpose of compression doesn't it? – SteveMustafa Mar 30 '14 at 02:30
  • If it works on 'small' files but fails on as 'big' file I would say that it raises the possibility of a file size limit. Either you take it further and try to establish if there's a bug in PSCX, or you try another solution. My suggestion is to use 7zip. – andyb Mar 30 '14 at 07:51
  • The VMs are shut down when you are backing up, right? If not, perhaps script a VM snapshot and back that up instead. – andyb Mar 30 '14 at 19:59
  • I used wrong terminology in previous comment. I meant 'clone' the VM, not snapshot. – andyb Apr 01 '14 at 01:40
  • @andyb Hi Guy, sorry, work has me under its fascist heel, slaving away. I tried going the 7-zip route the first time around but I had problems automating that i.e. scripting it. Have you come across a 7-zip compatible extension for PS? – SteveMustafa Apr 03 '14 at 14:25

0 Answers0