Upgrade and change DB

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
acidzfire
Posts: 7
Joined: 06 Jun 2008, 23:40

Upgrade and change DB

Post by acidzfire »

We are currently using Mantis 1.1.2. We will be soon(within a month) changing servers that mantis is located on and will take this time to upgrade mantis to 1.2.x . We are also wanting to change from using mysql to postgresql as mantis is now the only thing we have on mysql and are trying to be consistant. Has anyone done an upgrade in this fashion? Or what are some thoughts on this?
We are changing from:
Ubuntu -> RHEL
mysql -> postgresql
1.1.2 -> 1.2.x (1.2.0 rc1 or rc2...depends on if rc2 is out then)

Our plan is
  • build the new server with postgres
  • install latest Mantis release
  • migrate old Mantis DB from MySql to Postgres and import onto new server
  • copy over config_defaults_inc etc to new server
  • start using (hopefully)
Would this work or would it be better to
alain06
Posts: 1
Joined: 01 Apr 2010, 13:24

Re: Upgrade and change DB

Post by alain06 »

Hello.
I have the same issue here.
Using 1.1.8, willing to upgrade to 1.2 AND moving on to postgresql for corporate consistency.
Any feedback yet ?
Cheers
Alain.
duongnvm
Posts: 37
Joined: 19 May 2010, 07:26

Re: Upgrade and change DB

Post by duongnvm »

Hello every one
I have the same issue here.
Using 1.2.0a2, willing to upgrade to 1.2.1.
Any feedback yet? Help me!
duongnvm
Yeat

Howto migrate Mantis Database from MySQL to PostgreSQL

Post by Yeat »

Hello everyone,

since I could not find any resources about how to migrate from mySQL to PostgreSQL I had to figure out the steps on my own (upgraded from 1.1.6 to 1.2.0). It took me a while and I wrote a short article for my blog (it's in German though :roll:). Right now I'm too lazy to translate the full explanations to English so below there is the short English summary. Please feel free to ask if you need any further help. I performed the following steps under linux with bash, sed, grep, ruby, mysqldump and psql installed.


1. Updating mantis installation
I decided to update my mantis installation before the database migration because I wanted to transfer an up to date database. Upgrading is quite easy and is well documented elsewhere on this site :wink:


2. Get a database dump which is compatible with PostgreSQL
Visit the mysql2postgres site and download the mysql2postgres ruby script. You might have to install a few additional packages depending on your ruby installation (I had to install ruby, ruby-mysql, rubygems, rubygem-pg on my openSUSE system). I had to slightly modify the script to make it translate the tinyint(4)-type to boolean. This modified version can be downloaded here.

Then copy and modify the configuration file to fit your mySQL database settings and to exclude the table mantis_bug_file_table. A sample configuration would look like this (replace the [] values):

Code: Select all

mysql:
 hostname: [address of mySQL server]
 port: 3306
 socket:
 username: [user name]
 password: [password]
 database: [mantis database]

destination:
 # if file is given, output goes to file, else postgres
 file: mantis_table_data_raw.sql
 postgres:
  hostname:
  port:
  username:
  password:
  database:

# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
#tables:
#- table1
#- table2
#- table3
#- table4

# if exclude_tables is given, exclude the listed tables from the conversion.
exclude_tables:
- mantis_bug_file_table
#- table6
If you stick to the sample configuration the database dump will be written to the file mantis_table_data_raw.sql. After this make a working copy of this file (I named mine mantis_table_data.sql and will refer to it in the following steps).


3. Select relevant data from the dump
Delete all lines until the first COPY statement in the working copy. After that, put some DELETE statements at the beginning of the file with the following command

Code: Select all

sed -i '1i\DELETE FROM mantis_category_table;\nDELETE FROM mantis_config_table;\nDELETE FROM mantis_plugin_table;\nDELETE FROM mantis_user_table;\n' mantis_table_data.sql
Set the sequences to the proper values by using the following command

Code: Select all

grep "SELECT pg_catalog.setval" mantis_table_data_raw.sql >> mantis_table_data.sql
If the mySQL database and the PostgreSQL database use different character encodings (e. g. Latin1 vs. UTF8) you might want to put a

Code: Select all

SET client_encoding = '[mySQL encoding]';
on top of the dump file, replacing [mySQL encoding] with whatever encoding your mySQL database uses.


4. Extract and convert binary data (i. e. uploaded files)
Append the data from the formerly skipped table mantis_bug_file_table to the working copy with the following command (replace [server address], [user name], [password], [database] with proper values)

Code: Select all

mysqldump -h[server address] -u[user name] -p[password] --database [database]  --table mantis_bug_file_table --skip-extended-insert --complete-insert --hex-blob | sed -n -e "/INSERT /s/\`//g" -e "s/',0x\([0-9A-Fa-f]*\),/',E'\\\\x\1\',/g p" >> mantis_table_data.sql
Now set the value of the corresponding id sequence as follows (again, replace the brackets [])

Code: Select all

echo "SELECT pg_catalog.setval('mantis_bug_file_table_id_seq', $(expr $(mysql -h[server address] -u[user name] -p[password] [database] --skip-column-names --batch -e "SELECT MAX(id) FROM mantis_bug_file_table;") + 1), true);" >> mantis_table_data.sql

5. Create and initialize the PostgreSQL database
Let mantis itself do this job for you. Change the mantis configuration to point to your PostgreSQL database and create a database and user. Point your browser to http://[yoursite]/admin/install.php, fill out the form and have everything created and set.


6. Upload your data
Tell psql to upload your dump file

Code: Select all

psql -h [server address] -d [database] -U [user name] -W --log-file log1.log -f mantis_table_data.sql &>log2.log
If errors occur, they are reported in log2.log. In my case some bug descriptions were too long for the varchar(128) data type. But this could be easily fixed in the dump file. I dropped, recreated and re-filled the database until everything went without errors.

Finally: Congratulations! Everything is now set and ready for use :D
atrol
Site Admin
Posts: 8536
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Upgrade and change DB

Post by atrol »

Thanks for providing this information
Please use Search before posting and read the Manual
Post Reply