@echo off setlocal REM This script performs some basic DokuWiki maintenance REM Copyright (C) 2012 Peter Mosmans REM This program is free software: you can redistribute it and/or modify REM it under the terms of the GNU General Public License as published by REM the Free Software Foundation, either version 3 of the License, or REM (at your option) any later version. REM This program is distributed in the hope that it will be useful, REM but WITHOUT ANY WARRANTY; without even the implied warranty of REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the REM GNU General Public License for more details. REM You should have received a copy of the GNU General Public License REM along with this program. If not, see . REM Please contact support AT go-forward.net for questions and/or feedback REM Last modification: 02-05-2012 (Peter Mosmans) set NAME=maintain_dokuwiki set VERSION=0.13 REM path to the dokuwiki configuration file enclosed in double quotes set DOKUWIKICONFIG="\full\filename\of\your\dokuwiki\conf\local.php" REM preserve all files that are younger than DAYSTOKEEP days set DAYSTOKEEP=31 REM set to true if you want to show results and pause before deleting any files set SHOWRESULTSFIRST=true set FIND=c:\tools\find.exe set TEMPFILE=%TMP%\%NAME%.tmp REM see if all tools are present for %%i in (%FIND%) do ( if not exist %%i ( echo sorry, could not find %%i - exiting echo you can obtain the free GNU tools from gnuwin32.sourceforge.net exit /b ) ) REM see if the dokuwiki configuration file can be read if not exist %DOKUWIKICONFIG% ( echo sorry, could not find DokuWiki config at %DOKUWIKICONFIG% - exiting exit /b ) REM grab the correct paths from the configuration file for /f "usebackq delims=' tokens=2,4" %%i in (%DOKUWIKICONFIG%) do ( if /i "%%i"=="datadir" set DOCUMENTROOT=%%j if /i "%%i"=="olddir" set ATTICDIR=%%j if /i "%%i"=="cachedir" set CACHEDIR=%%j if /i "%%i"=="lockdir" set LOCKDIR=%%j ) if "%DOCUMENTROOT%" == "" ( echo sorry, could not find datadir variable in %DOKUWIKICONFIG%, exiting... exit /b ) REM use defaults if the paths are not specified if /i "%ATTICDIR%" == "" set ATTICDIR=%DOCUMENTROOT%/attic if /i "%LOCKDIR%" == "" set LOCKDIR=%DOCUMENTROOT%/lock if /i "%CACHEDIR%" == "" set CACHEDIR=%DOCUMENTROOT%/cache REM purge files older than DAYSTOKEEP days from the attic %FIND% "%ATTICDIR%" -type f -mtime +%DAYSTOKEEP% -print > %TEMPFILE% REM remove locks older than one day %FIND% "%LOCKDIR%" -name "*.lock" -type f -mtime +1 -print >> %TEMPFILE% REM remove cache files older than DAYSTOKEEP %FIND% "%CACHEDIR%" -type f -mtime +%DAYSTOKEEP% -print >> %TEMPFILE% REM show results, if any for /f "usebackq" %%i in (`%FIND% "%TMP%" -size +1 -name %NAME%.tmp`) do ( if /i "%SHOWRESULTSFIRST%"=="TRUE" ( echo files to be deleted: type %TEMPFILE% pause ) for /f "delims=#" %%i in (%TEMPFILE%) do del "%%i" ) REM clean up del /f /q %TEMPFILE% endlocal