Rake 작업 정리하기
GitLab은 GitLab 인스턴스를 정리하기 위한 Rake 작업을 제공합니다.
참조되지 않은 LFS 파일 제거하기
저장소의 역사에서 LFS 파일을 제거하면, 이들은 고아가 되어 계속해서 디스크 공간을 소모합니다. 이 Rake 작업을 사용하면 데이터베이스에서 잘못된 참조를 제거할 수 있으며, 이를 통해 LFS 파일의 가비지 수집이 가능해집니다.
예를 들어:
# omnibus-gitlab
sudo gitlab-rake gitlab:cleanup:orphan_lfs_file_references PROJECT_PATH="gitlab-org/gitlab-foss"
# installation from source
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 파일은 매일 제거되지만 필요시 즉시 제거할 수 있습니다. 예를 들어:
# omnibus-gitlab
sudo gitlab-rake gitlab:cleanup:orphan_lfs_files
# installation from source
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 데이터베이스에 존재하지 않는 로컬 프로젝트 업로드 파일을 정리합니다.
작업은 파일의 프로젝트를 찾을 수 있으면 파일을 수정하려고 시도하며, 그렇지 않으면 파일을 분실물 보관소로 이동합니다.
# omnibus-gitlab
sudo gitlab-rake gitlab:cleanup:project_uploads
# installation from source
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
객체 저장소를 사용하는 경우, 올인원 Rake 작업을 실행하여 모든 업로드가 객체 저장소로 마이그레이션되고 업로드 폴더에 디스크상의 파일이 없도록 해야 합니다.
프로젝트 업로드 파일을 객체 저장소에서 정리하기
GitLab 데이터베이스에 존재하지 않는 경우 객체 저장소 업로드 파일을 분실물 보관소 디렉토리로 이동합니다.
# omnibus-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 -- : 제거할 고아 원격 업로드를 찾고 있습니다. 드라이 실행 중...
I, [2018-08-02T10:26:14.120400 #45011] INFO -- : 분실물 보관소로 이동할 수 있음: @hashed/6b/DSC_6152.JPG
I, [2018-08-02T10:26:14.120482 #45011] INFO -- : 분실물 보관소로 이동할 수 있음: @hashed/79/02/7902699be42c8a8e46fbbb4501726517e86b22c56a189f7625a6da49081b2451/711491b29d3eb08837798c4909e2aa4d/DSC00314.jpg
I, [2018-08-02T10:26:14.120634 #45011] INFO -- : 이러한 파일을 정리하려면 DRY_RUN=false로 이 명령을 실행하세요.
$ sudo gitlab-rake gitlab:cleanup:remote_upload_files DRY_RUN=false
I, [2018-08-02T10:26:47.598424 #45087] INFO -- : 제거할 고아 원격 업로드를 찾고 있습니다...
I, [2018-08-02T10:26:47.753131 #45087] INFO -- : 분실물 보관소로 이동됨: @hashed/6b/DSC_6152.JPG -> lost_and_found/@hashed/6b/DSC_6152.JPG
I, [2018-08-02T10:26:47.764356 #45087] INFO -- : 분실물 보관소로 이동됨: @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
로 니코니스 레벨을 구성할 수 있습니다. 아래는 유효한 레벨입니다. 하지만 man 1 ionice
를 참조하여 확인하세요.
-
0
또는None
-
1
또는Realtime
-
2
또는Best-effort
(기본값) -
3
또는Idle
만료된 ActiveSession 조회 키 제거
# omnibus-gitlab
sudo gitlab-rake gitlab:cleanup:sessions:active_sessions_lookup_keys
# 소스에서 설치
bundle exec rake gitlab:cleanup:sessions:active_sessions_lookup_keys RAILS_ENV=production
컨테이너 레지스트리 가비지 수집
컨테이너 레지스트리는 상당한 양의 디스크 공간을 사용할 수 있습니다. 사용하지 않는 레이어를 정리하기 위해 레지스트리에는 가비지 수집 명령어가 포함되어 있습니다.