Table of Contents

Maintenance

Here are some tips to automate some of the day-to-day maintenance needed or recommended for DokuWiki.

Keep Blacklist up to date

See blacklist on how to set up a cronjob to keep the Anti-Spam Blacklist current.

Automatic cleanup script

It is recommended to set up some cleanup process for busy DokuWikis. The following Bash (Unix shell) shell script serves as an example. It deletes old revisions from the attic, removes stale lock files and empty directories, and it cleans up the cache1).

cleanup.sh
#!/bin/bash
 
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 (old revisions)
  find "$1"/attic/ -type f -mtime +$2 -print0 | xargs -0r rm -f
 
  # remove stale lock files (files which are 1-2 days old)
  find "$1"/locks/ -name '*.lock' -type f -mtime +1 -print0 | xargs -0r rm -f
 
  # remove empty directories
  find "$1"/{attic,cache,index,locks,media,meta,pages,tmp}/ \
    -mindepth 1 -type d -empty -print0 | xargs -0r rmdir
 
  # remove files older than $2 days from the cache
  find "$1"/cache/?/ -type f -mtime +$2 -print0 | xargs -0r rm -f
}
 
# cleanup DokuWiki installations (path to datadir, number of days)
# some examples:
 
cleanup /home/user1/htdocs/doku/data    256
cleanup /home/user2/htdocs/mywiki/data  180
cleanup /var/www/superwiki/data         180

To run it automatically, set up a cronjob. The following example calls the script every day 7 minutes after midnight. To run as non-root user remove root.

7 0 * * *   root  /full/path/to/cleanup.sh

Be sure to set everything up correctly - you don't want to delete the wrong things, do you?

Windows -- warmzip

A script for cleaning out old files on Windows systems is waRmZip, available from here on SourceForge. Write a batch file to call it, and schedule it to run every day. And as the man says: 'Be sure to set everything up correctly' ;-)

I took the above suggestion to use waRmZip and wrote this batch file - maybe it will help out.

My favorite way to run cron jobs on Windows is PyCron.

dw-cleanup.bat
@echo off
set waRmZip="c:\Program Files\waRmZip\waRmZip.wsf"
set wikiHome="c:\path\to\htdocs\wiki\data"

rem Move attic files older than 30 days to an archive location
%waRmZip% %wikiHome%\attic /ma:30 /md:%wikiHome%_archive\attic /r /q

rem Option: delete attic files older than 30 days
rem %waRmZip% %wikiHome%\attic /da:30 /dc /r /q

rem Delete empty attic directories; waRmZip requires the /da flag when using
rem /df, so add filter for *.zzz so /da doesn't remove any files
%waRmZip% %wikiHome%\attic /r /da:31 /df /fo:*.zzz /q

rem Remove stale lock files
%waRmZip% %wikiHome%\locks /da:1 /fo:*.lock /r /q

rem Remove empty directories
%waRmZip% %wikiHome%\pages /da:365 /df /fo:*.zzz /r /q

Keeping Playground Clean

To keep the wiki's Playground and other pages clean, use a cron job e.g. every 30 minutes, that restores Playground and other pages to their original content.

Example: Restore Playground every 30 min:

0,30 * * * * cp -pf /path/to/savedwiki/data/pages/playground/playground.txt /path/to/dokuwiki/data/pages/playground/

Example: Restore all pages in namespace “wiki” every 30 min:

0,30 * * * * cp -rpf /path/to/savedwiki/data/pages/wiki/ /path/to/dokuwiki/data/pages/wiki/

When cronjob is not available

When your hosting doesn't allow to use cronjobs, consider using the cronojob plugin instead.

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't it be safer to use the timestamp in the filename to determine if a file in the attic should be deleted or not?

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 cache maintenance to the Windows waRmZip script?

1) For a discussion of cache maintenance see also the forum discussion.