从零开始devops-gitlab使用mirror实现热备

背景:现在有两套GITLAB环境,假设一个为A,一个为B,现在需要把A上的TEST项目同步到B上的TEST,且A上的TEST项目每次PUSH后就会触发同步代码到B上的TEST项目
一、在B上创建一个与A同名的项目TEST(过程省略)
二、在A上TEST项目设置
在这里插入图片描述
在这里插入图片描述

Git repository URL #B上test项目的地址:https://访问B的gitlab用户名@test项目地址
Password #登陆B的gitlab密码
Only mirror protected branches #只同步保护的分支,勾选此项会在push后的1分钟内触发同步,如不勾选,会在5分钟内触发

三、查看受保护的分支
在这里插入图片描述
在这里插入图片描述

注意
两次更新时间至少相隔5分钟,如10:10分进行了同步,即使你在10:12进行了push,那么下次同步最快也得在10:15后开始

Project remote mirrors API
Push mirrors defined on a project’s repository settings are called “remote mirrors”, and the state of these mirrors can be queried and modified via the remote mirror API outlined below.

List a project’s remote mirrors
Introduced in GitLab 12.9.

Returns an Array of remote mirrors and their statuses:

GET /projects/:id/remote_mirrors

Example request:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/remote_mirrors"

Example response:

[
{
"enabled": true,
"id": 101486,
"last_error": null,
"last_successful_update_at": "2020-01-06T17:32:02.823Z",
"last_update_at": "2020-01-06T17:32:02.823Z",
"last_update_started_at": "2020-01-06T17:31:55.864Z",
"only_protected_branches": true,
"keep_divergent_refs": true,
"update_status": "finished",
"url": "https://:@gitlab.com/gitlab-org/security/gitlab.git"
}
]

For security reasons, the url attribute will always be scrubbed of username and password information.
Create a remote mirror
Introduced in GitLab 12.9.

Create a remote mirror for a project. The mirror will be disabled by default. You can enable it by including the optional parameter enabled when creating it:

POST /projects/:id/remote_mirrors

Attribute Type Required Description
url String yes The URL of the remote repository to be mirrored.
enabled Boolean no Determines if the mirror is enabled.
only_protected_branches Boolean no Determines if only protected branches are mirrored.
keep_divergent_refs Boolean no Determines if divergent refs are skipped.
Example request:

curl --request POST --data "url=https://username:token@example.com/gitlab/example.git" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/remote_mirrors"

Example response:

{
"enabled": false,
"id": 101486,
"last_error": null,
"last_successful_update_at": null,
"last_update_at": null,
"last_update_started_at": null,
"only_protected_branches": false,
"keep_divergent_refs": false,
"update_status": "none",
"url": "https://:@example.com/gitlab/example.git"
}

Update a remote mirror’s attributes
Introduced in GitLab 12.9.

Toggle a remote mirror on or off, or change which types of branches are mirrored:

PUT /projects/:id/remote_mirrors/:mirror_id

Attribute Type Required Description
mirror_id Integer yes The remote mirror ID.
enabled Boolean no Determines if the mirror is enabled.
only_protected_branches Boolean no Determines if only protected branches are mirrored.
keep_divergent_refs Boolean no Determines if divergent refs are skipped.
Example request:

curl --request PUT --data "enabled=false" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/remote_mirrors/101486"

Example response:

{
"enabled": false,
"id": 101486,
"last_error": null,
"last_successful_update_at": "2020-01-06T17:32:02.823Z",
"last_update_at": "2020-01-06T17:32:02.823Z",
"last_update_started_at": "2020-01-06T17:31:55.864Z",
"only_protected_branches": true,
"keep_divergent_refs": true,
"update_status": "finished",
"url": "https://:@gitlab.com/gitlab-org/security/gitlab.git"
}

posted @ 2020-12-18 09:33  于欣轩  阅读(946)  评论(0编辑  收藏  举报