Commit 4673d980a050f95f9b938579d23b7b05e34ab32b

Authored by Dmitriy Zaporozhets
2 parents 6af6f4b4 3bfbea37

Merge branch 'convert_backup_to_postgres' into 'master'

Convert MySQL backup to Postgres
Showing 2 changed files with 61 additions and 1 deletions   Show diff stats
CHANGELOG
... ... @@ -9,6 +9,7 @@ v 6.9.0
9 9 - Improve comments loading logic
10 10 - Stop refreshing comments when the tab is hidden
11 11 - Improve issue and merge request mobile UI (Drew Blessing)
  12 + - Document how to convert a backup to PostgreSQL
12 13  
13 14 v 6.8.0
14 15 - Ability to at mention users that are participating in issue and merge req. discussion
... ...
doc/update/mysql_to_postgresql.md
1   -# Use the shell commands below to convert a MySQL GitLab database to a PostgreSQL one.
  1 +# Migrating GitLab from MySQL to Postgres
  2 +
  3 +If you are replacing MySQL with Postgres while keeping GitLab on the same
  4 +server all you need to do is to export from MySQL and import into Postgres as
  5 +described below. If you are also moving GitLab to another server, or if you are
  6 +switching to omnibus-gitlab, you may want to use a GitLab backup file. The
  7 +second part of this documents explains the procedure to do this.
  8 +
  9 +## Export from MySQL and import into Postgres
  10 +
  11 +Use this if you are keeping GitLab on the same server.
2 12  
3 13 ```
  14 +sudo service gitlab stop
  15 +
  16 +# Update /home/git/gitlab/config/database.yml
  17 +
4 18 git clone https://github.com/lanyrd/mysql-postgresql-converter.git
5 19 cd mysql-postgresql-converter
6 20 mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.mysql -u root gitlabhq_production
7 21 python db_converter.py databasename.mysql databasename.psql
8 22 psql -f databasename.psql -d gitlabhq_production
  23 +
  24 +sudo service gitlab start
  25 +```
  26 +
  27 +## Converting a GitLab backup file from MySQL to Postgres
  28 +
  29 +GitLab backup files (<timestamp>_gitlab_backup.tar) contain a SQL dump. Using
  30 +the lanyrd database converter we can replace a MySQL database dump inside the
  31 +tar file with a Postgres database dump. This can be useful if you are moving to
  32 +another server.
  33 +
  34 +```
  35 +# Stop GitLab
  36 +sudo service gitlab stop
  37 +
  38 +# Create the backup
  39 +cd /home/git/gitlab
  40 +sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
  41 +
  42 +# Note the filename of the backup that was created. We will call it
  43 +# TIMESTAMP_gitlab_backup.tar below.
  44 +
  45 +# Move the backup file we will convert to its own directory
  46 +sudo -u git -H mkdir -p tmp/backups/postgresql
  47 +sudo -u git -H mv tmp/backups/TIMESTAMP_gitlab_backup.tar tmp/backups/postgresql/
  48 +
  49 +# Create a separate database dump with PostgreSQL compatibility
  50 +cd tmp/backups/postgresql
  51 +sudo -u git -H mysqldump --compatible=postgresql --default-character-set=utf8 -r gitlabhq_production.mysql -u root gitlabhq_production
  52 +
  53 +# Clone the database converter
  54 +sudo -u git -H git clone https://github.com/lanyrd/mysql-postgresql-converter.git
  55 +
  56 +# Convert gitlabhq_production.mysql
  57 +sudo -u git -H mkdir db
  58 +sudo -u git -H python mysql-postgresql-converter/db_converter.py gitlabhq_production.mysql db/database.sql
  59 +
  60 +# Replace the MySQL dump in TIMESTAMP_gitlab_backup.tar.
  61 +
  62 +# Warning: if you forget to replace TIMESTAMP below, tar will create a new file
  63 +# 'TIMESTAMP_gitlab_backup.tar' without giving an error.
  64 +
  65 +sudo -u git -H tar rf TIMESTAMP_gitlab_backup.tar db/database.sql
  66 +
  67 +# Done! TIMESTAMP_gitlab_backup.tar can now be restored into a Postgres GitLab installation.
9 68 ```
... ...