[Git]主仓库与镜像仓库同步备份

参考地址
http://www.jianshu.com/p/c913ce6c3eac
http://www.thinksaas.cn/topics/0/400/400475.html
http://www.jianshu.com/p/73890374b044

主机: 192.168.0.21
备用机: 192.16.0.29
操作环境: CentOs7

主仓库实现已经配置好

git clone git@192.168.0.21:/home/data/git/gittest.git

备用仓库

添加用户

[root@localhost home]# id git
id: git:无此用户
[root@localhost home]# useradd git
[root@localhost home]# passwd git

进入/home/data/git目录

从远程仓库克隆镜像仓库

git clone -mirror git@192.168.0.21:/home/data/git/gittest.git
Paste_Image.png

更新镜像库

git remote update
Paste_Image.png

使用公钥使更新时免输密码

ssh-keygen -t rsa -C "youemail@qq.com"
ssh git@192.168.0.21 'cat >> .ssh/authorized_keys' < /root/.ssh/id_rsa.pub

再试试

git remote update
Paste_Image.png

Crontab实现定时更新

编写脚本文件

/home/data/git/sh/updategit.sh编写

#!/bin/sh
cd /home/data/git/gittest.git
git remote update >> /home/data/git/log/gitupdate.log

记得赋执行权限

chmod 755 gitupdate.sh
crontab -e
*/1 * * * * /home/data/git/sh/gitupdate.sh
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容