You can use other revision control systems but this is tested with git
If you have multiple computers with identical set-ups, or if you tend to delete important documents then using git may help. You can set-up a repository with all your configurations that can be shared to multiple computers and you can keep track of different edits of an important document.
I started testing a couple rcs's for keeping track of my home directory. bazaar,svn, and git are all simple to use but one of the deciding factors for me was the size of git's repository after repacking, it was much smaller than the others. The commands are all similar so in my opinion it comes down to personal preference and familiarity.
you need to have git installed:
sudo apt-get install git
and that is about it.
first you need to initialize the directory as a repository. This guide will be using your home directory, but you can track any directory you want.
This will create a .git directory in your home directory, if you mess up any steps you can delete this directory and start over from here. Now you will need to decide what you want to track, I don't recommend tracking large files that don't change often. To set what files and directories are excluded edit ~/.git/info/exclude here is mine.
# git-ls-files --others --exclude-from=.git/info/exclude # Lines that start with '#' are comments. # For a project mostly in C, the following would be a good set of # exclude patterns (uncomment them if you want to use them): # *.[oa] *~ tmp Cache videos music downloads
Now that your exclusions are set-up you can add all your files to be tracked. Make sure your still in your home directory then
git add .
This will add all files in your home directory that haven't been excluded. You can also only track specific files that you want by adding them individually instead of using “git add .” , I wanted to track all files just in case.
Now that your files are added you can commit them to your repository.
git commit -m "first sync"
The -m sets a message for the sync, it can be whatever you want to help keep track of what you are syncing for. I set the message to “auto sync” for automatic syncs, and whatever file I'm about to change for a manual sync. Now you have an initial copy of all your files in your home directory.
Now you can either manually track changes when you are about to make a change to a config or edit an important document. Just do another:
git add . git commit -m "your message"
from your home directory, then if something goes wrong you can revert the changes. If you want to automatically track your changes you can set up a cron job with a shell script to add and commit, I wanted notification of when a commit was happening so I wouldn't shut down the computer in the middle of a commit, so I wrote a python script, it is in two parts because the cron job doesn't have your dbus session which is needed for the notifications. Here is the first part that you run during startup (put it in your autostart), it saves your dbus session address to a file in tmp.
#!/usr/bin/env python import os path = "/tmp/" dbus = open(path + "dbus", "w") dbus.write(os.environ["DBUS_SESSION_BUS_ADDRESS"])
make sure after you save the script you make it executable(you can name it whatever you want):
chmod +x thescript.py
The second part is run by cron to actually do the commits:
#!/usr/bin/env python import os,pynotify dbus = open("/tmp/dbus").read() os.environ["DBUS_SESSION_BUS_ADDRESS"] = dbus pynotify.init("Git") n = pynotify.Notification("Git sync started") n.show() os.chdir(os.environ["HOME"]) os.popen("git add .") os.popen("git commit -m 'auto sync'") n = pynotify.Notification("Git sync finished") n.show()
chmod +x this script too. Now that you have the two parts you can set-up the cron job, I have mine run every half hour, you can run it more or less frequently depending on your needs.
now you will add a line similar to this:
0,30 * * * * /home/eric/scripts/git_home.py
changing the path to where you saved the second script. If everything went well you should now get a popup at the hour and half-hour telling you when the git sync starts and finishes.
The repository will grow over time, the easiest way to help with this is to repack your archive. This will reduce the size of your archive. From your home directory (or wichever directory tracking) run:
git repack -a -d
if you want to see the difference it makes you can run:
du -sh .git
before and after the repack to see the difference. You can set this up as a cronjob if you want as well, I haven't done it yet but may add it to the script in the future so it will notify you of a repack and how much space was saved.
If you want to restore the whole archive to an older version you can run:
this will change you back to the last checked-in version. If there is an older version you want then do:
git checkout revisionnumber
if you just want to roll back a specific file the you can do:
git checkout filename
That should be enough information to get you started with tracking changes to your home directory.