0

I'm wondering if it is safe to use rsync to hotbackup a git server (The /home/git folder containing multiple repositories).

I'm assuming that this could introduce race conditions, but perhaps git commit is an atomic operation such that rsync either sees the files as they are before the commit or after the commit but not somewhere inbetween.

I'll provide an example as well just to make sure I'm illustrating this properly. Suppose file A and file B are being committed to one of the repositories. Rsync will either back them both up prior to the commit or after the commit. But will not backup file A before the commit, and then file B after the commit.

If using RSync is not safe an alternative would be to run a script that clones each repository to the backup server.

So for the entire server directory: 1) cd into the account 2) clone all repositories 3) cd into next account 4) clone all repositories 5) and so on...

But rsync is a lot simpler so I'm crossing my fingers :). If anyone has an even simpler option I would love to hear about that as well.

TIA, Ole

Ole
  • 41,793
  • 59
  • 191
  • 359
  • 1
    How could rsync be simpler than a post-receive hook that pushes to a backup server? Of course rsync introduces possible race conditions. I think you've acknowledged the problem, and you know the solution already, so I'm not sure why you're asking. – Mort Apr 29 '16 at 23:36
  • I think post receive hooks have to be registered per repository right? RSync introduces race conditions if commits are not atomic. From what I understand, Linus is pretty smart, so maybe he figured out a way to make commits atomic such that the state of the file system will be safe WRT to RSync backups. I'm asking to find the simplest solution period. – Ole Apr 30 '16 at 02:54
  • Keep It Simple, dude. Run `git push --mirror /path/to/archive` in your post-receive and be done with it. Not everyone knows about race conditions and efficiency and the tradeoffs involved in various kinds of atomicity guarantees, of course, just some. One of them implemented git. – jthill Apr 30 '16 at 04:54
  • If I want to do that I have to do it per repository right? I'm backing up a gogs server (http://stackoverflow.com/questions/36946751/performing-hotbackups-of-gogs) and ideally I would be able to do it all in one simple step. – Ole May 01 '16 at 05:21
  • I have not read up on `git push --mirror` yet but I'm starting to get the feeling that that is the best way to go :) – Ole May 01 '16 at 05:25
  • I'm hoping that there is a solution that allows me to backup all the respositories using a one liner. IIUC the solutions currently proposed must be administered on a per repository basis. – Ole May 01 '16 at 06:42
  • I documented what I ended up going with here: http://stackoverflow.com/questions/36946751/performing-hotbackups-of-gogs – Ole May 10 '16 at 17:08

0 Answers0