File: db_dump.md

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (56 lines) | stat: -rw-r--r-- 1,863 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
stage: Data Stores
group: Database
info: Any user with at least the Maintainer role can merge updates to this content. For details, see https://docs.gitlab.com/ee/development/development_processes.html#development-guidelines-review.
---

# Importing a database dump into a staging environment

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 and `sudo` access to both the production environment and the staging VM.

**Destroy your staging VM** when you are done with it. It is important to avoid
data leaks.

On the staging VM, add the following line to `/etc/gitlab/gitlab.rb` to speed up
large database imports.

```shell
# On STAGING
echo "postgresql['checkpoint_segments'] = 64" | sudo tee -a /etc/gitlab/gitlab.rb
sudo touch /etc/gitlab/skip-auto-reconfigure
sudo gitlab-ctl reconfigure
sudo gitlab-ctl stop puma
sudo gitlab-ctl stop sidekiq
```

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.

```shell
# 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.

```shell
# 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.

```shell
# On STAGING
sudo -u git xargs -0 mkdir -p < directories.txt
```