diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2015-05-18 13:36:41 +0200 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2015-05-18 13:37:43 +0200 |
commit | 5483c2b0a93c7313c7a7b42a402090f3f235519b (patch) | |
tree | ebdd5ba3c9d93a95333e538c8b25128bb4d223c3 /doc/development/db_dump.md | |
parent | c9c44e7f3bc726f4bb7dfb067e1be17da4dab5f3 (diff) | |
download | gitlab-ce-5483c2b0a93c7313c7a7b42a402090f3f235519b.tar.gz |
How to dump a production DB to staging
Diffstat (limited to 'doc/development/db_dump.md')
-rw-r--r-- | doc/development/db_dump.md | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/doc/development/db_dump.md b/doc/development/db_dump.md new file mode 100644 index 00000000000..4ad3bd534e0 --- /dev/null +++ b/doc/development/db_dump.md @@ -0,0 +1,45 @@ +# Importing a database dump into a staging enviroment + +Sometimes it is useful to import the database from a production environment +into a staging environment for testing. The procedure below assumes you have +SSH+sudo access to both the production environment and the staging VM. + +On the staging VM, add the following line to `/etc/gitlab/gitlab.rb` to speed up +large database imports. + +``` +# On STAGING +echo "postgresql['checkpoint_segments'] = 64" | sudo tee -a /etc/gitlab/gitlab.rb +sudo touch /etc/gitlab/skip-auto-migrations +sudo gitlab-ctl reconfigure +``` + +Next, we let the production environment stream a compressed SQL dump to our +local machine via SSH, and redirect this stream to a psql client on the staging +VM. + +``` +# On LOCAL MACHINE +ssh -C gitlab.example.com sudo -u gitlab-psql /opt/gitlab/embedded/bin/pg_dump -Cc gitlabhq_production |\ + ssh -C staging-vm sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -d template1 +``` + +## Recreating directory structure + +If you need to re-create some directory structure on the staging server you can +use this procedure. + +First, on the production server, create a list of directories you want to +re-create. + +``` +# On PRODUCTION +(umask 077; sudo find /var/opt/gitlab/git-data/repositories -maxdepth 1 -type d -print0 > directories.txt) +``` + +Copy `directories.txt` to the staging server and create the directories there. + +``` +# On STAGING +sudo -u git xargs -0 mkdir -p < directories.txt +``` |