Ivor O’Connor

September 19, 2009

Replacing Unison With Git

Filed under: Uncategorized — ioconnor @ 4:55 pm

Unison works across M$, Macs, and *nix machines. Unison synchronizes files between two machines. Git is not made for synchronizing files between two machines but it can be made to do so. It supposedly works on multiple platforms just like Unison does. In addition it does version control and keeps track of file and directory name changes along with files you delete. More importantly you can keep multiple machines in sync, not just two. I use the following two scripts, run from cron, on the machines I want kept in sync:
A script to pull in the changes somebody has made followed by a script to push out the changes. I should make a master script to do one right after the other. Perhaps also some monitor program that can pop-up to tell me when I need to do a three way merge.  (I haven’t needed these additions yet.)
The script to pull in the changes:

#!/bin/bash

# GLOBALS
sGitLogFile=~/common-git.log
sPathToLocalDir=~/common
sPathToRemoteGit=…

function doGitPull {
cd $sPathToLocalDir >> $sGitLogFile 2>&1
#pwd >> $sGitLogFile 2>&1
#whoami >> $sGitLogFile 2>&1
#printenv >> $sGitLogFile 2>&1
git pull –verbose $sPathToRemoteGit HEAD >> $sGitLogFile 2>&1
}

echo “{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{” >> $sGitLogFile 2>&1 # Time stamp the end of processing
echo $(date +%F[%T]) ” = STARTING TIME of pull” >> $sGitLogFile 2>&1 # Time stamp the start of processing
doGitPull
echo $(date +%F[%T]) ” = ENDING TIME of pull” >> $sGitLogFile 2>&1 # Time stamp the end of processing
echo “}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}” >> $sGitLogFile 2>&1 # Time stamp the end of processing
echo “” >> $sGitLogFile 2>&1 # Time stamp the end of processing

A script to push the changes out:

#!/bin/bash

# GLOBALS
sGitLogFile=~/common-git.log
sPathToLocalDir=~/common
sPathToRemoteGit=….

function doGitPush {
cd $sPathToLocalDir >> $sGitLogFile 2>&1
git add –verbose -A >> $sGitLogFile 2>&1
git commit –verbose -m”bkup” >> $sGitLogFile 2>&1
git push –verbose $sPathToRemoteGit master –receive-pack=’git receive-pack’ >> $sGitLogFile 2>&1
}

echo “{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{” >> $sGitLogFile 2>&1
echo $(date +%F[%T]) ” = STARTING TIME of common-push ” >> $sGitLogFile 2>&1 # Time stamp the start of processing
doGitPush >> $sGitLogFile 2>&1
echo $(date +%F[%T]) ” = ENDING TIME of common-push\n\n\n” >> $sGitLogFile 2>&1 # Time stamp the end of processing
echo “}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}” >> $sGitLogFile 2>&1

Advertisements

5 Comments »

  1. I’ve been using Unison for the past while to keep several computers in sync – via one server. I have been considering git as an alternative though, for the very reasons you mention (tracking of renaming and version control). Have you continued this (the article seems to be a few years old) and do you have any experience worth sharing about the whether this was a good idea?

    How big is the groups of files you are syncing?

    Comment by Rasmus Hedin — September 20, 2012 @ 7:36 am

    • No, I discontinued it about six months ago. Every once in a while it would get messed up because of file protection issues. I was syncing about 80GBs this way. I’ll probably go back to it in the future but for now I’m just syncing a few working directories with rsync since the majority doesn’t change and it’s on several computers with git.

      I just haven’t had the time. I am behind on so many different fronts. When I return to using git for backup I’ll also change the log files every month or week. They have a tendency to pile up. And I will put in an auto emailer so that when the log files do have an error I’ll look into it immediately.

      Comment by ioconnor — September 20, 2012 @ 1:46 pm

      • I hear you, these things takes a lot of time.

        I think it’s a bit unfortunate that there seems to be at least a couple of dussin of similar projects ppl are running seriously enough to write about them but noone seem to have gotten it all the way.

        ::R

        Comment by Rasmus Hedin — October 13, 2012 @ 8:02 pm

        • I’m looking at lipsync and sparkleshare http://www.linuxjournal.com/content/drop-your-dropbox-and-sparkleshare. Maybe with git on top of sparkleshare?

          Comment by ioconnor — October 13, 2012 @ 10:31 pm

          • I’ve read about that sparkleshare in earlier days as well. I think that was one of the ones I did think of for alternatives that never got far enough – when I looked last time it seemed stalled and not far enough. But yes it could be exactly what’s needed and perhaps contributing there is a useful way of spending the time.

            Sparkleshare is by default as I understand it using git, but allowing for plugged in different back ends – and lipsync phil is mentioning that there might be a way of integrating lipsync as an alternative back end.

            Comment by Rasmus Hedin — October 14, 2012 @ 9:19 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: