Journey to a backup solution: Git
After a while playing with rsync, I realized that I need version control on my files to make the backup painless as possible. Since I have a department server account and my laptop, I wanted a system which is truly distributed and also support version control. The answer was “Git”. I will not explain why git is so fantastic, I think the author of the program, Linus Torvalds, knows better than me, and you can listen to his talk given at Google.
Instead of telling you how wonderful it is, I will show you how to use it. (In fact, this post is motivated by my friend who wants to use it.) Like me, I guess most of you would have a personal computer, and an account from your department. While on your PC, you can do anything, usually this is not allowed at your department’s server. (If it is, then I envy you! And also I must say poor IT people in your department.) Git can be installed locally on your department server account.
1. Installing git locally on your account.
I think the easiest way to do this is download the source files from the git homepage. Google git, and you can find it on the first page. After unpacking we need to compile the source and install it. In the git directory, type the following commands.
./configure –prefix=$HOME (press enter to configure and check the system)
make (press enter to compile)
make install (press enter to install)
By these three commands, git will be installed in ~/bin. It will be convenient to put ~/bin in your path environment, you can set that up by using any config file that does the job and it also depends on which distro you are using. My department uses Debian and I cannot edit .bashrc directly so I made a .bashrc-user file in my home directory and added the following in .bashrc-user file:
PATH=~/bin:$PATH
If you type in git, and if it gives some output, then you are ready to go.
2. Installing git on your PC
Since it is your PC, I assume you have root access on it. Use your package manager: if you are using Ubuntu it will be synaptic, search for git and install it. I use SUSE and installed it through YaST. You can also install it on a Mac by using mac port or by compiling it like on the server.
3. Making a git repository
Now, let’s tell git which files it should take care of. First of all we need to make a repository. Use the following command in the directory you want to keep track of:
git init
We need to add the files to the repository. I only ask it to track my tex files. The command that does this is:
git add file1.tex file2.tex
Instead of giving it some file names, you can put an entire directory in to the repository by typing “git add .” (note that the . stands for current directory.) Now since git knows which files it should keep track of, let’s tell it to make a snapshot, this is called committing.
git commit -a
-a option makes git automatically search for changed files. After giving it some comments, like what you did and so on, git will record the current state of the files. The comments are helpful when viewing the history of the repository, using “git log” command.
4. Copying it to the other computer
In my case, I made the original git repository in my department server, and cloned it on my laptop. It is easy to do this, on your laptop type:
git clone id@server.address ~/directory/on/laptop
By this command, the files tracked by git on the server will be copied to your laptop. Now, you can use the files on your laptop, edit and save. After modifying the files on your laptop, it is wise to notify git that you want git to record the changes by using the commit command, i.e., git commit -a.
5. pulling files.
Whenever, you have changed the files and committed them on either of the computers, you can always update the files on the otherside by using git’s pull command. Say that you are on the server and want to update the files to the last version committed on the laptop, you simply type the following at the git repository directory:
git pull id@laptop.address
6. Remarks
Git is a distributed revision control system, so in principle, the server and the laptop has the same rights. This is different from central version control system like CVS or subversion. Since this is a very brief walk through, I advise you to read the git manual or the official tutorial
7. References
Tutorial: http://www.kernel.org/pub/software/scm/git/docs/tutorial.html
Everyday git: http://www.kernel.org/pub/software/scm/git/docs/everyday.html
Manual: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html






Git is awesome.
But when keeping backups in git you should note that it will not preserve permission bits or ownership. Have a look at etckeeper if you want to keep track of /etc.
git://git.debian.org/git/users/vanicat/etckeeper.git
Thanks for the nice comment! I think someone out there will find this very useful. I personally only backup my TeX files! But maybe I should backup my configuration files, too.
I use the same procedure to backup my .tex files. However, I use a “bare” git repository as the mother repository, even for my copy at the department computer.
The advantage of this is that I can then easily push changes (git-push) I have made both on my laptop and the department computer. As my laptop gets different IPs each time I connect, this is a nice time saver for me since I don’t have to find out my laptop’s IP each time I connect.
[...] Git as a Backup Solution [...]
[MCR] Backup « .square said this on January 16, 2009 at 1:24 pm |