Ubuntu系统与GitLab数据同步主要有以下两种场景及方法:
备份源服务器数据
在源服务器执行备份命令,生成包含仓库、配置、数据库的压缩包:
sudo gitlab-rake gitlab:backup:create
备份文件默认存放在/var/opt/gitlab/backups目录。
传输备份文件到目标服务器
使用scp命令将备份文件复制到目标服务器对应目录:
scp /var/opt/gitlab/backups/*.tar user@目标服务器:/var/opt/gitlab/backups/
恢复数据到目标服务器
sudo gitlab-ctl stop unicorn sidekiq
sudo gitlab-rake gitlab:backup:restore BACKUP=备份文件名
sudo gitlab-ctl start
main),保存后自动完成同步。git remote add gitlab git@gitlab.com:用户名/仓库.git
cron):# 示例脚本:同步main分支
git fetch origin main
git push gitlab main
crontab -e
# 添加以下内容
0 * * * * /path/to/sync_script.sh
.gitlab-ci.yml中配置同步任务:sync_to_gitlab:
script:
- git remote add target https://用户名:令牌@gitlab.com/目标仓库.git
- git push target $CI_COMMIT_REF_NAME
only:
- main # 仅同步指定分支