问题描述
使用 git bundle
?
对git存储库进行增量备份的最简单方法是什么?如果我只是想备份一个分支,我可以做这样的事情:
git bundle create foo last-backup..master
git tag -f last-backup master
但是如果我想备份所有内容包括所有分支机构)?
回答评论中的问题:
严格地说,我不需要使用通常的Git捆绑包,只要解决方案满足以下属性即可:
- 每个增量备份都是单个文件。我可以将它存储在某个地方,后续的增量备份无需修改此文件。
-
文件的大小近似等于Git提交的总大小自上次备份以来。二进制文件中的更改也被有效存储。
完整备份+所有增量备份包含我需要自动重建存储库的所有内容,包括所有分支。作为一个天真的例子,简单地用git仓库中最近更改过的文件构建一个tar归档文件并不能满足第二个要求,例如,如果发生了自动垃圾收集。) - 我几乎可以完全备份我的Git存储库以及所有最近的增量备份,并且我可以简单地从备份和存储库将是最新的。特别是,完全备份和增量备份之间是否存在部分重叠并不重要。 很好,如果我只需要处理一个分支。
- 将最后一次备份的可用空间设为
backup.bundle
- 有一个指向
backup.bundle的远程
备份
-
git fetch backup
- 只是为了确保我们是最新的 -
git bundle create newbackup.bundle ^ backup / A ^ backup / BABC
- 这意味着我们创建一个包含所有已经存在的东西bundle
- 很容易从
refs / remote生成所需的
^ backup / A
类型参数s / backup / - 同样,
A
样式参数来自refs /首页
- 复制
newbackup.bundle
至无论您在哪里保留备份,都可以使用newbackup.bundle
替换backup.bundle
所以您知道从哪里开始下一次增量备份 - 拥有一个或者为空的版本库或者代表版本库的旧版本
- 对于每个备份文件,依次为:
-
git remote rm recovery
-
git remote添加恢复<捆绑名称> ;
-
git fetch recovery
- 您需要命名远程设备才能使用
-
- 现在你应该在
refs / remotes / backup
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.
- 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.
- Have the last backup available as
backup.bundle
- Have a remote
backup
that points atbackup.bundle
git fetch backup
– just to make sure we're up to dategit 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 fromrefs/remotes/backup/
- Likewise the
A
-style arguments are fromrefs/heads
- copy
newbackup.bundle
to wherever you keep your backups - replace
backup.bundle
withnewbackup.bundle
so you know where to start the next incremental backup - Have a repository that is either empty or represents an old version of your repository
- For every backup file, in sequence:
git remote rm recovery
git remote add recovery <name-of-bundle>
git fetch recovery
– you need to name the remote for this to work
- Now you should have every branch available in
refs/remotes/backup
理想情况下,我还想拥有一个防白痴的系统:
(我们与Jukka讨论过这个问题, / b>
预赛:
制作备份:
恢复:
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:
(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:
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:
Making a backup:
Recovering:
这篇关于使用git bundle进行增量备份,适用于所有分支机构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!