Help us learn about your current experience with the documentation. Take the survey.

将数据库导入到预发布环境

有时将生产环境的数据库导入到预发布环境进行测试会很有用。下面的过程假设您对生产环境和预发布虚拟机(VM)都有 SSH 和 sudo 访问权限。

完成工作后销毁您的预发布虚拟机。避免数据泄露非常重要。

在预发布虚拟机上,将以下行添加到 /etc/gitlab/gitlab.rb 以加快大型数据库导入速度。

# 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

接下来,我们让生产环境通过 SSH 将压缩的 SQL 转储流传输到我们的本地机器,然后将这个流重定向到预发布虚拟机上的 psql 客户端。

# 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

重新创建目录结构

如果您需要在预发布服务器上重新创建某些目录结构,可以使用此过程。

首先,在生产服务器上,创建您想要重新创建的目录列表。

# On PRODUCTION
(umask 077; sudo find /var/opt/gitlab/git-data/repositories -maxdepth 1 -type d -print0 > directories.txt)

directories.txt 复制到预发布服务器并在那里创建目录。

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