Redmine migration from package to source install Ubuntu 20.04

You have a package (deb or rpm) installed redmine version and you want to switch to the source maintained redmine?
This article describes how to transfer your Redmine instance based on PostgreSQL to Ubuntu 20.04 instance.

You ask why we decided to switch to source based if the Ubuntu / Debian maintained redmine is available? Why to have the drawback to manage the updates yourself?
The answer is pretty simple. After using redmine since years with Ubuntu maintained installation, we have faced that the maintainers of the debian package are – sadly have to say – do a bad job. E.g. with Ubuntu 20.04 they have managed to use a ruby version which was not released by redmine team at all. So it created a mess with the debian package installation if you have tons of issues already. If you consider the fact that this issue is still not fixed, even if it was reported in the first weeks of the release of Ubuntu 20.04 and we have now march 2022!
You can imagine a some rate of frustration and also the drawback to wait for 2 years for a newer redmine version.

Create backups from old server

We may have these 4 data areas to backup:

  • database
  • redmine attached files and docs
  • redmine plugins
  • redmine themes

Backup database

First we need to dump the database from old server

sudo su - postgres -c 'psql -c "select datname from pg_database;"' | grep redmine

This will report you the database name. Iif you do not get an result run

sudo su - postgres -c 'psql -c "select * from pg_database;"'

For paranoid checks, let us verify the database name from the config too, by checking the database.yml
Under Ubuntu or Debian based installations the redmine configuration are located underneath /etc/redmine

cat /etc/redmine/default/database.yml | grep database

In my case the default database name is: redmine_default
Now let us dump the database into a file

sudo su - postgres -c 'pg_dump -C redmine_default | gzip > /tmp/redminedb.sql.gz'

copy to new server

scp /tmp/redminedb.sql.gz user@newserverhostname:/tmp/

Backup attachment files and docs

First identify where the files are located with

grep attachments_storage_path /etc/redmine/default/configuration.yml | grep -v "^\s*#"

In my case it was reporting:

attachments_storage_path: /var/lib/redmine/default/files

Now let us create the backup file

cd /var/lib/redmine/default/files
tar zcf /tmp/redmine-attachments.tar.gz .

copy to new server

scp /tmp/redmine-attachments.tar.gz user@newserverhostname:/tmp/

Backup installed plugins

You will need your plugins again. Best way is to backup and restore them. Backup the files

cd /usr/share/redmine/plugins/
tar zcf /tmp/redmine-plugins.tar.gz .

copy to new server

scp /tmp/redmine-plugins.tar.gz user@newserverhostname:/tmp/

Backup installed themes

You will need your themes again. Best way is to backup and restore them. Backup the files

cd /usr/share/redmine/public/themes
tar zcf /tmp/redmine-themes.tar.gz .

copy to new server

scp /tmp/redmine-plugins.tar.bz2 user@newserverhostname:/tmp/

Prepare your new Ubuntu 20.04 target server

login to your new server

ssh user@newserverhostname

You will need this packages to have apache2 and ruby passanger installed

sudo apt update
sudo apt dist-upgrade -y
sudo apt autoremove -y
sudo apt install -y apg build-essential libmysqlclient-dev libmysqlclient-dev imagemagick libmagickwand-dev libmagickcore-dev
sudo apt install -y dirmngr gnupg apt-transport-https ca-certificates apache2 apache2-dev libapache2-mod-passenger
sudo apt install -y ruby ruby-dev bundler
sudo apt install -y subversion git
sudo apt install -y postgresql postgresql-client postgresql-contrib postgresql-doc

Prepare DB – PostgreSQL

Create the new database with the required permissions

DBPWD=`apg -M sNCL -n 1 -m 16` && echo -e "#"'!'"/bin/bash\n\nDBPWD=$DBPWD\nexport DBPWD\necho DBPWD=$DBPWD" > /tmp/
source /tmp/
echo "using password $DBWPD"

Now take your generated password or your own password and enter it into the following command

sudo su - postgres -c "source /tmp/ && psql -c \"CREATE ROLE redmine LOGIN ENCRYPTED PASSWORD 'yourPassword' NOINHERIT VALID UNTIL 'infinity';\""
sudo su - postgres -c "zcat /tmp/redminedb.sql.gz | psql --set ON_ERROR_STOP=on"

now let us import the data into our new database

sudo su - postgres -c "psql -c \"CREATE DATABASE redmine WITH ENCODING='UTF8' OWNER=redmine;\""

Fetch the redmine sources. Now you have to decide to which version to work with. In the case of this tutorial the migration happend specifically from Ubuntu 20.04 with redmine debian package, which is 4.0.6 version. So the migration will happen first to the same source version or course.

sudo su -
cd /opt/
git clone
cd redmine
git checkout 4.0.6

configure the database

mkdir -p /etc/redmine/default
cp /opt/redmine/config/database.yml.example /etc/redmine/default/database.yml
ln -s /etc/redmine/default/database.yml /opt/redmine/config/database.yml
cp /opt/redmine/config/configuration.yml.example /etc/redmine/default/configuration.yml
ln -s /etc/redmine/default/configuration.yml /opt/redmine/config/configuration.yml

PostgreSQL configuration

Now configure the database config file with the relevant settings with

nano /etc/redmine/default/database.yml

change your configuration to this

adapter: postgresql
database: redmine
host: localhost
username: redmine
password: "yourPassword"
encoding: utf8

Mail / SMTP configuration

Now configure the redmine config file with the relevant settings with

nano /etc/redmine/default/configuration.yml

Attachment files and folders configuration

Now configure the attachment folder

mkdir -p /var/lib/redmine/default/files
cd /var/lib/redmine/default/files
tar zxf /tmp/redmine-attachments.tar.gz

Prepare for apache setup

sudo chown -R www-data:www-data /opt/redmine/
sudo chmod -R 755 /opt/redmine/
sudo ln -s /usr/share/redmine/public /var/www/redmine

Prepare ruby

gem install bundler
bundle install --without development test