gitlab backup & restore 방법
gitlab 백업과 복원 방법은 간단하다.
# gitlab-backup create
2023-12-01 10:36:40 UTC -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2023-12-01 10:36:43 UTC -- Dumping database ... done
2023-12-01 10:36:43 UTC -- Dumping repositories ...
2023-12-01 10:36:47 UTC -- Dumping repositories ... done
2023-12-01 10:36:47 UTC -- Dumping uploads ...
2023-12-01 10:36:47 UTC -- Dumping uploads ... done
2023-12-01 10:36:47 UTC -- Dumping builds ...
2023-12-01 10:36:47 UTC -- Dumping builds ... done
2023-12-01 10:36:47 UTC -- Dumping artifacts ...
2023-12-01 10:36:47 UTC -- Dumping artifacts ... done
2023-12-01 10:36:47 UTC -- Dumping pages ...
2023-12-01 10:36:47 UTC -- Dumping pages ... done
2023-12-01 10:36:47 UTC -- Dumping lfs objects ...
2023-12-01 10:36:47 UTC -- Dumping lfs objects ... done
2023-12-01 10:36:47 UTC -- Dumping terraform states ...
2023-12-01 10:36:47 UTC -- Dumping terraform states ... done
2023-12-01 10:36:47 UTC -- Dumping container registry images ... [DISABLED]
2023-12-01 10:36:47 UTC -- Dumping packages ...
2023-12-01 10:36:47 UTC -- Dumping packages ... done
2023-12-01 10:36:47 UTC -- Dumping ci secure files ...
2023-12-01 10:36:47 UTC -- Dumping ci secure files ... done
2023-12-01 10:36:47 UTC -- Creating backup archive: 1701427000_2023_12_01_16.2.3_gitlab_backup.tar ...
2023-12-01 10:36:48 UTC -- Creating backup archive: 1701427000_2023_12_01_16.2.3_gitlab_backup.tar ... done
2023-12-01 10:36:48 UTC -- Uploading backup archive to remote storage ... [SKIPPED]
2023-12-01 10:36:48 UTC -- Deleting old backups ... [SKIPPED]
2023-12-01 10:36:48 UTC -- Deleting tar staging files ...
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/backup_information.yml
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/db
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/repositories
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/uploads.tar.gz
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/builds.tar.gz
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/artifacts.tar.gz
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/pages.tar.gz
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/lfs.tar.gz
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/terraform_state.tar.gz
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/packages.tar.gz
2023-12-01 10:36:48 UTC -- Cleaning up /var/opt/gitlab/backups/ci_secure_files.tar.gz
2023-12-01 10:36:48 UTC -- Deleting tar staging files ... done
2023-12-01 10:36:48 UTC -- Deleting backups/tmp ...
2023-12-01 10:36:48 UTC -- Deleting backups/tmp ... done
2023-12-01 10:36:48 UTC -- Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
2023-12-01 10:36:48 UTC -- Backup 1701427000_2023_12_01_16.2.3 is done.
2023-12-01 10:36:48 UTC -- Deleting backup and restore PID file ... done
이렇게 백업이 진행 된다.
옵션을 수정하지 않았다면 기본 백업 경로는
/var/opt/gitlab/backups/ 위치에 저장 되고
# ls
1701427000_2023_12_01_16.2.3_gitlab_backup.tar
tar 파일로 저장이 된다.
백업 경로는 수정하고 싶다면
# vi /etc/gitlab/gitlab.rb
위 파일을 수정하고 경로 수정 하면 된다.
gitlab.rb 파일을 수정하면 적용 시켜줘야 정상 작동이 된다.
적용 방법은
# gitlab-ctl reconfigure
# gitlab-ctl restart
이다.
복원은
# gitlab-backup restore 1701427000_2023_12_01_16.2.3_gitlab_backup.tar
백업된 파일을 /var/opt/gitlab/backups 로 복사 해주고 권한을 git:git 으로 변경해주자
# chown -r git:git /var/opt/gitlab/backups/*
이렇게 해주면 정상적으로 복원이 된다.
추가로 설정파일도 복사해서 새로운 서버에 넣어주자
/etc/gitlab/ 파일 복사
만약에 버전이 안맞는다면 위와 같이 버전이 안맞는다고 에러 뜬다 버전을 맞춰줘야 한다.
git 버전 확인 하는 방법은
# gitlab-rake gitlab:env:info
System information
System:
Current User: git
Using RVM: no
Ruby Version: 3.0.6p216
Gem Version: 3.4.14
Bundler Version:2.4.16
Rake Version: 13.0.6
Redis Version: 7.0.12
Sidekiq Version:6.5.7
Go Version: unknown
GitLab information
Version: 16.2.3
Revision: 6a407717a9c
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
이렇게 버전 확인이 가능하다.
특정 버전 설치는
# curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
하고나서
# yum install gitlab-ce-(원하는 버전)-ce.0.el6.x86_64 하면 된다.
yum install gitlab-ce-16.2.3-* 이렇게~
주기적인 백업을 하고 싶다면 crontab -e 를 이용해주면 된다.
# crontab -e
0 1 * * * /opt/gitlab/bin/gitlab-backup create CRON=1
하면 된다.