remove_old_logs.bat #1

  • //
  • guest/
  • perforce_software/
  • sdp/
  • main/
  • Server/
  • Windows/
  • p4/
  • common/
  • bin/
  • remove_old_logs.bat
  • View
  • Commits
  • Open Download .zip Download (4 KB)
::-----------------------------------------------------------------------------
:: Copyright (c) Perforce Software, Inc., 2007-2014. All rights reserved
::
:: Redistribution and use in source and binary forms, with or without
:: modification, are permitted provided that the following conditions are met:
::
:: 1  Redistributions of source code must retain the above copyright
::    notice, this list of conditions and the following disclaimer.
::
:: 2.  Redistributions in binary form must reproduce the above copyright
::     notice, this list of conditions and the following disclaimer in the
::     documentation and/or other materials provided with the distribution.
::
:: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
:: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
:: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
:: FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE
:: SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
:: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
:: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
:: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
:: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
:: TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
:: THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
:: DAMAGE.
::-----------------------------------------------------------------------------

@echo off

set CkpNum=%1
set JnlNum=%2
set KeepCkpsNum=%3
set KeepLogsNum=%4
set ORIG_DIR=%CD%

set /A OldJnlNum="JnlNum - KeepLogsNum"
set /A OldCkpNum="CkpNum - KeepCkpsNum"

if %KeepLogsNum%x == x (
   echo Usage Error: remove_old_logs.bat CkpNum JnlNum KeepCkps KeepLogs
   exit /b 1
)

if %CkpNum%x == x (
   echo Warning: CkpNum not defined.  No old logs deleted.
   exit /b 1
)

if %JnlNum%x == x (
   echo Warning: JnlNum not defined.  No old logs deleted.
   exit /b 1
)

if %KeepCkpsNum%x == x (
   echo Warning: KeepCkpsNum not defined.  No old logs deleted.
   exit /b 1
)

if %KeepLogsNum%x == x (
   echo Warning: KeepLogsNum not defined.  No old logs deleted.
   exit /b 1
)

if %LOGS_DIR%x == x (
   echo Warning: LOGS not defined.  No old logs deleted.
   exit /b 1
)

if %OldJnlNum%x == x (
   echo Warning: OldJnlNum could not be calculated.  No old logs deleted.
   exit /b 1
)

if %OldCkpNum%x == x (
   echo Warning: OldCkpNum could not be calculated.  No old logs deleted.
   exit /b 1
)

:ROTATE_ACTIVE_SERVER_LOG

cd /D "%LOGS_DIR%"

IF EXIST log (
   echo Rotating active server log to log.%JnlNum%.
   echo .
   ren log log.%JnlNum%
) ELSE (
   echo Warning:  Server log file 'log' not found.
   echo .
)

:CLEAN_SERVER_LOGS

if %KeepLogsNum% == 0 (
   echo Skipping cleanup of old server logs because KEEPLOGS is set to 0.
   echo .
   goto CLEAN_CHECKPOINT_LOGS
)

echo Removing old server logs.
echo Keeping latest %KeepLogsNum%, per KEEPLOGS setting in sdp_config.ini.
if exist log.%JnlNum% (
   echo Latest server log number is log.%JnlNum%.
)
echo .

if %OldJnlNum% LSS 8 (
   echo No old server logs need to be deleted.
   echo .
   goto CLEAN_CHECKPOINT_LOGS
) ELSE (
   echo Deleting existing server logs numbered 8-%OldJnlNum%.  Delete 1-7 manually.
   echo .
)

for /L %%C in (%OldJnlNum%, -1, 8) do (
   if exist log.%%C (
      echo DEL /F /Q log.%%C
      DEL /F /Q log.%%C
   )
)

:CLEAN_CHECKPOINT_LOGS

if %KeepCkpsNum% == 0 (
   echo Skipping cleanup of old checkpoint logs because KEEPCKPS is set to 0.
   echo .
   goto END
)

echo Removing old checkpoint logs.
echo Keeping latest %KeepCkpsNum%, per KEEPCKPS setting in sdp_config.ini.

if %OldCkpNum% LSS 8 (
   echo No old checkpoint logs need to be deleted.
   echo .
   goto END
) ELSE (
   echo Deleting existing checkpoint logs numbered 8-%OldCkpNum%.  Delete 1-7 manually.
   echo .
)

for /L %%D in (%OldCkpNum%, -1, 8) do (
   if exist checkpoint.log.%%D (
      echo DEL /F /Q checkpoint.log.%%D
      DEL /F /Q checkpoint.log.%%D 
   )
)

:END

echo Log cleanup processing complete.
echo .

cd /d "%ORIG_DIR%"

exit /b 0
# Change User Description Committed
#4 20767 C. Thomas Tyler Released SDP 2016.2.20755 (2016/09/29).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#3 15856 C. Thomas Tyler Replaced the big license comment block with a shortened
form referencing the LICENSE file included with the SDP
package, and also by the URL for the license file in
The Workshop.
#2 15694 Robert Cowham Fixed problem where log file was not being rotated.
#1 10872 C. Thomas Tyler Added Windows SDP into The Workshop:
* Combined (back) into Unix SDP structure.
* Avoided adding duplicate files p4verify.pl, p4review.(py,cfg).
* Upgraded 'dist.sh' utility to produce both Unix and Windows
packages (*.tgz and *.zip), adjusting line endings on text
files to be appropriate for Windows prior to packaging.

To Do:
* Resolve duplication of [template_]configure_new_server.bat.
* Merge test suites for Windows and Unix into a cohesive set.