{{< details >}}
- Tier: 基础版, 专业版, 旗舰版
- Offering: 极狐GitLab 私有化部署
{{< /details >}}
极狐GitLab 提供 Rake 任务用于清理极狐GitLab 实例。
删除未引用的 LFS 文件
{{< alert type=”warning” >}}
不要在极狐GitLab 升级后的 12 小时内运行此命令。这是为了确保所有后台迁移已完成,否则可能导致数据丢失。
{{< /alert >}}
当你从仓库历史中删除 LFS 文件时,它们会变成孤立的,并继续占用磁盘空间。通过此 Rake 任务,你可以从数据库中删除无效引用,从而允许对 LFS 文件进行垃圾回收。例如:
{{< tabs >}}
{{< tab title=”Linux 软件包 (Omnibus)” >}}
sudo gitlab-rake gitlab:cleanup:orphan_lfs_file_references PROJECT_PATH="gitlab-org/gitlab-foss"
{{< /tab >}}
{{< tab title=”自编译 (source)” >}}
bundle exec rake gitlab:cleanup:orphan_lfs_file_references RAILS_ENV=production PROJECT_PATH="gitlab-org/gitlab-foss"
{{< /tab >}}
{{< /tabs >}}
你也可以使用 PROJECT_ID
代替 PROJECT_PATH
来指定项目。
例如:
$ 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 文件:
{{< tabs >}}
{{< tab title=”Linux 软件包 (Omnibus)” >}}
sudo gitlab-rake gitlab:cleanup:orphan_lfs_files
{{< /tab >}}
{{< tab title=”自编译 (source)” >}}
bundle exec rake gitlab:cleanup:orphan_lfs_files
{{< /tab >}}
{{< /tabs >}}
示例输出:
$ sudo gitlab-rake gitlab:cleanup:orphan_lfs_files
I, [2020-01-08T20:51:17.148765 #43765] INFO -- : Removed unreferenced LFS files: 12
清理项目上传文件
如果项目上传文件在极狐GitLab 数据库中不存在,则清理这些文件。
从文件系统中清理项目上传文件
如果本地项目上传文件在极狐GitLab 数据库中不存在,则清理这些文件。任务会尝试修复文件,如果找到其项目,否则会将文件移动到失物招领目录。要从文件系统中清理项目上传文件:
{{< tabs >}}
{{< tab title=”Linux 软件包 (Omnibus)” >}}
sudo gitlab-rake gitlab:cleanup:project_uploads
{{< /tab >}}
{{< tab title=”自编译 (source)” >}}
bundle exec rake gitlab:cleanup:project_uploads RAILS_ENV=production
{{< /tab >}}
{{< /tabs >}}
示例输出:
$ 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 数据库中不存在,则将其移动到失物招领目录。要从对象存储中清理项目上传文件:
{{< tabs >}}
{{< tab title=”Linux 软件包 (Omnibus)” >}}
sudo gitlab-rake gitlab:cleanup:remote_upload_files
{{< /tab >}}
{{< tab title=”自编译 (source)” >}}
bundle exec rake gitlab:cleanup:remote_upload_files RAILS_ENV=production
{{< /tab >}}
{{< /tabs >}}
示例输出:
$ 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
删除孤立的产物文件
{{< alert type=”note” >}}
这些命令不适用于存储在对象存储上的产物。
{{< /alert >}}
当你注意到磁盘上有比预期更多的作业产物文件和/或目录时,你可以运行:
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 查找密钥
要删除过期的 ActiveSession 查找密钥:
{{< tabs >}}
{{< tab title=”Linux 软件包 (Omnibus)” >}}
sudo gitlab-rake gitlab:cleanup:sessions:active_sessions_lookup_keys
{{< /tab >}}
{{< tab title=”自编译 (source)” >}}
bundle exec rake gitlab:cleanup:sessions:active_sessions_lookup_keys RAILS_ENV=production
{{< /tab >}}
{{< /tabs >}}
容器镜像仓库垃圾收集
容器镜像仓库可能会使用大量磁盘空间。为了清理未使用的层,注册表包含一个垃圾收集命令。