开发者

Backup gitosis repositories with rsync?

I have a standard gitosis setup that I would like to backup using rsync. When I try:

rsync -avz git@192.168.0.2:/home/git git_origin/

or

rsync -avz --rsync-path 'sudo rsync' 192.168.0.2:/home/git git_origin/

It copes no repository files. Pretty sure it has to do with how the 'git' user has no password and complete ownership of all 开发者_C百科files in it's /home/git/repositories directory structure. Since you can't 'ssh git' or 'su git' I can't achieve the correct permission level.

So, how do I use rsync to backup all my gitosis repositories?


Easiest way IMO would be to add a custom key into your authorized_keys file for the git user.

Add in an entry above the line that says ### autogenerated by gitosis, DO NOT EDIT as the root user under /home/git/.ssh/authorized_keys (on most Linux systems) and you should be good to go. Gitosis by default ignores custom entries to the authorized_keys file when regenerating it.

If you want to lock the server down more, you can always add a custom command= directive before the key entry, googling "rsync ssh lock down" gives you http://sixohthree.com/1458/locking-down-rsync-using-ssh as the first hit, which should get you started.

The only other way of grabbing the files over rsync without jumping through some random user switching hoops (as in user->root->git switches) would be to use ssh to connect as the root user and grab the files with it.

Both running as the root user and ssh'ing as the git user by providing a custom authorized_keys entry should give you the permissions you need to access the files you want to rsync.


gitolite lists rsync as one of the supported external commands that it can provide authorization for.

I have not done this but I believe you can set this up with a specific ssh key allowed to use rsync on every repository. The first step is setting $RSYNC_BASE in the gitolite.rc file. The example.conf shows how to specify permissions for rsync.

And encase you are wondering why I answered about gitolite instead of gitosis, gitosis is unmaintained, deprecated, and dead, stop using it and switch to gitolite.


I was using this script for a start for my customized scripts, and it is using

--rsync-path='sudo /usr/bin/rsync'

Maybe that could help?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜