脚本方式同步gitlabA与B
Posted liusingbon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了脚本方式同步gitlabA与B相关的知识,希望对你有一定的参考价值。
sh脚本下载gitlab-A的代码,
exp脚本自动读入gitlab-B的用户名及密码,提交实现同步.
$ cat ai_sdk_middleware.sh
#!/bin/bash
cd /opt/gitlabmirror-repo/Faceline
git clone ssh://git@gitlab.xxxxxx.com:9022/faceline/ai_sdk_middleware.git
cp ai_sdk_middleware.exp ai_sdk_middleware/
git branch -r | grep -v ‘->‘ | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
cd ai_sdk_middleware
git fetch --all
git pull --all
echo ‘*.exp‘ >> .git/info/exclude
$ cat ai_sdk_middleware.exp
#!/usr/bin/expect -f
set user "root"
set pwd "1qaz1qaz"
spawn git remote rename origin old-origin
spawn git remote add origin http://172.16.2.42:8099/faceline/ai_sdk_middleware
spawn git push -u origin --all
expect "Username*"
send "$user "
expect "Password*"
send "$pwd "
expect eof
spawn git push origin --tags --force
expect "Username*"
send "$user "
expect "Password*"
send "$pwd "
expect eof
定时同步:
* 6 * * * /opt/gitlabmirror-repo/Faceline/ai_sdk_middleware.sh && cd /opt/gitlabmirror-repo/Faceline/ai_sdk_middleware && /usr/bin/expect -f ai_sdk_middleware.exp >/dev/null 2>&1
结束。
以上是关于脚本方式同步gitlabA与B的主要内容,如果未能解决你的问题,请参考以下文章