Commit c01efa0ed5a9dadd2daf8cc63c5612864c771f23

Authored by Jacob Vosmaer
1 parent 3dea71ce

Document how to convert a backup to PostgreSQL

Showing 2 changed files with 48 additions and 0 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 1 # Use the shell commands below to convert a MySQL GitLab database to a PostgreSQL one.
2 2  
  3 +## Export from MySQL and import into Postgres
  4 +
  5 +Use this if you are keeping GitLab on the same server.
  6 +
3 7 ```
4 8 git clone https://github.com/lanyrd/mysql-postgresql-converter.git
5 9 cd mysql-postgresql-converter
... ... @@ -7,3 +11,46 @@ mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.m
7 11 python db_converter.py databasename.mysql databasename.psql
8 12 psql -f databasename.psql -d gitlabhq_production
9 13 ```
  14 +
  15 +## Converting a GitLab backup file from MySQL to Postgres
  16 +
  17 +GitLab backup files (<timestamp>_gitlab_backup.tar) contain a SQL dump. Using
  18 +the lanyrd database converter we can replace a MySQL database dump inside the
  19 +tar file with a Postgres database dump. This can be useful if you are moving to
  20 +another server.
  21 +
  22 +```
  23 +# Stop GitLab
  24 +sudo service gitlab stop
  25 +
  26 +# Create the backup
  27 +cd /home/git/gitlab
  28 +sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
  29 +
  30 +# Note the filename of the backup that was created. We will call it
  31 +# TIMESTAMP_gitlab_backup.tar below.
  32 +
  33 +# Move the backup file we will convert to its own directory
  34 +sudo -u git -H mkdir -p tmp/backups/postgresql
  35 +sudo -u git -H mv tmp/backups/TIMESTAMP_gitlab_backup.tar tmp/backups/postgresql/
  36 +
  37 +# Create a separate database dump with PostgreSQL compatibility
  38 +cd tmp/backups/postgresql
  39 +sudo -u git -H mysqldump --compatible=postgresql --default-character-set=utf8 -r gitlabhq_production.mysql -u root gitlabhq_production
  40 +
  41 +# Clone the database converter
  42 +sudo -u git -H git clone https://github.com/lanyrd/mysql-postgresql-converter.git
  43 +
  44 +# Convert gitlabhq_production.mysql
  45 +sudo -u git -H mkdir db
  46 +sudo -u git -H python mysql-postgresql-converter/db_converter.py gitlabhq_production.mysql db/database.sql
  47 +
  48 +# Replace the MySQL dump in TIMESTAMP_gitlab_backup.tar.
  49 +
  50 +# Warning: if you forget to replace TIMESTAMP below, tar will create a new file
  51 +# 'TIMESTAMP_gitlab_backup.tar' without giving an error.
  52 +
  53 +sudo -u git -H tar rf TIMESTAMP_gitlab_backup.tar db/database.sql
  54 +
  55 +# Done! TIMESTAMP_gitlab_backup.tar can now be restored into a Postgres GitLab installation.
  56 +```
... ...