2020-10-05 11:08:56 -04:00
---
2022-05-31 11:09:02 -04:00
stage: Data Stores
2020-10-05 11:08:56 -04:00
group: Database
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-10-05 11:08:56 -04:00
---
2015-11-23 18:19:17 -05:00
# Importing a database dump into a staging environment
2015-05-18 07:36:41 -04:00
Sometimes it is useful to import the database from a production environment
into a staging environment for testing. The procedure below assumes you have
2020-06-09 23:08:17 -04:00
SSH and `sudo` access to both the production environment and the staging VM.
2015-05-18 07:36:41 -04:00
2015-06-16 04:00:02 -04:00
**Destroy your staging VM** when you are done with it. It is important to avoid
data leaks.
2015-05-18 07:36:41 -04:00
On the staging VM, add the following line to `/etc/gitlab/gitlab.rb` to speed up
large database imports.
2020-03-05 22:08:08 -05:00
```shell
2015-05-18 07:36:41 -04:00
# On STAGING
echo "postgresql['checkpoint_segments'] = 64" | sudo tee -a /etc/gitlab/gitlab.rb
2018-11-23 09:44:27 -05:00
sudo touch /etc/gitlab/skip-auto-reconfigure
2015-05-18 07:36:41 -04:00
sudo gitlab-ctl reconfigure
2021-06-03 08:10:18 -04:00
sudo gitlab-ctl stop puma
2015-06-16 04:00:02 -04:00
sudo gitlab-ctl stop sidekiq
2015-05-18 07:36:41 -04:00
```
Next, we let the production environment stream a compressed SQL dump to our
2020-06-09 23:08:17 -04:00
local machine via SSH, and redirect this stream to a `psql` client on the staging
2015-05-18 07:36:41 -04:00
VM.
2020-03-05 22:08:08 -05:00
```shell
2015-05-18 07:36:41 -04:00
# 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.
2020-03-05 22:08:08 -05:00
```shell
2015-05-18 07:36:41 -04:00
# 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.
2020-03-05 22:08:08 -05:00
```shell
2015-05-18 07:36:41 -04:00
# On STAGING
sudo -u git xargs -0 mkdir -p < directories.txt
```