I have written a batch file that does the following:
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=
I am saving the files as the %1
and the date/time the file was created:
SSS_20130110133304.ZIP
SSS_20130110133336.ZIP
I am running this in the task scheduler to run every night.
I want to keep from having too many zip files in the directory so I'd like to keep the last 30 zip files that exist.
I'm stuck at this point. How do I keep the most RECENT 30 zip files so that I don't end up with a crap load of zip files?