MoinMoin to text perl script

I had a wiki in MoinMoin for sys admin notes and scraps of code and solutions – all the stuff you accumulate to try and not have to solve the same problem over and over from scratch. Moin Moin was flat directory structure coded in python. It’s elegant – but the search function started blowing up for me once I got to a certain size. Even when working search through a text/directory structure was slow.

I backed up this structure with the following perl code – it takes the directory structure of MoinMoin, descends and translates it into text files and attachments within a directory. This worked great for backups – it was readable without MoinMoin if needed, and it could be reversed into a MoinMoin structure if needed. Being largely text, it compressed well.

Here’s the script:

 

#! /usr/bin/perl

 use strict;
 use Carp;
 use File::Copy;

 ## script to parse moinmoin wiki 1.3 file structure into a flat text file set.  For readability and  backup
 ## Structure:
 ## /space/Wikis/dsm/data/pages is the root directory
 ## each page is a named directory
 ## within that directory there is:
 ## lensman pages # ls -la RmanErrors/
 ## total 104
 ## drwxrwx---     4 dsm dsm  4096 Mar  8 17:09 .
 ## drwxr-x---  2348 dsm dsm 81920 Jul 24 14:18 ..
 ## drwxrwx---     2 dsm dsm  4096 Mar  8 16:58 cache
 ## -rw-rw----     1 dsm dsm     9 Mar  8 17:09 current
 ## -rw-rw----     1 dsm dsm   201 Mar  8 17:09 edit-log
 ## drwxrwx---     2 dsm dsm  4096 Mar  8 17:09 revisions
 ## cache is ignorable - that is for speedy display...
 ## what you need is to cat current into a variable
 ## chomp iot...
 ## then cat $ROOT//revisions/$variable into a text file...
 ## go into attachments file and copy those to - $RESULT_DIR/$copyname.txt`;
    # attachments if any
    if ( -d "$DIR/$file/attachments" ) {
        print ("Found ATTACHMENTS directory\n");
        opendir(ATT, "$DIR/$file/attachments") || croak "Failed to open $DIR/$file/attachments";
        my @files = grep { /^.*$/ } readdir(ATT);
        closedir(ATT);
        foreach my $attach (@files) {
            print ("attachment: $attach\n");
            unless (($attach eq ".") || ($attach eq "..")) {
                my $attach_start = "$DIR/$file/attachments/$attach";
                my $attach_endpoint = "$RESULT_DIR/$copyname-$attach";
                copy($attach_start, $attach_endpoint);
            }
        }
    }
 }
 closedir(DIR);

 `chown -R dsm.dsm $RESULT_DIR`;
 exit;

 

—doug