[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 [email protected]:/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 [email protected]:/home/data/git/gittest.git
[Git]主仓库与镜像仓库同步备份_第1张图片
Paste_Image.png

更新镜像库

git remote update
Paste_Image.png

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

ssh-keygen -t rsa -C "[email protected]"
ssh [email protected] 'cat >> .ssh/authorized_keys' < /root/.ssh/id_rsa.pub

再试试

git remote update
[Git]主仓库与镜像仓库同步备份_第2张图片
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

你可能感兴趣的:([Git]主仓库与镜像仓库同步备份)