9

I often backup my laptop to an external hard drive. Is rsyncing git repos over good enough backup solution or are there any problems with this method?

dreftymac
  • 31,404
  • 26
  • 119
  • 182
DavidW
  • 5,069
  • 14
  • 46
  • 68
  • you could use something like bitbucket if you need private repos and use that as a backup... – three Feb 17 '12 at 20:43
  • @three I don't trust third parties when it comes to my source code – DavidW Feb 17 '12 at 20:45
  • well, then just rsync it to a local hard drive. Make sure in case of fire that external hard drive is not destroyed too. – three Feb 17 '12 at 20:46
  • 1
    By the way see http://stackoverflow.com/questions/13713101/rsync-exclude-according-to-gitignore-like-cvs-exclude for information on handling ignored files like build products. – Jesse Glick Mar 27 '13 at 14:02

3 Answers3

8

rsync is a good solution for this. It may be a good idea to run git gc and git repack (neither with any arguments) before doing your backup; this may significantly reduce the number of files, and increase the chance of the data not changing too much by next time. Neither will lose any data.

See Git Best Practices (by Seth Robertson) for a write-up of why doing this with git isn't such a good solution.

CodeFox
  • 3,321
  • 1
  • 29
  • 41
FauxFaux
  • 2,445
  • 16
  • 20
3

rsync is interesting if you really want to backup everything (including hooks and private files).
However:

  • it doesn't guarantee the integrity of your repo once sync'ed (ie is git still working from the rsync'ed repo?)
  • it has a higher probability of data corruption (you have to save many many files)

A nicer (and cleaner) solution would be to use git bundle (which is essentially a bar repo seen as one file).
You update your local bundle, and save rsync it to your remote media.
Except that, this time, you only "rsync" (actually a simple copy is enough) one file.
And you can directly clone or pull from that one file, that bundle.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

I have a repo I keep on hosting that I push to. If I want to work somewhere I clone it, push changes back when I'm done.

You could rsync it too, but I found it easier to clone a repo out and then use it as my main dev spot. I think using one tool might be easier, but your mileage may vary.

gmoney
  • 1,264
  • 1
  • 10
  • 12