请参阅下面的更新回答
Windows批处理文件。
我非常喜欢7-Zip并且效果很好,但是就像WinZip的移动和时间戳文件一样。但是,WinZip(命令行界面)对文件大小和存档中的文件数量有限制。例如。
谷歌搜索我们确实看到有人,他确实采用了7-zip的代码并重新编译了代码以使用-m(移动)开关。但是,在我们的生产环境中使用7-zip开发人员以外的第三方感到不舒服。另外,我看过 - http://alternativeto.net/software/7-zip/
我编码: 如果不是ERRORLEVEL 1(在Zip处理之后)删除文件,但如果有多个相同的文件名结构,则这不安全。
以下是代码的一些示例: 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*
apache_log.2014-01-16 可能是:
apache_log.2014-01-16.1
apache_log.2014-01-16.2
apache_log.2014-01-16.3
等
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%
我想从软件需求的角度来看,我想在7Zip中拥有WinZip的一些功能..我喜欢7Zip,因为它有能力使用大型档案。我喜欢PeaZip,而且我之前使用的是PowerArchiver。我遇到的问题是我正在使用Apache Tomcat for Windows,我们必须存档每小时超过200-300 MB的日志,并且需要保持服务器不受旧日志的影响。
希望这更有意义。
更新
相信我已回答了我自己的问题。
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"
)
现在哪种方法效果很好。
答案 0 :(得分:7)
7-Zip的最新alpha版本支持新开关“-sdel”,以便在包含归档后删除文件。
答案 1 :(得分:0)
在7z讨论那里你可以找到一个疯狂的批处理方式来代替安迪在这个档案切换后丢失的删除:http://sourceforge.net/p/sevenzip/discussion/45797/thread/5bf7022b/
@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中,那就更好了。