Batch file - need 7-zip alternative - cannot move

See updated answer below

Windows batch files.

I really like 7-Zip and it works great, but like WinZip, you can move files and timestamp files. However, WinZip (command line interface) has limitations on file size and number of files in the archive, for example.

Googling we see that there is a person who made a 7-zip code and recompiled the code to use the -m (move) switch. However, I do not feel comfortable using third-party Developers of 7-zip in our production environment.

Also, I saw - http://alternativeto.net/software/7-zip/

I coded: IF NOT ERRORLEVEL 1 (after the Zip process) to delete the file, but it is unsafe if there are several identical file name structures.

Here are some examples of code bits: 7zip:

D:\scripts\7za -tzip -y a D\zips\20140116_someclient_%computername%@%location%.zip D:\logs\apache_log.2014-01-16* >nul >>%logfile%
IF NOT ERRORLEVEL 1 ECHO Y|DEL D:\logs\apache_log.2014-01-16*

Where apache_log.2014-01-16 can be:

apache_log.2014-01-16.1
apache_log.2014-01-16.2
apache_log.2014-01-16.3

and etc.

Winzip

c:\progra~1\WinZip\Wzzip.exe -T -ex -m D\zips\20140116_someclient_%computername%@%location%.zip D:\logs\some_file.2014-01-16* >nul >>%logfile%

I think, in terms of software requirements, I would like to have some WinZip features in 7Zip. I like 7Zip, as it has the ability to work with large Archives. I like PeaZip and I used PowerArchiver many moons ago. My problem is that I work with Apache Tomcat for Windows, and we have to archive hourly logs, which can be more than 200-300 MB per hour, and it is necessary that the servers are not cleared of old logs.

Hope this makes more sense.

UPDATE:

Believe me, I answered my question.

FOR /F %%F IN ('dir /B "D:\serverlogs\server.log.2014-01-19*"') DO (
D:\work\scripts\7za.exe –tzip –y a "D:\ziplogs\201401109_COMPANY_SERVERNAME@DATACENTER.ZIP" >> D:\WORK\SCRIPTS\LOGS\LOG_20140120.LOG && DEL "D:\serverlogs\%%F"
)

Now it works well.

+4
2

- 7-Zip "-sdel" .

+7

7z Andy : http://sourceforge.net/p/sevenzip/discussion/45797/thread/5bf7022b/ p >

@ECHO off
echo ################################################
echo Zipping up Backups with 7-Zip
cd e:\gh\backups
7z.exe a %DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%_DB1-Prod.7z
    IF  "%errorlevel%"=="0" (goto testzips) ELSE (goto zipfail)
:testzips
echo ################################################
echo Testing Integrity of Zipfile
FOR %%i IN (*.7z) DO 7z.exe t %%i
    IF "%errorlevel%"=="0" (goto extract) ELSE (goto testzipfail)
:extract
echo ################################################
Echo Extracting files to temp folder
FOR %%i IN (*.7z) DO 7z.exe e %%i -oe:\gh\temp
IF  "%errorlevel%"=="0" (goto movezip) ELSE (goto errorextract)
:movezip
echo ################################################
echo Moving Zipped File to Archive Folder
move e:\gh\Backups\*.7z e:\gh\Archives
IF  "%errorlevel%"=="0" (goto testfiles) ELSE (goto archivemovefail)
:testfiles
echo ################################################
fc /b e:\gh\backups\*.4BS e:\gh\temp\*.4BS 
IF ERRORLEVEL 0 (goto testfile4BL) else (goto comparealert)
:testfile4BL
fc /b e:\gh\backups\*.4BL e:\gh\temp\*.4BL
IF ERRORLEVEL 0 (goto testfile4BK) else (goto comparealert)
:testfile4BK
fc /b e:\gh\backups\*.4BK e:\gh\temp\*.4BK
IF ERRORLEVEL 0 (goto testfile4BR) else (goto comparealert)
:testfile4BR
fc /b e:\gh\backups\*.4BR e:\gh\temp\*.4BR
IF ERRORLEVEL 0 (goto copytonas) else (goto comparealert)
:: IF ERRORLEVEL 1 (goto copytonas) ELSE (goto comparealert)
:copytonas
echo ################################################
echo Copying archive to Fileserver
robocopy e:\gh\Archives \\fileserver\backups /NP /MAXAGE:1
REM IF "%errorlevel%"=="1" (goto cleanup) ELSE (goto nascopyalert)
    if errorlevel 16 echo ***FATAL ERROR*** & goto nascopyalert
    if errorlevel 15 echo OKCOPY + FAIL + MISMATCHES + XTRA & goto nascopyalert
    if errorlevel 14 echo FAIL + MISMATCHES + XTRA & goto nascopyalert
    if errorlevel 13 echo OKCOPY + FAIL + MISMATCHES & goto nascopyalert
    if errorlevel 12 echo FAIL + MISMATCHES& goto nascopyalert
    if errorlevel 11 echo OKCOPY + FAIL + XTRA & goto nascopyalert
    if errorlevel 10 echo FAIL + XTRA & goto nascopyalert
    if errorlevel 9 echo OKCOPY + FAIL & goto nascopyalert
    if errorlevel 8 echo FAIL & goto nascopyalert
    if errorlevel 7 echo OKCOPY + MISMATCHES + XTRA & goto nascopyalert
    if errorlevel 6 echo MISMATCHES + XTRA & goto nascopyalert
    if errorlevel 5 echo OKCOPY + MISMATCHES & goto cleanup
    if errorlevel 4 echo MISMATCHES & goto nascopyalert
    if errorlevel 3 echo OKCOPY + XTRA & goto cleanup
    if errorlevel 2 echo XTRA & goto nascopyalert
    if errorlevel 1 echo OKCOPY & goto cleanup
    if errorlevel 0 echo No Change & goto nascopyalert
:cleanup
Echo Congrats - All files were backed up properly.  Cleaning up
REM cd e:\gh\temp
REM del /Q *.*
cd e:\gh\temp
    del /Q *.*
cd e:\gh\backups
    del /Q *.*
IF "%errorlevel%"=="0" (goto EOF) ELSE (goto cleanupalert)
:zipfail
echo FAILURE 
echo Backup files did not zip properly - Check Backups!!
:testzipfail
echo FAILURE 
echo Backup files did not pass integrity chec - Check Backups!!
:archivemovefail
echo FAILURE 
echo Backup files did not move to archive directory - Check Backups!!
:errorextract   
echo FAILURE 
echo Backup files did not extract to test directory properly - Check Backups!!
:comparealert
Echo FAILURE
echo Backup files did not pass comparison check in FC - Check Backups!!
:nascopyalert
echo FAILURE 
echo Backup files did not copy to the NAS - Check Backups!!
:cleanupalert
echo FAILURE 
echo Backup files did not clean up - Check Backups!!
:cleancomplete
:EOF
Echo Proccess Complete - Check Logs and emails.

. , 7zip.

0

All Articles