Incremental backups with git bundle, for all branches

后端 未结 4 1146
春和景丽
春和景丽 2020-12-05 05:20

What is the easiest way to do incremental backups of a git repository with git bundle?

If I just wanted to backup a single branch, I could do something

相关标签:
4条回答
  • 2020-12-05 05:53

    (We discussed this problem with Jukka, this is the outcome.)

    Preliminaries:

    1. Have the last backup available as backup.bundle
    2. Have a remote backup that points at backup.bundle

    Making a backup:

    1. git fetch backup – just to make sure we're up to date
    2. git bundle create newbackup.bundle ^backup/A ^backup/B A B C
      • This means we create a bundle that excludes all the stuff that was already in the bundle
      • It's easy to generate the needed ^backup/A-style arguments from refs/remotes/backup/
      • Likewise the A-style arguments are from refs/heads
    3. copy newbackup.bundle to wherever you keep your backups
    4. replace backup.bundle with newbackup.bundle so you know where to start the next incremental backup

    Recovering:

    1. Have a repository that is either empty or represents an old version of your repository
    2. For every backup file, in sequence:
      1. git remote rm recovery
      2. git remote add recovery <name-of-bundle>
      3. git fetch recovery – you need to name the remote for this to work
    3. Now you should have every branch available in refs/remotes/backup
    0 讨论(0)
  • 2020-12-05 05:54

    Seems opqdonut solution will not work, cause ^backup/A ^backup/B only points to last incremental backup. And actually need to exclude refs from all previous incremental backups.

    Need to create remotes for each of previous bundles.

    UPD: No, it should work, see Jukka comment below.

    0 讨论(0)
  • 2020-12-05 05:56

    Try using --since with --all.

    Create the first backup:

    git bundle create mybundle-all --all
    

    Do an incremental backup:

    git bundle create mybundle-inc --since=10.days --all
    

    The incremental should contain all commits on all branches that have happened in the past 10 days. Make sure the --since parameter goes back far enough or you might miss a commit. Git will also refuse to create the bundle if no commits have happened in that time-frame, so plan for that.

    0 讨论(0)
  • 2020-12-05 05:56

    You could do

    git clone --mirror <your_repo> my-backup.git
    

    It will create a bare repo with all refs.

    Then you could periodically do git push --mirror <my-backup>.

    0 讨论(0)
提交回复
热议问题