Create multiple zip files

  • I have found many examples how to zip ziles, but is there  native to P/S how to create multiple zip files based upon a parm to split them based upon given  filesize?

    I have a large backup file .bak that I would like to split into x files as based upon a parm of filesz. If I set filesz to 100mb it creates x zip files of 100mb based upon what size of the .bak file.

    Thanks.

  • Try this.  Splits files, then zips each one.

    $from = "C:\temp\bigfile.exe"
    $rootName = "C:\temp\bigfile"
    $ext = "chunk"
    $upperBound = 500KB


    $fromFile = [io.file]::OpenRead($from)
    $buff = new-object byte[] $upperBound
    $count = $idx = 0
    try {
    do {
    "Reading $upperBound"
    $count = $fromFile.Read($buff, 0, $buff.Length)
    if ($count -gt 0) {
    $to = "{0}.{1}.{2}" -f ($rootName, $idx, $ext)
    $toFile = [io.file]::OpenWrite($to)
    try {
    "Writing $count to $to"
    $tofile.Write($buff, 0, $count)
    } finally {
    $tofile.Close()
    compress-archive $to "$to.zip"
    }
    }
    $idx ++
    } while ($count -gt 0)
    }
    finally {
    $fromFile.Close()
    }
  • I don't believe windows will do split zip files natively so you would need to download some other program to do it.  7-zip does have a command line so that might work.

  •  

    Cool.

     

    That worked perfect to do split is there away then to using the chunk file to recreate the original file I zipped.

  • I want to get rid of the BIG file I'm trying to ZIP but need to make sure I can recreate from the multiple Chunk files created..

    Thx.

  • Try this.  Please mark as answered if this does the trick.

    ls "c:\temp\bigfile*chunk*.zip" | Expand-Archive -force -destinationpath c:\temp
    cmd /c copy /b "c:\temp\bigfile*chunk" "c:\temp\bigfile.exe"

     

  • Perfect Thanks!!!!

  • Bruin wrote:

    I have found many examples how to zip ziles, but is there  native to P/S how to create multiple zip files based upon a parm to split them based upon given  filesize?

    I have a large backup file .bak that I would like to split into x files as based upon a parm of filesz. If I set filesz to 100mb it creates x zip files of 100mb based upon what size of the .bak file.

    Thanks.

    What is it that you're actually trying to do... email a large .bak to someone or something?  If that's true, why not just copy it to somewhere where other people can simply download it.  GitHub, for example.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Bruin wrote:

    I have found many examples how to zip ziles, but is there  native to P/S how to create multiple zip files based upon a parm to split them based upon given  filesize?

    I have a large backup file .bak that I would like to split into x files as based upon a parm of filesz. If I set filesz to 100mb it creates x zip files of 100mb based upon what size of the .bak file.

    Thanks.

    Quick questions, what version and edition of SQL Server are you using? Is this a backup file? If so, why don't you simply use backup compression (gzip algo) and multiple destination files, produces almost the same result?

    😎

     

  • Eirikur Eiriksson wrote:

    Bruin wrote:

    I have found many examples how to zip ziles, but is there  native to P/S how to create multiple zip files based upon a parm to split them based upon given  filesize?

    I have a large backup file .bak that I would like to split into x files as based upon a parm of filesz. If I set filesz to 100mb it creates x zip files of 100mb based upon what size of the .bak file.

    Thanks.

    Quick questions, what version and edition of SQL Server are you using? Is this a backup file? If so, why don't you simply use backup compression (gzip algo) and multiple destination files, produces almost the same result?

    😎

    I was thinking in a similar fashion until I saw the 100MB limit per file.  That smacks of someone trying to send a database via multiple emails.  I don't have what are consider to be really big databases but I do have tables with NCI's that would take 650 of those size files.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • It was to transfer files across network to backup storage location. I was weighing impact of doing the compression in the SQL backup versus a script..

    Thx.

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply