Retro-Put Backup Directories to git as Historical Commits

By Xah Lee. Date:

This page shows you how to put your backup directories into a git repository as historical commits.

Problem

Suppose you have several backup dirs like this:

web_backup_2012-03-07
web_backup_2012-06-03
web_backup_2012-06-21
web_backup_2012-06-25
web_backup_2012-07-02
web_backup_2012-07-15
web_backup_2012-07-21

Now you want to put them on git, where each backup should become commit of corresponding date. What's the best way? (each backup is about 1.1 G, 20k files.)

Solution

① cd to the oldest dir.

② then do:

git init
git add -A
git commit -m "Backup date."
git tag "date"

Now, it'll create a .git dir in it.

③ Move the .git dir to the second dir. cd to it. Then do:

git add -A
git commit -m "Backup date."
git tag "date"

④ Repeat.

Here's a bash script to do it:

#!/bin/bash
git init
GIT_DIR=$(pwd)
for dir in $(find . -maxdepth 1 -name web_backup_\* | sort); do
  pushd $dir
  git add -A
  git commit -m "Backup for $dir."
  git tag $dir
  popd
done

This answer is provided by Jeff Bowman. Thanks Jeff.

Reference: [retro create a git repository from backup dirs By Jeff Bowman. At http://stackoverflow.com/questions/12697617/retro-create-a-git-repository-from-backup-dirs/12697950 , accessed on 2012-10-02 ]

[see Git Basics]

If you have a question, put $5 at patreon and message me.