我编写了一个批处理文件,它执行以下操作:
REM @ECHO OFF
rem %1 = coid
rem %2 = rpg location with ending /
rem get the path of this cmd script
SET SUBDIR=%~dp0
SET BKUPDIR=%SUBDIR%BACKUPS\
SET LOGFILE=%BKUPDIR%backup.log
ECHO ************************************************* >>%LOGFILE%
ECHO STARTING BACKUP FOR %1 AT %2 >>%LOGFILE%
FOR /f "skip=1" %%x in ('wmic os get localdatetime') DO IF NOT defined mydate SET mydate=%%x
SET filedate=%mydate:~0,14%
SET fullname=%BKUPDIR%%1_%FILEDATE%.ZIP
ECHO BKUPDIR: %BKUPDIR% >>%LOGFILE%
ECHO mydate: %mydate% >>%LOGFILE%
ECHO filedate: %filedate% >>%LOGFILE%
ECHO fullname: %fullname% >>%LOGFILE%
ECHO SUBDIR: %SUBDIR% >>%LOGFILE%
rem lets make sure the backup directory exists before starting
IF NOT EXIST %BKUPDIR% MD %BKUPDIR% >>%LOGFILE%
%SUBDIR%7z a -tzip %fullname% %2%1*.d
IF ERRORLEVEL 255 ECHO user_stopped_the_process >>%LOGFILE%
IF ERRORLEVEL 8 ECHO not_enough_memory >>%LOGFILE%
IF ERRORLEVEL 7 ECHO command_line_error >>%LOGFILE%
IF ERRORLEVEL 2 ECHO fatal_error >>%LOGFILE%
IF ERRORLEVEL 1 ECHO ok_warnings >>%LOGFILE%
IF ERRORLEVEL 0 GOTO END
IF EXIST %fullname% DEL %fullname%
:END
ECHO FINISHING BACKUP FOR %1 >>%LOGFILE%
ECHO ************************************************* >>%LOGFILE%
set mydate=
我将文件保存为文件的%1
创建日期/时间:
SSS_20130110133304.ZIP
SSS_20130110133336.ZIP
我在任务调度程序中运行它以每天晚上运行。
我想避免目录中有太多 zip 文件,所以我想保留最后 30 个存在的 zip 文件。
我被困在这一点上。如何保留最近的 30 个 zip 文件,这样我就不会收到一堆垃圾的 zip 文件?