Debian 10: Migrate Redmine + PostgreSQL from Debian 8 to Debian 10

This article will describe how to migrate Redmine + PostgreSQL from Debian 8 to Debian 10.

1 Create backup of Redmine + PostgreSQL on Debian 8

Dump redmine_default table in PostgreSQL.

$ sudo -u postgres pg_dump redmine_default > /tmp/redmine_default.pgsql

Create backup of /var/lib/redmine where files of Redmine are placed.

$ cd /var/lib
$ sudo tar czfp /tmp/redmine.tgz redmine

This article transfers these files to /tmp on Debian 10.

2 Install Redmine + PostgreSQL on Debian 10

The redmine package is in buster-backports repository on Debian 10. And ruby-xxx packages in buster-backports are needed by Redmine.

#!/bin/sh -e

# Database passwd for redmine_default table.
[ -z "${REDMINE_PASSWD}" ] && REDMINE_PASSWD=redmine

pgsql_install()
{
    sudo apt install -y postgresql
}

redmine_install()
{
    # Enable buster-backports repository.
    echo "deb http://deb.debian.org/debian buster-backports main" | \
        sudo tee /etc/apt/sources.list.d/backports.list
    sudo apt update -y

    cat <<EOF | sudo debconf-set-selections
redmine redmine/instances/default/dbconfig-install boolean true
redmine redmine/instances/default/database-type select pgsql
redmine redmine/instances/default/remote/host select localhost
redmine redmine/instances/default/pgsql/app-pass password ${REDMINE_PASSWD}
redmine redmine/instances/default/pgsql/admin-pass password
redmine redmine/instances/default/password-confirm password
redmine redmine/instances/default/app-password-confirm password ${REDMINE_PASSWD}
EOF

    # The redmine/buster-backports needs ruby-xxx package in buster-backports
    # repository.
    sudo apt install -y redmine/buster-backports redmine-pgsql/buster-backports \
         ruby-rouge/buster-backports
}

apache_install()
{
    sudo apt install -y apache2 libapache2-mod-passenger bundler

    # Overwrite passenger.conf.
    cat << EOF | sudo tee /etc/apache2/mods-available/passenger.conf
<IfModule mod_passenger.c>
    PassengerRoot /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini
    PassengerDefaultRuby /usr/bin/ruby
    PassengerDefaultUser www-data
    RailsBaseURI /redmine
</IfModule>
EOF

    cd /var/www/html
    sudo ln -s /usr/share/redmine/public redmine
    sudo chown -R www-data:www-data /usr/share/redmine
    cat << EOF | sudo tee /etc/apache2/sites-available/redmine.conf
<VirtualHost _default_:443>
    SSLEngine on
    SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
    SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

    <Directory /redmine>
        Options FollowSymLinks
        PassengerResolveSymlinksInDocumentRoot on
        AllowOverride None
    </Directory>
</VirtualHost>
EOF

    sudo a2enmod passenger
    sudo a2enmod ssl
    sudo a2ensite redmine

    sudo systemctl enable apache2
    sudo systemctl restart apache2
}

redmine_main()
{
    pgsql_install
    redmine_install
    apache_install
}

redmine_main

3 Restore database and files on Debian 10

Stop Appache.

$ sudo systemctl stop apache2

Delete redmine_default table, which is created by Redmine installation, and create empty redmine_default table.

$ cat <<EOF | sudo -u postgres psql
DROP DATABASE redmine_default;
CREATE DATABASE redmine_default OWNER = "redmine/instances/default" \
TEMPLATE = template0 ENCODING = 'UTF8';
EOF

Change username, who can access redmine_default table, from redmine_default to "redmine/instances/default". Also you can change username in /etc/redmine/default/database.ymlのusername instead of backup. Restore redmine_default table by backup of Debian 8's PostgreSQL.

$ sed -e 's;redmine_default;"redmine/instances/default";g' \
-i redmine_default.pgsql
$ sudo -u postgres psql redmine_default < /tmp/redmine_default.pgsql

Run database migration.

$ wget https://www.redmine.org/projects/redmine/repository/raw/tags/3.4.2/db/migrate/20170309214320_add_project_default_assigned_to_id.rb
$ sudo mv 20170309214320_add_project_default_assigned_to_id.rb \
/usr/share/redmine/db/migrate/
$ cd /usr/share/redmine/
$ sudo bundle exec rake db:migrate RAILS_ENV=production

Extract /var/lib/redmine. If Gemfile.lock is exists, delete it.

$ cd /var/lib
$ sudo tar zxf /tmp/redmine.tgz
$ sudo rm -f /var/lib/redmine/Gemfile.lock

Run Apache. Now Redmine is running on Debian 10.

$ sudo systemctl start apache2