정리 Rake 작업
Offering: GitLab Self-Managed
GitLab은 GitLab 인스턴스를 정리하기 위한 Rake 작업을 제공합니다. GitLab 업그레이드 후 12시간 이내에는 이 작업을 실행하지 마세요. 리포지터리의 기록에서 LFS 파일을 제거하면 고아 상태가 되어 계속 디스크 공간을 차지합니다.
GitLab은 GitLab 인스턴스를 정리하기 위한 Rake 작업을 제공합니다.
참조되지 않은 LFS 파일 제거#
GitLab 업그레이드 후 12시간 이내에는 이 작업을 실행하지 마세요. 그렇지 않으면 아직 완료되지 않은 백그라운드 마이그레이션으로 인해 데이터 손실이 발생할 수 있습니다.
리포지터리의 기록에서 LFS 파일을 제거하면 고아 상태가 되어 계속 디스크 공간을 차지합니다. 이 Rake 작업으로 데이터베이스에서 유효하지 않은 참조를 제거할 수 있으며, 이를 통해 LFS 파일의 가비지 컬렉션이 가능해집니다. 예를 들어:
sudo gitlab-rake gitlab:cleanup:orphan_lfs_file_references PROJECT_PATH="gitlab-org/gitlab-foss"
bundle exec rake gitlab:cleanup:orphan_lfs_file_references RAILS_ENV=production PROJECT_PATH="gitlab-org/gitlab-foss"
PROJECT_PATH 대신 PROJECT_ID로 프로젝트를 지정할 수도 있습니다.
예를 들어:
$ sudo gitlab-rake gitlab:cleanup:orphan_lfs_file_references PROJECT_ID="13083"
I, [2019-12-13T16:35:31.764962 #82356] INFO -- : Looking for orphan LFS files for project GitLab Org / GitLab Foss
I, [2019-12-13T16:35:31.923659 #82356] INFO -- : Removed invalid references: 12
기본적으로 이 작업은 아무것도 삭제하지 않고 삭제 가능한 파일 참조 수를 보여줍니다. 실제로 참조를 삭제하려면 DRY_RUN=false로 명령을 실행하세요. LIMIT={number} 매개변수를 사용하여 삭제할 참조 수를 제한할 수도 있습니다.
이 Rake 작업은 LFS 파일에 대한 참조만 제거합니다. 참조되지 않은 LFS 파일은 나중에(하루에 한 번) 가비지 컬렉션됩니다. 즉시 가비지 컬렉션해야 하는 경우 아래에서 설명하는 rake gitlab:cleanup:orphan_lfs_files를 실행하세요.
참조되지 않은 LFS 파일 즉시 제거#
참조되지 않은 LFS 파일은 매일 제거되지만 필요한 경우 즉시 제거할 수 있습니다. 참조되지 않은 LFS 파일을 즉시 제거하려면:
sudo gitlab-rake gitlab:cleanup:orphan_lfs_files
bundle exec rake gitlab:cleanup:orphan_lfs_files
출력 예시:
$ sudo gitlab-rake gitlab:cleanup:orphan_lfs_files
I, [2020-01-08T20:51:17.148765 #43765] INFO -- : Removed unreferenced LFS files: 12
프로젝트 업로드 파일 정리#
GitLab 데이터베이스에 존재하지 않는 프로젝트 업로드 파일을 정리합니다.
파일 시스템에서 프로젝트 업로드 파일 정리#
GitLab 데이터베이스에 존재하지 않는 로컬 프로젝트 업로드 파일을 정리합니다. 이 작업은 프로젝트를 찾을 수 있으면 파일을 수정하려 시도하고, 그렇지 않으면 파일을 분실물 보관함 디렉터리로 이동합니다. 파일 시스템에서 프로젝트 업로드 파일을 정리하려면:
sudo gitlab-rake gitlab:cleanup:project_uploads
bundle exec rake gitlab:cleanup:project_uploads RAILS_ENV=production
출력 예시:
$ sudo gitlab-rake gitlab:cleanup:project_uploads
I, [2018-07-27T12:08:27.671559 #89817] INFO -- : Looking for orphaned project uploads to clean up. Dry run...
D, [2018-07-27T12:08:28.293568 #89817] DEBUG -- : Processing batch of 500 project upload file paths, starting with /opt/gitlab/embedded/service/gitlab-rails/public/uploads/test.out
I, [2018-07-27T12:08:28.689869 #89817] INFO -- : Can move to lost and found /opt/gitlab/embedded/service/gitlab-rails/public/uploads/test.out -> /opt/gitlab/embedded/service/gitlab-rails/public/uploads/-/project-lost-found/test.out
I, [2018-07-27T12:08:28.755624 #89817] INFO -- : Can fix /opt/gitlab/embedded/service/gitlab-rails/public/uploads/foo/bar/89a0f7b0b97008a4a18cedccfdcd93fb/foo.txt -> /opt/gitlab/embedded/service/gitlab-rails/public/uploads/qux/foo/bar/89a0f7b0b97008a4a18cedccfdcd93fb/foo.txt
I, [2018-07-27T12:08:28.760257 #89817] INFO -- : Can move to lost and found /opt/gitlab/embedded/service/gitlab-rails/public/uploads/foo/bar/1dd6f0f7eefd2acc4c2233f89a0f7b0b/image.png -> /opt/gitlab/embedded/service/gitlab-rails/public/uploads/-/project-lost-found/foo/bar/1dd6f0f7eefd2acc4c2233f89a0f7b0b/image.png
I, [2018-07-27T12:08:28.764470 #89817] INFO -- : To cleanup these files run this command with DRY_RUN=false
$ sudo gitlab-rake gitlab:cleanup:project_uploads DRY_RUN=false
I, [2018-07-27T12:08:32.944414 #89936] INFO -- : Looking for orphaned project uploads to clean up...
D, [2018-07-27T12:08:33.293568 #89817] DEBUG -- : Processing batch of 500 project upload file paths, starting with /opt/gitlab/embedded/service/gitlab-rails/public/uploads/test.out
I, [2018-07-27T12:08:33.689869 #89817] INFO -- : Did move to lost and found /opt/gitlab/embedded/service/gitlab-rails/public/uploads/test.out -> /opt/gitlab/embedded/service/gitlab-rails/public/uploads/-/project-lost-found/test.out
I, [2018-07-27T12:08:33.755624 #89817] INFO -- : Did fix /opt/gitlab/embedded/service/gitlab-rails/public/uploads/foo/bar/89a0f7b0b97008a4a18cedccfdcd93fb/foo.txt -> /opt/gitlab/embedded/service/gitlab-rails/public/uploads/qux/foo/bar/89a0f7b0b97008a4a18cedccfdcd93fb/foo.txt
I, [2018-07-27T12:08:33.760257 #89817] INFO -- : Did move to lost and found /opt/gitlab/embedded/service/gitlab-rails/public/uploads/foo/bar/1dd6f0f7eefd2acc4c2233f89a0f7b0b/image.png -> /opt/gitlab/embedded/service/gitlab-rails/public/uploads/-/project-lost-found/foo/bar/1dd6f0f7eefd2acc4c2233f89a0f7b0b/image.png
오브젝트 스토리지를 사용하는 경우, All-in-one Rake 작업을 실행하여 모든 업로드가 오브젝트 스토리지로 마이그레이션되었고 업로드 폴더의 디스크에 파일이 없는지 확인하세요.
오브젝트 스토리지에서 프로젝트 업로드 파일 정리#
GitLab 데이터베이스에 존재하지 않는 오브젝트 스토리지 업로드 파일을 분실물 보관함 디렉터리로 이동합니다. 오브젝트 스토리지에서 프로젝트 업로드 파일을 정리하려면:
sudo gitlab-rake gitlab:cleanup:remote_upload_files
bundle exec rake gitlab:cleanup:remote_upload_files RAILS_ENV=production
출력 예시:
$ sudo gitlab-rake gitlab:cleanup:remote_upload_files
I, [2018-08-02T10:26:13.995978 #45011] INFO -- : Looking for orphaned remote uploads to remove. Dry run...
I, [2018-08-02T10:26:14.120400 #45011] INFO -- : Can be moved to lost and found: @hashed/6b/DSC_6152.JPG
I, [2018-08-02T10:26:14.120482 #45011] INFO -- : Can be moved to lost and found: @hashed/79/02/7902699be42c8a8e46fbbb4501726517e86b22c56a189f7625a6da49081b2451/711491b29d3eb08837798c4909e2aa4d/DSC00314.jpg
I, [2018-08-02T10:26:14.120634 #45011] INFO -- : To cleanup these files run this command with DRY_RUN=false
$ sudo gitlab-rake gitlab:cleanup:remote_upload_files DRY_RUN=false
I, [2018-08-02T10:26:47.598424 #45087] INFO -- : Looking for orphaned remote uploads to remove...
I, [2018-08-02T10:26:47.753131 #45087] INFO -- : Moved to lost and found: @hashed/6b/DSC_6152.JPG -> lost_and_found/@hashed/6b/DSC_6152.JPG
I, [2018-08-02T10:26:47.764356 #45087] INFO -- : Moved to lost and found: @hashed/79/02/7902699be42c8a8e46fbbb4501726517e86b22c56a189f7625a6da49081b2451/711491b29d3eb08837798c4909e2aa4d/DSC00314.jpg -> lost_and_found/@hashed/79/02/7902699be42c8a8e46fbbb4501726517e86b22c56a189f7625a6da49081b2451/711491b29d3eb08837798c4909e2aa4d/DSC00314.jpg
고아 아티팩트 파일 제거#
이 명령은 오브젝트 스토리지에 저장된 아티팩트에는 작동하지 않습니다.
디스크에 예상보다 더 많은 작업 아티팩트 파일 및/또는 디렉터리가 있는 것을 발견하면 다음을 실행할 수 있습니다:
sudo gitlab-rake gitlab:cleanup:orphan_job_artifact_files
이 명령은:
- 전체 아티팩트 폴더를 스캔합니다.
- 데이터베이스에 레코드가 있는 파일을 확인합니다.
- 데이터베이스 레코드가 없으면 디스크에서 파일과 디렉터리를 삭제합니다.
기본적으로 이 작업은 아무것도 삭제하지 않고 삭제할 수 있는 항목을 보여줍니다. 실제로 파일을 삭제하려면 DRY_RUN=false로 명령을 실행하세요:
sudo gitlab-rake gitlab:cleanup:orphan_job_artifact_files DRY_RUN=false
LIMIT으로 삭제할 파일 수를 제한할 수도 있습니다(기본값 100):
sudo gitlab-rake gitlab:cleanup:orphan_job_artifact_files LIMIT=100
이렇게 하면 디스크에서 최대 100개의 파일만 삭제됩니다. 테스트 목적으로 소규모 세트를 삭제하는 데 사용할 수 있습니다.
DEBUG=1을 제공하면 고아로 감지된 모든 파일의 전체 경로가 표시됩니다.
ionice가 설치된 경우 작업은 이를 사용하여 명령이 디스크에 과도한 부하를 주지 않도록 합니다. NICENESS로 niceness 수준을 구성할 수 있습니다. 아래는 유효한 수준이지만, 확실하게 하려면 man 1 ionice를 참조하세요.
0또는None1또는Realtime2또는Best-effort(기본값)3또는Idle
만료된 ActiveSession 조회 키 제거#
만료된 ActiveSession 조회 키를 제거하려면:
sudo gitlab-rake gitlab:cleanup:sessions:active_sessions_lookup_keys
bundle exec rake gitlab:cleanup:sessions:active_sessions_lookup_keys RAILS_ENV=production
컨테이너 레지스트리 가비지 컬렉션#
컨테이너 레지스트리는 상당한 양의 디스크 공간을 사용할 수 있습니다. 사용하지 않는 레이어를 정리하기 위해 레지스트리는 가비지 컬렉션 명령을 포함합니다.
