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:
Git bundles satisfy all this very nicely if I only need to handle one branch.
Incremental backups serve to reduce the amount of time and network workload needed to run consecutive full backups. The starting point for making an incremental backup is making one full backup first, and then only those blocks of data that have changed since the last backup job are backed up in increments.
Bundles are used for the "offline" transfer of Git objects without an active "server" sitting on the other side of the network connection. They can be used to create both incremental and full backups of a repository, and to relay the state of the references in one repository to another.
Incremental backups require one full backup to be made. Afterward, only the files that have changed since the last full backup are backed up. This means that to restore, you only need the latest full backup set and the latest differential backup set.
Use the git clone Command to Clone All Branches in Git Clone your repository with the git clone command. Then navigate to the directory where your project is located. Use the git branch command to view local branches. This command will only show you local branches.
(We discussed this problem with Jukka, this is the outcome.)
Preliminaries:
backup.bundle
backup
that points at backup.bundle
Making a backup:
git fetch backup
– just to make sure we're up to dategit bundle create newbackup.bundle ^backup/A ^backup/B A B C
^backup/A
-style arguments from refs/remotes/backup/
A
-style arguments are from refs/heads
newbackup.bundle
to wherever you keep your backupsbackup.bundle
with newbackup.bundle
so you know where to start the next incremental backupRecovering:
git remote rm recovery
git remote add recovery <name-of-bundle>
git fetch recovery
– you need to name the remote for this to workrefs/remotes/backup
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With