7zip Like files to multiple archives

  • Andrew

    Andrew - 2013-08-17

    I need an automatic way to zip some nighlty backups and send them via SFTP to a remote storage location.

    The application I support utilizes 3 databases and logs per entity that are named using an id number. I work with about 30 unique entities (id's). Counting the db and log I have 6 files to zip per entity each night.

    Each night I use db events to place a nightly backup in my nightly backup folder. Here is an example of what the folder might contain .... db111.db, db111.log, ab111.db, ab111.log, bb111.db, bb111.log and db222.db, db222.log, ab222.db, ab222.log, bb222.db and bb222.log.....and so on.

    Using batch and the command line of 7zip, I want to end up with 1 archive for each of the six files with the same id. The archive for id 111 would contain six files and be named something like 111.z, all 6 files for 222 would end up in 222.z, and so on....

    I know the command is something like:

    7za a C:\Archive\WILDCARD.z C:\Nightly Backup*%%.*

    I am very new to doing anything on a command line or in batch. I could force this to work by saving my backed up DB's in individual folders, but I am hoping to leave them all in the same place.

    Thanks for any help!!

    I am a non-programmer, new to command and batch. Thanks for any help you all can provide.

  • fernando

    fernando - 2013-08-17

    first -
    why .Z ... 7-zip does not compress to .Z

    second -
    today to make "111.z" what to do tommorrow? do yo overwrite or what?

    third -
    is always like:

    same prefix (ab, bb, db) of .log and .db pairs?

  • Andrew

    Andrew - 2013-08-19

    Hi Fernando,

    My syntax for the command was very general. I know there are switches to make the file compress to .zip or with no switch I should get a *.7z file extension on my archive.

    Yes I will the overwrite each night, because at the end of the batch file that archives these folders there is a call to WINSCP to send the zip file to remote storage.

    Here is a sample command I was given, but the person using this was only configuring it to work for one entity number (###). If a wildcard is not possible, can I modify line 2 in the batch shown below for each ### and have 30 7zip commands in the batch?

    Setup give n for one ###:

    @Echo Off
    7za a C:..Nightly\Send\NAMEBKDB.7z C:..NIGHTLY\DBBKUP*.
    -mhe -pBBywhYCFdIuPMu_7
    cd "C:\Program Files (x86)\WinSCP" WinSCP.exe /console /script=C:..NIGHTLY\SFTPBKUP.txt /log=C:..NIGHTLY\SFTPlog.txt cd C:..NIGHTLY\Send del . /Q

    Will sending the command to zip multiple times in the batch work?:

    @Echo Off
    7za a C:..NIGHTLY\Send\111.7z C:..NIGHTLY\DBBKUP*111.
    -mhe -pBBywhYCFdIuPMu_7
    7za a C:..NIGHTLY\Send\222.7z C:..NIGHTLY\DBBKUP*222.
    -mhe -pBBywhYCFdIuPMu_7
    7za a C:..NIGHTLY\Send\999.7z C:..NIGHTLY\DBBKUP*999.
    -mhe -pBBywhYCFdIuPMu_7
    cd "C:\Program Files (x86)\WinSCP" WinSCP.exe /console /script=C:..NIGHTLY\SFTPBKUP.txt /log=C:..NIGHTLY\SFTPlog.txt cd C:..NIGHTLY\Send del . /Q

    Sorry for the long post, and thanks for any input!

  • fernando

    fernando - 2013-08-21

    you do not answer this "same prefix (ab, bb, db) of .log and .db pairs?"

    idea is to use ab###.db (or whatever file name schema is consistent)
    to find the ### (right trim the file extension, left trim two characters).
    then archive all ###. files into archive named ###.7z

    -ax!*.7z added just to ensure archive ###.7z does not get archived in itself

    you add the -mhe and -p switches

    look at...

    FOR /F %%I IN ('DIR/b C:\NIGHTLY\DBBKUP\ab*.db') DO (
    SET A=%%~nI
    7z a C:\NIGHTLY\Send\!A:ab=! C:\NIGHTLY\DBBKUP\*!A:ab=!* -ax!*.7z

    see code.txt attached to this forum post for unaltered code.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks