Ye olde converter script.
* Script now parses the madeleine storage into SQL * Added a new option, -o/--outfile to specify where the output from the script should go * ./import_storage -t /home/joe/instiki/storage/2500 \ -i /home/joe/instiki -o /home/joe/export.sql Exporting the instiki.org snapshot I have takes about 40 seconds (with output to screen) and generates an approximately 17 meg SQL script from the ~900k Madeleine snapshot. Oh well. Tested with MySQL.
This commit is contained in:
parent
0238780355
commit
7aaa35ae4a
1 changed files with 79 additions and 15 deletions
|
@ -20,7 +20,7 @@ ARGV.options do |opts|
|
||||||
"contains .snapshot files.") do |storage|
|
"contains .snapshot files.") do |storage|
|
||||||
OPTIONS[:storage] = storage
|
OPTIONS[:storage] = storage
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.separator ""
|
opts.separator ""
|
||||||
|
|
||||||
opts.on("-i", "--instiki /full/path/to/instiki", String,
|
opts.on("-i", "--instiki /full/path/to/instiki", String,
|
||||||
|
@ -31,15 +31,33 @@ ARGV.options do |opts|
|
||||||
|
|
||||||
opts.separator ""
|
opts.separator ""
|
||||||
|
|
||||||
|
opts.on("-o", "--outfile /full/path/to/output_file", String,
|
||||||
|
"Full path (including filename!) to where ",
|
||||||
|
"you want the SQL output placed, such as ",
|
||||||
|
"/home/joe/instiki.sql") do |outfile|
|
||||||
|
OPTIONS[:outfile] = outfile
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.separator ""
|
||||||
|
|
||||||
opts.on_tail("-h", "--help",
|
opts.on_tail("-h", "--help",
|
||||||
"Show this help message.") { puts opts; exit }
|
"Show this help message.") { puts opts; exit }
|
||||||
|
|
||||||
opts.parse!
|
opts.parse!
|
||||||
end
|
end
|
||||||
|
|
||||||
if OPTIONS[:instiki].nil? or OPTIONS[:storage].nil?
|
if OPTIONS[:instiki].nil? or OPTIONS[:storage].nil? or OPTIONS[:outfile].nil?
|
||||||
$stderr.puts "Please specify full paths to Instiki installation and storage"
|
$stderr.puts "Please specify full paths to Instiki installation and storage,"
|
||||||
$stderr.puts
|
$stderr.puts "as well as the path to the output file"
|
||||||
|
$stderr.puts
|
||||||
|
puts ARGV.options
|
||||||
|
exit -1
|
||||||
|
end
|
||||||
|
|
||||||
|
if FileTest.exists? OPTIONS[:outfile]
|
||||||
|
$stderr.puts "Output file #{OPTIONS[:outfile]} already exists!"
|
||||||
|
$stderr.puts "Please specify a new file"
|
||||||
|
$stderr.puts
|
||||||
puts ARGV.options
|
puts ARGV.options
|
||||||
exit -1
|
exit -1
|
||||||
end
|
end
|
||||||
|
@ -77,18 +95,64 @@ class Revision
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sql_insert(table, hash)
|
||||||
|
output = "INSERT INTO #{table} ("
|
||||||
|
output << hash.keys.join(", ")
|
||||||
|
|
||||||
|
output << ") VALUES ('"
|
||||||
|
output << hash.values.map{|v| v.to_s.gsub("'", "\\\\'")}.join("', '")
|
||||||
|
|
||||||
|
output << "');"
|
||||||
|
return output
|
||||||
|
end
|
||||||
|
|
||||||
WikiService.storage_path = OPTIONS[:storage]
|
WikiService.storage_path = OPTIONS[:storage]
|
||||||
wiki = WikiService.instance
|
wiki = WikiService.instance
|
||||||
|
|
||||||
wiki.webs.each_pair do |web_name, web|
|
File.open(OPTIONS[:outfile], 'w') { |outfile|
|
||||||
# INSERT INTO webs goes here
|
wiki.webs.each_pair do |web_name, web|
|
||||||
puts "Web #{web_name} has #{web.pages.keys.size} pages"
|
outfile.puts sql_insert(:webs, {
|
||||||
web.pages.each_pair do |page_name, page|
|
:id => web.object_id,
|
||||||
# INSERT INTO pages goes here
|
:name => web.name,
|
||||||
puts " Page #{page_name} has #{page.revisions.size} revisions"
|
:address => web.address,
|
||||||
page.revisions.each_with_index do |rev, i|
|
:password => web.password,
|
||||||
# INSERT INTO revisions goes here
|
:additional_style => web.additional_style,
|
||||||
puts " Revision #{i} created at #{rev.created_at}"
|
:allow_uploads => web.allow_uploads,
|
||||||
end
|
:published => web.published,
|
||||||
|
:count_pages => web.count_pages,
|
||||||
|
:markup => web.markup,
|
||||||
|
:color => web.color,
|
||||||
|
:max_upload_size => web.max_upload_size,
|
||||||
|
:safe_mode => web.safe_mode,
|
||||||
|
:brackets_only => web.brackets_only,
|
||||||
|
})
|
||||||
|
|
||||||
|
puts "Web #{web_name} has #{web.pages.keys.size} pages"
|
||||||
|
web.pages.each_pair do |page_name, page|
|
||||||
|
outfile.puts sql_insert(:pages, {
|
||||||
|
:id => page.object_id,
|
||||||
|
:web_id => web.object_id,
|
||||||
|
:locked_by => page.locked_by,
|
||||||
|
:name => page.name
|
||||||
|
})
|
||||||
|
|
||||||
|
puts " Page #{page_name} has #{page.revisions.size} revisions"
|
||||||
|
page.revisions.each_with_index do |rev, i|
|
||||||
|
outfile.puts sql_insert(:revisions, {
|
||||||
|
:id => rev.object_id,
|
||||||
|
:page_id => page.object_id,
|
||||||
|
:content => rev.content,
|
||||||
|
:author => rev.author,
|
||||||
|
:ip => '0.0.0.0',
|
||||||
|
})
|
||||||
|
puts " Revision #{i} created at #{rev.created_at}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
['webs', 'pages', 'revisions'].each do |table|
|
||||||
|
outfile.puts "UPDATE #{table} SET created_at = NOW();"
|
||||||
|
outfile.puts "UPDATE #{table} SET updated_at = NOW();"
|
||||||
|
end
|
||||||
|
outfile.puts "UPDATE revisions SET revised_at = NOW();"
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue