Simply use importer plugin. It works for different databases.
https://gerrit-review.googlesource.com/Documentation/config-plugins.html#importer https://gerrit.googlesource.com/plugins/importer/
[Deprecated]
Tutorial and tool to help those migrating a gerrit instance with an embedded H2 database to one with mysql (mariadb as well)
I kept this very basic to limit the amount of packages and libraries need to run the perl script
Inspired by original support I found:
https://groups.google.com/forum/#!searchin/repo-discuss/Convert$20Gerrit$20database/repo-discuss/KiDVyDJg5u4/2-wKVb0eNkUJ
- This tool assumes you have a current Gerrit instance with H2 running and knowledge of gerrit
- In order to migrate to a mysql based database, some gerrit settings will need to be changed after the migration
- If you would like to go back to the h2 database, you can use your original settings. However be aware you will lose data if you do so after restarting gerrit and data is published to it.
"Just watch out for the CSV dump-load process to make sure
they are using the same escaping rules for data values, same table
column orderings, and that you got every table in the schema."(from google group forum)
- The CSVWRITE function for H2 had a few mistmatches with MYSQL. My attempt to fix all the issues
is done in the CSV Cleaner portion of each table dump. Change $debug to > 2 in the script to see issues found - There may also be issues with the user running this migration and the user that the gerrit server is running under.
I was able to make this work running as a different user than the owner of the gerrit server. - This was tested on gerrit 2.8.6.1, it is possible tables have changed in older/newer versions.
Modify h2TablesToMigrate, h2TablesToMigrate, and mysqlTablesToUpdate accordingly in the script. Better support could be to pull in config files.
Create reviewdb database
"MAKE SURE YOU USE THE SAME VERSION OF YOUR CURRENT GERRIT INSTANCE
Just run the standard installation procedure to setup a MySQL instance of Gerrit Code Review in a temporary site path.
You'll wind up with a clean database schema in your MySQL server, and this dummy site directory directory you can clean up later." (from google group forum)
Make sure the gerrit server has the following /etc/gerrit.config
*Note type is mysql even for mariadb
[database]
type = mysql
hostname = <hostname>
port = <port>
database = reviewd
username = root
Shutdown your mysql based temporary gerrit server
Create .ssh/config file in home (~/) and add the following to the config file
Host gerrit-server
Hostname <hostname of permanent gerrit server>
Port <port default is 29418>
AFSTokenPassing no [possibly needed]
Currently not using a config file due to libraries needed
my %config = (
"gerrit" =>
{
"host" => "<host in .ssh/config e.g. gerrit-server>"
},
"mysql" =>
{
"host" => "<hostname for mysql>",
"config" => "<path to config file default my.cnf>",
"port" => "<mysql port>",
"password" => "<password>"
},
"general" =>
{
"h2_csv_dir" => "<path to csv directory>",
"mysql_infile_dir" => "<path to mysql infile directory>"
}
);
This init dump file already exists in gerrit-h2-mysql as gerrit_init.sql, but if you want to manually generate
mysqldump -u root -p -h <hostname> --port=<port> reviewdb > <dump file path>
Takes variable length, and due to the CSV Cleaner steps files are processed line by line.
This was a quick and dirty solution to fix the issues I found and didn't add too much time in my case
cd gerrit-h2-mysql
./gerrit-h2-mysql.pl
If you run into issues here are some settings to mess around with.
I tried to separate fields and lines differently from the traditional method ("col1","col2","col3")
Current values in the script that can be modified
my $uniqueSepartor = "@#!!#@";
my $rowSeparator = "#%#";
my $fieldDelimiter = "^";
The variables mean the following:
$fieldDelimiterCOLUMN1$fieldDelimiter$uniqueSepartor$fieldDelimiterCOLUMN2$fieldDelimiter$rowSeparator
Example with the current settings:
^column1^@#!!#@^column2^@#!!#@^column3^#%#
^column1b^@#!!#@^column2b^@#!!#@^column3b^#%#
If there are issues remember to use gerrit_init.sql to reload the base reviewdb state,
and most likely this is due
to the csv format not being parsed correctly.
mysql -u root -p -h <hostname> --port=<port> reviewdb < gerrit_init.sql
See step 2 for gerrit.config options, but do for permanent gerrit instance
As for secure.config add the following
[database]
password = <password>
You can remove the temporary gerrit site, it was only used to initialize the mysql database