Import an existing Redmine installation in Capistrano

In my previous article I explained how to install and upgrade Redmine using Capistrano, in this post I want to explain how to import your existing installation using the same method. Once again this is an experimental procedure, so make a backup before doing anything.

In order to import an existing installation of Redmine you’ll need both local (your development machine) and remote steps (on your production server). First of all you need to checkout my Redmine fork on your local machine using this command:

git checkout git://github.com/fabn/redmine.git

After that you need to define at least your production configuration, this goes into config/deploy/production.rb file. This could be its content


# roles definition
role :web, "your.redmine.org"
role :app, "your.redmine.org"
role :db, "your.redmine.org", :primary => true

# used on redmine install to load default data when installing
#set :load_default_data, false # default: true

# Customize here your start, stop and restart tasks if you need
# To use them you MUST deploy using explicit environment i.e. cap production redmine:upgrade
#namespace :deploy do
#  task :stop do
#    logger.important "Overridden"
#  end
#end

After that, from the local machine run

cap deploy:setup

this will prepare the folder structure on the server (under /var/rails/redmine folder, if you want to edit that override the :deploy_to variable for capistrano in the same file)

After the setup ssh into the remote machine and run the following commands, adjust paths to fit your needs

export OLD_REDMINE=/where/you/have/it
export NEW_REDMINE=/what/you/ve/set/in/production.rb
# The file configuration.yml exists only in RM >= 1.2
cp -a ${OLD_REDMINE}/config/{database,email,configuration}.yml ${NEW_REDMINE}/shared/config
rmdir ${NEW_REDMINE}/shared/files && cp -a ${OLD_REDMINE}/files ${NEW_REDMINE}/shared/

Then you should copy your themes and plugins in your new structure, you can use the following commands, but then need to remove all the stuff provided in Redmine itself. This is true especially for plugins since your installed plugins are in the same folder of the distribution plugins. If you won’t Capistrano will fail on deploy with a "ln: file exist" error.

cp -a ${OLD_REDMINE}/public/themes/* ${NEW_REDMINE}/shared/themes
cp -a ${OLD_REDMINE}/vendor/plugins/* ${NEW_REDMINE}/shared/plugins

Alternatively you can pick only folders you’ve manually installed into themes and plugins folders and put it in the destination folders (under shared/plugins and shared/themes).

Then, from the local machine, deploy the current version with

GIT_TAG=<your-current-version> cap production redmine:upgrade

This will deploy the code for the given tag, symlink all the imported data and then it migrate the db. Since you’re not doing a real upgrade no migration should be ran.

Final Notes

To ensure you can run all the above command you can try them with a staging configuration before doing the actual import to ensure that you meet the requirements. To do that follow these steps

Create a config/deploy/staging.rb file locally, with the following content:

# deploy to a different path
set :deploy_to, "/another/redmine/path"
# roles definition
role :web, "your.redmine.org"
role :app, "your.redmine.org"
role :db, "your.redmine.org", :primary => true

# used on redmine install to load default data when installing
set :load_default_data, true

Edit local configuration example files (especially config/database.yml.example and put it a sqlite database to avoid mess with production database)

cap staging deploy:setup
GIT_TAG=<your-current-version> cap staging redmine:install

If everything runs fine login on the remote machine and start the staging installation with

cd <your staging path> && rails server

point your browser to http://your-server:3000 to see if everything works.

Fix any issue in this staging environment before doing the above procedure, if staging configuration works then the above should work either.

You can leave a response, or trackback from your own site.
Subscribe to RSS Feed