This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

Backing Up


Using Git Version Control and other strategies

 

Now that we have Git, "the stupid version control system" (according to Linus Torvalds, Git's author), we can go ahead and put it to good use. Let's first initialize our repository. We can do this one of two ways: big repo, or small repo.

Big Repository


If you're building on an 8 G USB stick like I suggested earlier, don't use the big repo, and instead skip down to the instructions for the small repo. You've only got four gigs to work with. You'll want roughly 12 gigs available for this. That's the obvious disadvantage; your repo will be huge. The advantage is that the "time machine" will keep track of literally every change you make to your system.

First, let's set up our repo. You need write permissions to your $CLFS directory.:

cd $CLFS
git init

That's it. Every time you complete a book chapter from here on out, you'll do this:

cd $CLFS
git add -A
git commit -m "completed chapter 5.9, mpfr"

Every time you want to rewind things to the last time you committed, it's

cd $CLFS
git reset --hard

And every time you want to go back in time further than that, you'll do

cd $CLFS
git log | less

You'll see a long string of hexadecimal numbers, and then the log message you left yourself earlier. Pick out the "date" you'd like to return to, copy the first eight or so numbers from that long hexadecimal string (we'll say it's 1234ABCD), and then

git reset --hard
git checkout 1234ABCD

The big repo and small repo instructrions aren't mutually exclusive, so read on if you'd like to set up another repo for your specs and sources. The big repo won't track changes in the small repo.

Small Repository


Let's initialize,

cd ~/clfs
git init

We're going to want to ignore several temporary files that get created during the build process:

cat >> .git/info/exclude << "DONE"
clfs/book/
clfs/build/
DONE

The crash course at the end of the Big Repo section should get you through here as well. If you'd like a gentle introduction to git that's a little more in depth than what I've given you, here's one:

http://thinkvitamin.com/code/starting-with-git-cheat-sheet/

If you're using a small repo and not a big repo, and you've got about 8 gigs free somewhere else, and you'd like some of the advantage of the big repo, you can back up your $CLFS fileystem.

The slow way to do that is with the dd tool. You'll notice the lack of a caution icon this time; this is a safe way to use dd. To be extra-safe, though, you'll want to do this as an ordinary user. Assuming the device you're building CLFS on is /dev/sdb1, the command would be

dd if=/dev/sdb1 of=~/backup.ext2 bs=32M

The first time you do that, you'll see the problem with it: it takes forever and hogs system resources. I mentioned it only because it works, and it's already available to you. So instead, I'd like to suggest installing yet another program, rsync. If you don't already have it, its CBLFS book page is here:

http://cblfs.cross-lfs.org/index.php/Rsync

and it has no dependencies. Rsync only copies over what's new and what's changed and skips everything else, so backing up is very fast. You can use it to create back-ups like this (assuming you're backing up to ~/clfs_backup) :

rsync -r --progress -v $CLFS ~/clfs_backup
tar jcvf ~/clfs_backup-`date '+%d%b%Y-%H:%M:%S'`.tar.bz2 ~/clfs_backup

As a bonus, you'll notice it gives you a progress bar and lets you know what's copied already. One thing I like to do when backing up this way, is to periodically transfer those tarballs to read-only media, like CDs or DVDs.

Task Discussion