3
migration from moin 1.3 < patch-196 to moin 1.3 >= patch-196
4
Because of trouble with float timestamps, we migrate to usec timestamp resolution here.
5
* data/pages/PageName/backup/<UTC timestamp> -> .../<UTC timestamp in usecs>
6
* data/user/<uid>.bookmark -> convert to usecs
7
* data/edit-log and data/pages/PageName/edit-log -> convert to usecs
8
* data/event-log -> convert to usecs
10
Steps for a successful migration:
12
1. Stop your wiki and make a backup of old data and code
14
2. Make a copy of the wiki's "data" directory to your working dir
16
3. Run this script from your working dir
18
4. If there was no error, you will find:
19
data.pre-mig4 - the script renames your data directory copy to that name
20
data - converted data dir
22
5. Verify conversion results (number of pages, size of logs, attachments,
23
number of backup copies) - everything should be reasonable before
26
6. Copy additional files from data.pre-mig4 to data (maybe intermaps, logs,
27
etc.). Be aware that the file contents AND file names of wiki content
28
may have changed, so DO NOT copy the files inside the cache/ directory,
29
let the wiki refill it.
31
7. Replace the data directory your wiki uses with the data directory
32
you created by previous steps. DO NOT simply copy the converted stuff
33
into the original or you will duplicate pages and create chaos!
35
8. Test it - if something has gone wrong, you still have your backup.
38
@copyright: 2004 Thomas Waldmann
39
@license: GPL, see COPYING for details
43
import os.path, sys, urllib
45
sys.path.insert(0, '../../../..')
46
from MoinMoin import wikiutil
48
from MoinMoin.script.migration.migutil import opj, listdir, copy_file, copy_dir
50
def convert_ts(ts_from):
51
if ts_from > 5000000000: # far more than 32bits?
52
ts_to = ts_from # we already have usec kind of timestamp
54
ts_to = wikiutil.timestamp2version(ts_from)
55
return long(ts_to) # must be long for py 2.2.x
57
def convert_eventlog(file_from, file_to):
58
if not os.path.exists(file_from):
60
f = open(file_to, 'a')
61
for l in open(file_from):
65
data[0] = str(convert_ts(float(data[0]))) # we want usecs
66
data = '\t'.join(data)
70
def convert_editlog(file_from, file_to):
71
if not os.path.exists(file_from):
73
f = open(file_to, 'a')
74
for l in open(file_from):
78
data[2] = str(convert_ts(float(timestamp))) # we want usecs
79
data = '\t'.join(data)
83
def convert_pagedir(dir_from, dir_to, is_backupdir=0):
85
for pagedir in listdir(dir_from):
86
text_from = opj(dir_from, pagedir, 'text')
87
text_to = opj(dir_to, pagedir, 'text')
88
os.mkdir(opj(dir_to, pagedir))
89
copy_file(text_from, text_to)
91
backupdir_from = opj(dir_from, pagedir, 'backup')
92
backupdir_to = opj(dir_to, pagedir, 'backup')
93
if os.path.exists(backupdir_from):
94
os.mkdir(backupdir_to)
95
for ts in listdir(backupdir_from):
96
ts_usec = str(convert_ts(float(ts)))
97
backup_from = opj(backupdir_from, ts)
98
backup_to = opj(backupdir_to, ts_usec)
99
copy_file(backup_from, backup_to)
101
editlog_from = opj(dir_from, pagedir, 'edit-log')
102
editlog_to = opj(dir_to, pagedir, 'edit-log')
103
convert_editlog(editlog_from, editlog_to)
105
#cachedir_from = opj(dir_from, pagedir, 'cache')
106
#cachedir_to = opj(dir_to, pagedir, 'cache')
107
#if os.path.exists(cachedir_from):
108
# os.mkdir(cachedir_to)
111
# opj(cachedir_from, 'hitcounts'),
112
# opj(cachedir_to, 'hitcounts'))
115
attachdir_from = opj(dir_from, pagedir, 'attachments')
116
attachdir_to = opj(dir_to, pagedir, 'attachments')
117
if os.path.exists(attachdir_from):
119
copy_dir(attachdir_from, attachdir_to)
123
def convert_userdir(dir_from, dir_to):
125
for fname in listdir(dir_from):
126
if fname.endswith('.bookmark'):
127
bm = open(opj(dir_from, fname)).read().strip()
128
bm = str(wikiutil.timestamp2version(float(bm)))
129
f = open(opj(dir_to, fname), 'w')
133
copy_file(opj(dir_from, fname), opj(dir_to, fname))
136
origdir = 'data.pre-mig4'
138
# Backup original dir and create new empty dir
140
os.rename('data', origdir)
143
print "You need to be in the directory where your copy of the 'data' directory is located."
146
convert_pagedir(opj(origdir, 'pages'), opj('data', 'pages'))
148
convert_editlog(opj(origdir, 'edit-log'), opj('data', 'edit-log'))
150
convert_eventlog(opj(origdir, 'event.log'), opj('data', 'event-log'))
152
convert_userdir(opj(origdir, 'user'), opj('data', 'user'))
154
copy_dir(opj(origdir, 'plugin'), opj('data', 'plugin'))
156
copy_file(opj(origdir, 'intermap.txt'), opj('data', 'intermap.txt'))