스테이징 환경으로 데이터베이스 덤프 가져오기

테스트를 위해 프로덕션 환경의 데이터베이스를 스테이징 환경으로 가져오는 것이 유용할 때가 있습니다. 아래 절차는 프로덕션 환경과 스테이징 VM의 SSH 및 sudo 액세스 권한이 있다고 가정합니다.

작업이 끝나면 스테이징 VM을 제거하세요. 데이터 누출을 피하는 것이 중요합니다.

스테이징 VM에서 대규모 데이터베이스 가져오기를 가속화하기 위해 /etc/gitlab/gitlab.rb에 다음 줄을 추가합니다.

# 스테이징에서 실행
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

다음으로, 프로덕션 환경에서 압축된 SQL 덤프를 우리의 로컬 머신으로 스트리밍하고, 이 스트림을 스테이징 VM의 psql 클라이언트로 리디렉션합니다.

# 로컬 머신에서 실행
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

디렉토리 구조 재생성

스테이징 서버에서 일부 디렉토리 구조를 다시 생성해야 할 경우 이 절차를 사용할 수 있습니다.

먼저, 프로덕션 서버에서 다시 생성하려는 디렉토리 목록을 작성합니다.

# 프로덕션에서 실행
(umask 077; sudo find /var/opt/gitlab/git-data/repositories -maxdepth 1 -type d -print0 > directories.txt)

directories.txt를 스테이징 서버로 복사하고 해당 디렉토리를 생성합니다.

# 스테이징에서 실행
sudo -u git xargs -0 mkdir -p < directories.txt