tips:maintenance
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tips:maintenance [2009-12-14 14:26] – updated snippets (lockdir) kazmiya | tips:maintenance [2020-01-29 02:40] – corrected bash function syntax. this was an invalid mix of the two possible bash function formats. benks | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Maintenance ====== | ====== Maintenance ====== | ||
+ | |||
+ | Here are some tips to automate some of the day-to-day maintenance needed or recommended for DokuWiki. | ||
- | Here are some tips to automate some of the day-to-day maintenance needed for DokuWiki. | + | See also the plugins: [[plugin: |
===== Keep Blacklist up to date ===== | ===== Keep Blacklist up to date ===== | ||
Line 9: | Line 11: | ||
===== Automatic cleanup script ===== | ===== Automatic cleanup script ===== | ||
- | It is recommended to set up some cleanup process for busy DokuWikis. The following script | + | It is recommended to set up some cleanup process for busy DokuWikis. The following |
- | <code bash> | + | <file bash cleanup.sh> |
- | #!/bin/sh | + | #!/bin/bash |
- | # set the path to your DokuWiki installation here | + | cleanup() |
- | DOKUWIKI=/path/to/your/wiki | + | { |
+ | local data_path=" | ||
+ | local retention_days=" | ||
- | # purge files older than 30 days from the attic | + | |
- | find $DOKUWIKI/ | + | find "${data_path}" |
- | # remove stale lock files | + | |
- | find $DOKUWIKI/ | + | find "${data_path}" |
- | # remove empty directories | + | |
- | find $DOKUWIKI/ | + | find "${data_path}" |
- | </ | + | |
- | To run it automatically, | + | # remove files older than ${retention_days} days from the cache |
+ | if [ -e " | ||
+ | then | ||
+ | find " | ||
+ | fi | ||
+ | } | ||
- | 5 0 * * * / | + | # cleanup DokuWiki installations (path to datadir, number of days) |
+ | # some examples: | ||
- | Be sure to set everything up correctly - you don't want to delete the wrong things, do you? | + | cleanup / |
+ | cleanup / | ||
+ | cleanup / | ||
+ | </ | ||
- | ==== Script for multiple installations ==== | + | To run it automatically, |
- | The following shell script is more handy for multiple installations of DokuWiki. It also shows how to use [[man> | + | 7 0 * * * |
- | <code bash> | + | Be sure to set everything up correctly |
- | #!/bin/sh | + | |
- | + | ||
- | cleanup() { | + | |
- | + | ||
- | # $1 ... full path to data directory of wiki | + | |
- | # $2 ... number of days after which old files are to be removed | + | |
- | + | ||
- | # purge files older than $2 days from the attic | + | |
- | find " | + | |
- | + | ||
- | # remove stale lock files (if older than 2 days) | + | |
- | find " | + | |
- | + | ||
- | # remove empty directories | + | |
- | find " | + | |
- | } | + | |
- | + | ||
- | # cleanup my wiki installations (path to datadir, number of days) | + | |
- | # some examples: | + | |
- | + | ||
- | cleanup / | + | |
- | cleanup / | + | |
- | cleanup / | + | |
- | </ | + | |
==== Windows -- warmzip ==== | ==== Windows -- warmzip ==== | ||
- | A script for cleaning out old files on Windows systems is [[http:// | + | A script for cleaning out old files on Windows systems is [[http:// |
I took the above suggestion to use '' | I took the above suggestion to use '' | ||
- | My favorite way to run cron jobs on Windows is [[http://www.kalab.com/freeware/pycron/pycron.htm|PyCron]]. | + | My favorite way to run cron jobs on Windows is [[https://sourceforge.net/projects/ |
- | <code dos> | + | <file dos dw-cleanup.bat> |
@echo off | @echo off | ||
set waRmZip=" | set waRmZip=" | ||
Line 91: | Line 80: | ||
rem Remove empty directories | rem Remove empty directories | ||
%waRmZip% %wikiHome%\pages /da:365 /df /fo:*.zzz /r /q | %waRmZip% %wikiHome%\pages /da:365 /df /fo:*.zzz /r /q | ||
- | </code> | + | </file> |
+ | |||
+ | ==== Windows -- batch script ==== | ||
+ | |||
+ | This is another Windows command shell script for maintaining your dokuwiki base on a Windows environment. | ||
+ | The script uses the free and open source utility find, which can be obtained via [[http:// | ||
+ | |||
+ | All paths are read from the DokuWiki config file. Files to be deleted can be shown before deletion, to prevent accidental deletion of files. | ||
+ | |||
+ | <file dos maintain_dokuwiki.cmd> | ||
+ | @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: | ||
+ | set NAME=maintain_dokuwiki | ||
+ | set VERSION=0.13 | ||
+ | |||
+ | REM path to the dokuwiki configuration file enclosed in double quotes | ||
+ | set DOKUWIKICONFIG=" | ||
+ | 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: | ||
+ | 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 " | ||
+ | if /i " | ||
+ | if /i " | ||
+ | if /i " | ||
+ | if /i " | ||
+ | ) | ||
+ | if " | ||
+ | echo sorry, could not find datadir variable in %DOKUWIKICONFIG%, | ||
+ | exit /b | ||
+ | ) | ||
+ | |||
+ | REM use defaults if the paths are not specified | ||
+ | if /i " | ||
+ | if /i " | ||
+ | if /i " | ||
+ | |||
+ | REM purge files older than DAYSTOKEEP days from the attic | ||
+ | %FIND% " | ||
+ | REM remove locks older than one day | ||
+ | %FIND% " | ||
+ | REM remove cache files older than DAYSTOKEEP | ||
+ | %FIND% " | ||
+ | |||
+ | REM show results, if any | ||
+ | for /f " | ||
+ | if /i " | ||
+ | echo files to be deleted: | ||
+ | type %TEMPFILE% | ||
+ | pause | ||
+ | ) | ||
+ | for /f " | ||
+ | ) | ||
+ | |||
+ | REM clean up | ||
+ | del /f /q %TEMPFILE% | ||
+ | |||
+ | endlocal | ||
+ | </file> | ||
===== Keeping Playground Clean ===== | ===== Keeping Playground Clean ===== | ||
- | To keep the wiki's Playground and other pages clean, use a cron job every 30 min, that restores Playground and other pages to their original content. | + | To keep the wiki' |
- | Example: Restore | + | Example: Restore Playground every 30 min: |
- | 0,30 * * * * cp -rpf / | + | 0,30 * * * * cp -pf / |
Example: Restore all pages in [[: | Example: Restore all pages in [[: | ||
Line 105: | Line 193: | ||
0,30 * * * * cp -rpf / | 0,30 * * * * cp -rpf / | ||
+ | ==== Problems with CAPTCHA plugin ==== | ||
+ | |||
+ | Using the CAPTCHA plugin and the recommended [[tips: | ||
+ | |||
+ | When this occurs, the problem can be easily resolved by removing the related playground files in the meta folder with the next cronjob. | ||
+ | |||
+ | Example: Deletes Playground metafiles every 30 min: | ||
+ | 0,30 * * * * rm -f / | ||
+ | |||
+ | ===== When cronjob is not available ===== | ||
+ | |||
+ | When your hosting doesn' | ||
+ | |||
+ | ===== Discussion ===== | ||
+ | |||
+ | Could you please provide PHP versions of these scripts to use with the cronojob plugin? | ||
+ | ---- | ||
+ | |||
+ | > Regarding the above cleanup script which uses file modification time (mtime), wouldn' | ||
+ | |||
+ | On the one hand, I'd say it could be done but it's of course trickier to set up. For many installations it will be fine to use mtime. On the other hand, some might want to make sure they clean up old files no matter what (e.g. files left after a crash or critical PHP error). | ||
+ | ---- | ||
+ | |||
+ | Could someone add the appropriate line for [[https:// | ||
+ | ---- | ||
+ | Does the [[plugin: | ||
+ | |||
+ | ---- | ||
+ | This is example of php script to clean old cache files. useful when .sh is not available to run. | ||
+ | |||
+ | <file php cleanup.php> | ||
+ | |||
+ | <? | ||
+ | /* | ||
+ | * mrlemonade ~ | ||
+ | | ||
+ | function getFilesFromDir($dir) { | ||
+ | $files = array(); | ||
+ | if ($handle = opendir($dir)) { | ||
+ | while (false !== ($file = readdir($handle))) { | ||
+ | if ($file != " | ||
+ | if(is_dir($dir.'/' | ||
+ | $dir2 = $dir.'/' | ||
+ | $files[] = getFilesFromDir($dir2); | ||
+ | } | ||
+ | else { | ||
+ | $files[] = $dir.'/' | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | closedir($handle); | ||
+ | } | ||
+ | return array_flat($files); | ||
+ | } | ||
+ | function array_flat($array) { | ||
+ | foreach($array as $a) { | ||
+ | if(is_array($a)) { | ||
+ | $tmp = array_merge($tmp, | ||
+ | } | ||
+ | else { | ||
+ | $tmp[] = $a; | ||
+ | } | ||
+ | } | ||
+ | return $tmp; | ||
+ | } | ||
+ | |||
+ | // Define the folder to clean | ||
+ | $captchaFolder = ' | ||
+ | // Here you can define after how many | ||
+ | // days the files should get deleted | ||
+ | $expire_time = 5; | ||
+ | // Find all files of the given file type | ||
+ | foreach (getFilesFromDir($captchaFolder) as $Filename) { | ||
+ | // Read file creation time | ||
+ | $FileCreationTime = filectime($Filename); | ||
+ | // Calculate file age in seconds | ||
+ | $FileAge = time() - $FileCreationTime; | ||
+ | // Is the file older than the given time span? | ||
+ | if ($FileAge > ($expire_time*60*60*24 )) { | ||
+ | // Now do something with the olders files... | ||
+ | print "The file $Filename is older than $expire_time days \n"; | ||
+ | // For example deleting files: | ||
+ | // unlink($Filename); | ||
+ | } | ||
+ | } | ||
+ | echo ' | ||
+ | ?> | ||
+ | |||
+ | </ | ||
+ | use this at your own risk. --- [[user> | ||
+ | |||
+ | ---- | ||
+ | Cheers, I'd like to add that it is a good idea to clean up orphaned meta data, don't you think? | ||
+ | I do the following (in an R script): | ||
+ | -list all files in the pages directory recursively | ||
+ | -add a column ' | ||
+ | -in pagename exchange '/' | ||
+ | -do the same for the meta directory + exclude some additional files | ||
+ | -remove all entries from the meta-list from which the page name is in the pages-list | ||
+ | -delete all files left in the meta list | ||
+ | Of course one could add a time constraint on it so that you don't use metadata immediately. | ||
+ | |||
+ | Clemo // | ||
tips/maintenance.txt · Last modified: 2023-10-10 20:28 by staze