Jump to content

Recommended Posts

Posted

I have a backup script which is causing me some consternation and would be grateful for some input / help.

 

The script is a loop that cycles through files in a folder, compresses and encrypts them. I use this script across a number of sites and it works in all but two and I cannot see why it's failing at 2. The code runs, the file name is created but the file size stays at zero and the script never moves on. The CPU isn't being taxed so it's just stuck.

 

These are the same constants across all the sites

 

- 7 Zip Module installed in Power shell using Install-Module -Name 7Zip4PowerShell -Verbose

- Server OS is 2016 Standard

 

 

The code is below.

 

cd $TargetFolderdir | ForEach-Object { & "C:\Program Files\7-Zip\7z.exe" a -p"$SQLKey" -tzip ($_.Name+".zip") $_.Name }

 

I have tried running it as a user, domain admin and local admin. I'm hoping I have missed installing a module somewhere.

 

Thanks

Posted

I can't see from that code why you need "7Zip for Powershell" module installed, as it's calling 7Zip directly from the command line.

 

At a guess, are you on a 64bit server with 7Zip 32bit installed, in which case path would be "Program Files (x86)"?

Posted
Thanks for the quick reply, I appreciate that I don't perhaps need the module but I have tried it with and without just to check. We have about 20 sites all of which are on Server 2016 with 7 Zip in C:\Program Files. What I'm struggling with is why two just won't run but the other 18 will. Hoping it's something obvious
Posted
Indeed I have and also run it as a domain admin, local admin and a domain user. It can be run manually from file explorer but just not from power shell.
Posted

It looks like this is the module you are importing: https://github.com/thoemmi/7Zip4Powershell plenty of info about the syntax on that site.

 

But the code you have given however isn't using that module.

 

cd $TargetFolderdir | ForEach-Object { & "C:\Program Files\7-Zip\7z.exe" a -p"$SQLKey" -tzip ($_.Name+".zip") $_.Name }

 

Your script is adding files to a zip file just using 7zip directly.

 

From scripting 7-zip myself there are a couple of issues you might want to look at:

 

7-zip version - 32 bit / 64 bit as others have mentioned - the file location varies and are all servers running the same release?

 

Try the standalone 7-zip, there is a version (extra) that has a standalone exe (7za.exe) that I have found more reliable and portable. - https://www.7-zip.org/download.html

 

I usually set the 7-zip application as an alias e.g.

 

set-alias -Name 7zip -Value "C:\Program Files\7-Zip\7z.exe"

 

Another thing in your script I'm not clear on is the part you are piping:

 

cd $TargetFolderdir | ...

 

I'd expect you to be doing something like

 

Get-ChildItem $TargetFolderdir

 

I'd try something more like:

 

set-alias -Name 7zip -Value "C:\Program Files\7-Zip\7za.exe"
cd $TargetFolderdir
Get-ChildItem $TargetFolderdir | ForEach-Object {7zip a -p"$SQLKey" -tzip ($_.Name+".zip") $_.Name }

 

If you want to use the module the command might be more like:

 

cd $TargetFolderdir
Get-ChildItem $TargetFolderdir | ForEach-Object {Compress-7Zip -Path $_.Name -ArchiveFileName ($_.Name+".zip") -Password "$SQLKey" -Format Zip}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...