git 更改数据目录 gitlab 以将 repos 存储在其他地方
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19902417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
change the data directory gitlab to store repos elsewhere
提问by Brij Raj Singh - MSFT
my basic disk is full for my gitlab installation, is it possible to move the repositories and their data to some other folder and make sure that the upcoming push's data is sent to those directories?
我的 gitlab 安装的基本磁盘已满,是否可以将存储库及其数据移动到其他文件夹并确保即将推送的数据发送到这些目录?
I tried stopping the gitlab and copying over the entire folder, but to no avail. PS - I am not an IT guy, I am just pitching in to see how could we get out of this issue; so please be verbose when answering.
我尝试停止 gitlab 并复制整个文件夹,但无济于事。PS - 我不是 IT 人员,我只是想看看我们如何摆脱这个问题;所以请在回答时详细说明。
回答by Gus E
Just updating in case people still refer to this. From the GitLab documentation:
只是更新以防人们仍然参考这个。从 GitLab文档:
By default, omnibus-gitlab stores the Git repository data under
/var/opt/gitlab/git-data
. The repositories are stored in a subfolderrepositories
. You can change the location of thegit-data
parent directory by adding the following line to/etc/gitlab/gitlab.rb
.git_data_dirs({"default" => "/mnt/nas/git-data"})
Starting from GitLab 8.10 you can also add more than one git data directory by adding the following lines to
/etc/gitlab/gitlab.rb
instead.git_data_dirs({ "default" => "/var/opt/gitlab/git-data", "alternative" => "/mnt/nas/git-data" })
Note that the target directories and any of its subpaths must not be a symlink.
Run
sudo gitlab-ctl reconfigure
for the changes to take effect.If you already have existing Git repositories in
/var/opt/gitlab/git-data
you can move them to the new location as follows:# Prevent users from writing to the repositories while you move them. sudo gitlab-ctl stop # Note there is _no_ slash behind 'repositories', but there _is_ a # slash behind 'git-data'. sudo rsync -av /var/opt/gitlab/git-data/repositories /mnt/nas/git-data/ # Fix permissions if necessary sudo gitlab-ctl reconfigure # Double-check directory layout in /mnt/nas/git-data. Expected output: # gitlab-satellites repositories sudo ls /mnt/nas/git-data/ # Done! Start GitLab and verify that you can browse through the repositories in # the web interface. sudo gitlab-ctl start
默认情况下, omnibus-gitlab 将 Git 存储库数据存储在
/var/opt/gitlab/git-data
. 存储库存储在子文件夹中repositories
。您可以git-data
通过将以下行添加到/etc/gitlab/gitlab.rb
.git_data_dirs({"default" => "/mnt/nas/git-data"})
从 GitLab 8.10 开始,您还可以通过添加以下行来添加多个 git 数据目录
/etc/gitlab/gitlab.rb
。git_data_dirs({ "default" => "/var/opt/gitlab/git-data", "alternative" => "/mnt/nas/git-data" })
请注意,目标目录及其任何子路径不能是符号链接。
运行
sudo gitlab-ctl reconfigure
以使更改生效。如果您已经有现有的 Git 存储库,
/var/opt/gitlab/git-data
您可以将它们移动到新位置,如下所示:# Prevent users from writing to the repositories while you move them. sudo gitlab-ctl stop # Note there is _no_ slash behind 'repositories', but there _is_ a # slash behind 'git-data'. sudo rsync -av /var/opt/gitlab/git-data/repositories /mnt/nas/git-data/ # Fix permissions if necessary sudo gitlab-ctl reconfigure # Double-check directory layout in /mnt/nas/git-data. Expected output: # gitlab-satellites repositories sudo ls /mnt/nas/git-data/ # Done! Start GitLab and verify that you can browse through the repositories in # the web interface. sudo gitlab-ctl start
回答by Kovah
Much easier solution for new installs with the version > 7.14.1:
版本 > 7.14.1 的新安装更简单的解决方案:
Open the gitlab.rb configuration file
打开 gitlab.rb 配置文件
sudo nano /etc/gitlab/gitlab.rb
Search for git_data_dir
, uncomment the line and set your directory here, e.g.
搜索git_data_dir
,取消注释该行并在此处设置您的目录,例如
git_data_dir "/storage/data/gitlab/git-data"
Save the file and reconfigure Gitlab:
保存文件并重新配置 Gitlab:
sudo gitlab-ctl reconfigure
回答by alastairtree
I just moved my gitlab repositories folder from one directory to another, might be useful for someone (do this quickly at a quiet time or stop gitlab beforehand!)
我刚刚将我的 gitlab 存储库文件夹从一个目录移动到另一个目录,可能对某人有用(在安静的时间快速执行此操作或事先停止 gitlab!)
Assuming you have a standard install the steps are
假设您有标准安装,步骤是
- Create a new folder for repos as root and change the owner to the git user
- Copy (with archive, recursive options) the old repo folder contents to its new home
cp -ar SOURCE DESTINATION
- Edit the gitlab config file andthe gitlab-shell config files with the new repo path
- Restart gitlab
sudo /etc/init.d/gitlab restart
- 以 root 身份为 repos 创建一个新文件夹,并将所有者更改为 git 用户
- 将旧的 repo 文件夹内容复制(使用存档、递归选项)到其新主目录
cp -ar SOURCE DESTINATION
- 使用新的 repo 路径编辑 gitlab 配置文件和gitlab-shell 配置文件
- 重启gitlab
sudo /etc/init.d/gitlab restart
回答by Rusty
If you're getting the cannot find repo
error in GitLab after running the above steps. Run this command.
如果您cannot find repo
在运行上述步骤后在 GitLab 中遇到错误。运行此命令。
gitlab-rake cache:clear RAILS_ENV=production
This should fix the issue if your pathing is correct.
如果您的路径正确,这应该可以解决问题。
回答by ThorSummoner
In my case, I needed to move a repository from the default
storage to storage1
If you load the project's general setting, it show the project number, for example 37
:
就我而言,我需要将存储库从default
存储移动到storage1
如果加载项目的常规设置,它会显示项目编号,例如37
:
sudo gitlab-rails console
irb(main):012:0> p37 = Project.find(37)
irb(main):009:0> p37.repository_storage
=> "default"
irb(main):010:0> p37.repository_storage = 'storage1'
irb(main):011:0> p37.save
=> true
irb(main):012:0> # <ctrl>+d to send EOF and exit
clearing the cache is probably a good idea too
清除缓存也可能是个好主意
回答by ThinhLP
you need append this small config bellow:
你需要在下面附加这个小配置:
git_data_dirs({
"default" => {
"path" => "/srv/gitlab/git-data"
}
})
And
和
rsync -av /var/opt/gitlab/git-data/* /srv/gitlab/git-data/.
chown -R git:git /srv/gitlab/git-data/
sudo gitlab-ctl reconfigure
Done.
完毕。