Towards a git-based backup system

published Dec 28, 2019 11:05   by admin ( last modified Dec 29, 2019 05:23 )

The following things need to be solved and I believe they are solved:

  • How to make it impossible to rewrite history on the remote, so your backup cannot be wiped from a malicious client
  • How to add all files, even those that git has never seen before
  • How to handle all merge conflicts automatically, by splitting the conflict into two files, one for each version (this is actually more for synchronization than backup)

How to make it impossible to rewrite history on the remote

Untested by me, but this can be handled by:

  • Only allowing fast forwards
  • Denying all deletes

It seems this needs to be done system-wide, so you need to dedicate a server, virtual server or container to this. And you probably need to configure it yourself, since I know of no services that would let you do this.

The settings are the following.

 git config --system receive.denyNonFastforwards true

and

 $ git config --system receive.denyDeletes true

Got that info from here: https://stackoverflow.com/questions/2085871/strategy-for-preventing-or-catching-git-history-rewrite

How to add all files, even those that git has never seen before

This is simply done with the git command:

git add -A

How to handle all merge conflicts automatically, by splitting the conflict into two files, one for each version

This can be handled by writing a custom merge tool.  According to the git docs:


    the configured command line will be invoked with $BASE set to the name of a temporary file containing the common base for the merge, if available; $LOCAL set to the name of a temporary file containing the contents of the file on the current branch; $REMOTE set to the name of a temporary file containing the contents of the file to be merged, and $MERGED set to the name of the file to which the merge tool should write the result of the merge resolution.
 

One thing that needs to be checked is what git does if two people rename the file at the same time. However this whole merge conflict matter, is actually more for synchronization. And the question is if you want that for backup? By using a de-duplicating file system it might be okay with separate repos for each device.