Project

General

Profile

Export project(s) - NOT FOR THE FAINT OF HEART!

Added by Felix Schäfer over 13 years ago

DISCLAIMER: This is a f*ugly hack at best, it might break stuff, make your redmine unusable or kill your aunt's chihuahua, USE AT YOUR OWN RISKS! I am not responsible in any way of what you do with the following script, nor will I provide support of any kind if something bad happens.

I have users of my redmine leaving for a few days to a somewhat not-internet-covered area, but they wanted to take the redmine projects they use with them. I have hacked together this script to make an offline export of a project and its subprojects, each project is in its own directory and contains subdirectories for:

  • all issues as PDF files,
  • the (raw) wikipages as text files,
  • all files attached to the project,
  • an export of the repository.

This script works for us but will probably need some tweaking to work in your environment, make sure you understand everything that happens before you use it.

require 'ftools'
include Redmine::Export::PDF
include Redmine::I18n
include IssuesHelper
def self.current_language; "en"; end
def self.controller; "dummy"; end
def self.request; "dummy"; end

Project.find("identifier").self_and_descendants.each do |project|
  paths = %w(issues wiki files).collect {|p| "exports/#{project.identifier}/#{p}"}
  File.makedirs *paths
  project.issues.each do |issue|
    filename = "#{format("%04d", issue.id)} -- #{issue.category.name if issue.category} -- #{issue.subject}.pdf".gsub(/\//, '_')
    File.open("exports/#{project.identifier}/issues/#{filename}", 'w') {|f| f.write(issue_to_pdf(issue)) }
  end
  project.wiki.pages.each do |page|
    filename = "#{page.ancestors.reverse.collect {|parent| "#{parent.title}-"}.join}#{page.title}.txt" 
    File.open("exports/#{project.identifier}/wiki/#{filename}", 'w') {|f| f.write(page.content.text) }
  end
  project.attachments.each do |attachment|
    File.copy("files/#{attachment.disk_filename}", "exports/#{project.identifier}/files/#{attachment.filename}")
  end
  system "svn export #{project.repository.url} exports/#{project.identifier}/repository" if project.repository
end

Replies (2)

RE: Export project(s) - NOT FOR THE FAINT OF HEART! - Added by Muntek Singh over 13 years ago

I got this script to work with some minor tweaks, I had to keep ruby docs open for most of it, but it works. I thought I would be able to get it to do what I wanted for one of my many minor to-do list items, but alas no. At least I have something that works though!

Thanks Felix!

RE: Export project(s) - NOT FOR THE FAINT OF HEART! - Added by Felix Schäfer over 13 years ago

Muntek Singh wrote:

I got this script to work with some minor tweaks

Just noticed I had patched a little mishap in the pdf export thingie that makes the above script break. I'll submit a patch for it.

I had to keep ruby docs open for most of it, but it works. I thought I would be able to get it to do what I wanted for one of my many minor to-do list items, but alas no. At least I have something that works though!

Thanks Felix!

You're welcome :-)

    (1-2/2)