使用git bundle进行增量备份,适用于所有分支机构 [英] Incremental backups with git bundle, for all branches

查看:196
本文介绍了使用git bundle进行增量备份,适用于所有分支机构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 git bundle

对git存储库进行增量备份的最简单方法是什么?如果我只是想备份一个分支,我可以做这样的事情:

  git bundle create foo last-backup..master 
git tag -f last-backup master

但是如果我想备份所有内容包括所有分支机构)?






回答评论中的问题:

严格地说,我不需要使用通常的Git捆绑包,只要解决方案满足以下属性即可:




  • 每个增量备份都是单个文件。我可以将它存储在某个地方,后续的增量备份无需修改此文件。

  • 文件的大小近似等于Git提交的总大小自上次备份以来。二进制文件中的更改也被有效存储。

  • 完整备份+所有增量备份包含我需要自动重建存储库的所有内容,包括所有分支。作为一个天真的例子,简单地用git仓库中最近更改过的文件构建一个tar归档文件并不能满足第二个要求,例如,如果发生了自动垃圾收集。)



    理想情况下,我还想拥有一个防白痴的系统:




    • 我几乎可以完全备份我的Git存储库以及所有最近的增量备份,并且我可以简单地从备份和存储库将是最新的。特别是,完全备份和增量备份之间是否存在部分重叠并不重要。
    • 很好,如果我只需要处理一个分支。

      解决方案

      (我们与Jukka讨论过这个问题, / b>

      预赛:


      1. 将最后一次备份的可用空间设为 backup.bundle

      2. 有一个指向 backup.bundle的远程备份



      3. 制作备份:


        1. git fetch backup - 只是为了确保我们是最新的

        2. git bundle create newbackup.bundle ^ backup / A ^ backup / BABC

          • 这意味着我们创建一个包含所有已经存在的东西bundle

          • 很容易从 refs / remote生成所需的 ^ backup / A 类型参数s / backup /

          • 同样, A 样式参数来自 refs /首页


        3. 复制 newbackup.bundle 至无论您在哪里保留备份,都可以使用 newbackup.bundle 替换 backup.bundle 所以您知道从哪里开始下一次增量备份

        恢复:


        1. 拥有一个或者为空的版本库或者代表版本库的旧版本

        2. 对于每个备份文件,依次为:


          1. git remote rm recovery

          2. git remote添加恢复<捆绑名称> ;

          3. git fetch recovery - 您需要命名远程设备才能使用


          4. 现在你应该在 refs / remotes / backup


          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 along these lines:

          git bundle create foo last-backup..master
          git tag -f last-backup master
          

          But what if I want to backup everything (including all branches)?


          To answer the questions in the comments:

          Strictly speaking, I do not need to use the usual Git bundles, as long as the solution satisfies the following properties:

          • Each incremental backup is a single file. I can store it somewhere and subsequent incremental backups do not need to modify this file.

          • The size of the file is approximately equal to the total size of Git commits since the previous backup. Changes in binary files are also efficiently stored.

          • A full backup + all incremental backups since then contain everything that I need to automatically reconstruct the repository, including all branches.

          (As a naive example, simply constructing a tar archive with recently-changed files in the git repository fails to satisfy the second requirement if, for example, automatic garbage collection has occurred.)

          And ideally I would also like to have a system that is idiot-proof:

          • I can take virtually any full backup of my Git repository, plus all recent incremental backups, and I can simply "pull" everything from the backups and the repository will be up-to-date. In particular, it does not matter if there is a partial overlap between the full backup and incremental backups.

          Git bundles satisfy all this very nicely if I only need to handle one branch.

          解决方案

          (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

          这篇关于使用git bundle进行增量备份,适用于所有分支机构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆