How to prevent Powershell from being used from "cached" data

I have the following command running in the command window:

"C:\Program Files (x86)\VisualSVN Server\bin\svnadmin.exe" dump --quiet "C:\svnrepo" | "C:\Program Files\7-Zip\7z.exe" a -si "C:\svnbak.7z"

      

This dumps the contents of my SVN repository into a receiving 7-zip instance, which writes the contents compressed to disk. When the command is run, I can see the 7z file grow as it finishes to completion.

When trying to include in Powershell v2 script, I changed it to:

& "C:\Program Files (x86)\VisualSVN Server\bin\svnadmin.exe" dump --quiet "C:\svnrepo" | "C:\Program Files\7-Zip\7z.exe" a -si "C:\svnbak.7z"

      

He complained that "expressions are only allowed as the first element of the pipeline." Based on another SO answer , I changed the command to this:

& "C:\Program Files (x86)\VisualSVN Server\bin\svnadmin.exe" dump --quiet "C:\svnrepo" | & "C:\Program Files\7-Zip\7z.exe" a -si "C:\svnbak.7z"

      

The Powershell script seems to run, but instead of writing the file slowly, only my memory is increasing. My guess is, instead of writing the content to the 7-zip process, Powershell "caches" the content until the dump is complete. When the dump is finished, the contents will be migrated to 7-zip. Is there anyway to prevent this from happening (to get the same results as the original command)?

+3


source to share


1 answer


This is more of a suggestion than a solution, but it might help your situation. I've experimented a lot with this and I can't seem to get the data to dump to 7z until everything is loaded into memory (and then some). My guess is that "normal" shells take the standard command of the first command and pipe it to the stdin of the second command when you use the pipe. With PowerShell, everything is an object. So it tries to pass objects and doesn't know which object should go through until it's loaded. If your first command created an array of strings, and the second could consume the array from the pipeline, it would probably work as expected.

Here's a partial solution:

New-Alias svnadmin "C:\Program Files (x86)\VisualSVN Server\bin\svnadmin.exe"
New-Alias 7z "C:\Program Files\7-Zip\7z.exe"
svnadmin dump --quiet "C:\svnrepo" > snvdump.txt 
Get-Content svndump.txt | 7z a -si "C:\svnbak.7z"

      

This uses about 1/5 of the memory as a shape solution, but still more than it needs to be. It also doesn't clear data until 7z until it's loaded, so it might not work depending on the size of your dump.




Update: Since it runs in CMD and not PowerShell (and svnadmin and 7z are console apps, not cmdlets), why not just call CMD?

 CMD /C """C:\Program Files (x86)\VisualSVN Server\bin\svnadmin.exe"" dump --quiet ""C:\svnrepo"" | ""C:\Program Files\7-Zip\7z.exe"" a -si ""C:\SourceCode\svnbak.7z"""

      

Notice I don't have svn on my machine, so I did it with a large text file:

CMD /C "type files.txt | ""C:\Program Files\7-Zip\7z.exe"" a -si ""C:\SourceCode\svnbak.7z"""

      

CMD

should be in your way, so it should just work. It was much faster on my machine and was used without memory.

+1


source







All Articles