How to share data across multiple machines

Jonathan Kamens jik at kamens.us
Thu Jan 30 13:59:45 EST 2014


I don't know if this will be useful to anybody, and it probably won't be 
useful to someone who self-identifies as a "computer DUMMY", but perhaps 
someone else will benefit from it.

I'm been using GnuCash since before Dropbox existed, and so I had to 
come up with my own semi-automated solution for being able to access my 
GnuCash data both at home and at work. I came up with the attached 
script, which uses SSH and rsync to deal with locking and synchronize 
data between the "master" machine it lives on and secondary machine(s) 
where I also need to run GnuCash. I've used this script both on Windows 
(Cygwin) and Linux. There's a comment at the top of the script 
explaining what it does and how to configure it for your environment.

Even now that Dropbox exists, if your GnuCash data file is very big, 
then Dropbox may not be the best way to synchronize data between 
multiple machines. Also, some people might not want to store their 
financial data unencrypted in Dropbox; I know that would make me 
uncomfortable. I believe there are some Dropbox competitors who encrypt 
the data, but of course if it's encrypted than they can't do any sort of 
meaningful delta processing when synchronizing the file, which means 
every time you modify it the whole thing needs to be transferred.

Regards,

   jik

On 01/30/2014 10:32 AM, Colin Law wrote:
> Remember please to reply to all (or reply to list) when responding. On
> this list just using Reply will only send it to the last sender.
>
> On 30 January 2014 15:06, NutHouse Granola <craig at nuthousegranola.com> wrote:
>> How to use it with GC. I guess I don't know how to direct GC to look for the files in Dropbox instead of where they use to be on my desktop folder. Directory routing issue?
> In GnuCash do File > Save As and save it in the Dropbox folder (or
> preferably a subfolder of Dropbox).    It might be a good idea to also
> re-name the original gnucash accounts file to something else in order
> to prevent you accidentally reverting to using that one at some point.
>
> On the other machine (after it has synced via dropbox) do File > Open
> and browse to the file in the Dropbox folder.  Make sure you don't
> open the accounts on both machines at the same time.
>
> Colin
>
>> Sent from my iPhone
>>
>>> On Jan 30, 2014, at 1:11 AM, Colin Law <clanlaw at gmail.com> wrote:
>>>
>>>> On 29 January 2014 23:14, Craig Boon <craig at nuthousegranola.com> wrote:
>>>> Hello:
>>>>
>>>> I have been using GnuCash on my home office desktop computer.
>>>>
>>>> I now have a laptop from which I want to access my account data remotely so i can generate invoices, retrieve reports, etc away from home.
>>>>
>>>> I have tried to do this via Dropbox, but haven't been able to figure it out.
>>> Is it the operation of dropbox that you are not able to figure out or
>>> how to use it with GC?
>>>
>>> Colin
> _______________________________________________
> gnucash-user mailing list
> gnucash-user at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> -----
> Please remember to CC this list on all your replies.
> You can do this by using Reply-To-List or Reply-All.
>
>

-------------- next part --------------
#!/bin/bash -e

# GnuCash wrapper for running GnuCash on multiple machines
#
# Copyright (c) 2014 Jonathan Kamens <jik at kamens.us>.
# Distributed under the GPL yadda yadda yadda
# http://www.gnu.org/licenses/gpl.html.

# The purpose of this script is to allow you to run GnuCash on
# multiple machines by using SSH And rsync to synchronize the data
# betweeen a "primary" machine which is where it officially lives, and
# "secondary" machines where you want to also run GnuCash. You need to
# be able to SSH to your primary machine from the secondaries in order
# for this script to work.
#
# SSH is used on the secondary machines to check if GnuCash is locked
# on the primary, and to create/delete lock files when running Gnucash
# on a secondary. Rsync is used to synchronize data from the primary
# to a secondary before running GnuCash there, and to synchronize the
# changes back to the primary afterward.
#
# Remember: You can't run GnuCash on two machines at the same time.
#
# I've used this script on Linux and on Windows under Cygwin.

# Change the following variables to configure the behavior of the
# script.
#
# Whatever "echo $HOSTNAME" prints in a shell window on the primary
# GnuCash machine. If the script detects that it is running on this
# machine, then it will run GnuCash directly rather than doing the
# whole SSH / rsync thing.
PRIMARY_HOST=jik2.kamens.brookline.ma.us
#
# The host name for the primary that the secondaries should use for
# SSH and rsync, if it's different from $PRIMARY_HOST.
SSH_HOST=$PRIMARY_HOST
#
# The path of the directory in which your GnuCash data file lives, and
# the name of the data file within that directory. The script requires
# you to use the same directory and data file name on the primary and
# all secondaries.
DATA_DIR=~/closed/finances
DATA_FILE=gnucash
#
# The GnuCash executables we should look for.
GNUCASH_EXES="/usr/bin/gnucash /c/PROGRA~1/gnucash/bin/gnucash.exe \
    /c/PROGRA~2/gnucash/bin/gnucash.exe"

# *** IMPORTANT NOTE ABOUT FAILURE RECOVERY ***
#
# You should run this script from a command window on the secondary so
# that you can see its output and make sure that it successfully
# copies data back to the primary after you quite from GnuCash.
#
# If it doesn't, then rerun the script with the argument
# "--sync-to-primary" to get it to retry the synchronization.

found=false
for GC in $GNUCASH_EXES; do
    if [ -f $GC ]; then
	found=true
	break
    fi
done
if ! $found; then
    echo "Can't find gnucash executable"
    exit 1
fi

if [ "$HOSTNAME" = "$PRIMARY_HOST" ]; then
    exec $GC "$@"
fi

SYNC_UP=false
case "$1" in
    "--sync-to-primary") shift; SYNC_UP=true ;;
    "--help") shift; echo "Usage: $0 [--help] [--sync-to-primary]"; exit ;;
esac

if [ "$TERM" != "dumb" ]; then
    echo -n -e '\033]0;'"GNUCASH"'\007'
fi


SSH='ssh -x -a'
RSYNC_SSH="$SSH -o Compression=no"

lf=$DATA_DIR/$DATA_FILE.LCK; 

if ! ssh-add -l >/dev/null 2>&1; then
    ssh-add
fi

if ! $SYNC_UP; then
    echo -n "Locking..."
    $SSH -n $SSH_HOST "echo $(hostname) $(date) > $lf.$$ && ln $lf.$$ $lf && rm $lf.$$"
    echo "done"
fi

if ! $SYNC_UP; then
    echo -n "Pulling gnucash file..."
    rsync --rsh="$RSYNC_SSH" -z $SSH_HOST:$DATA_DIR/$DATA_FILE $DATA_DIR/$DATA_FILE
    echo "done"
fi

if ! $SYNC_UP; then
    echo -n "Launching gnucash..."
    if [ "$(uname -o)" = "Cygwin" ]; then
	cd ${GC%/*}
	$GC "$(cygpath -w $DATA_DIR/$DATA_FILE)" >/dev/null 2>&1
    else
	$GC $DATA_DIR/$DATA_FILE >/dev/null 2>&1
    fi
    echo "done"

    echo -n "Stripping CRs from gnucash file..."
    dos2unix -q $DATA_DIR/$DATA_FILE
    echo "done"
fi

echo -n "Pushing gnucash file..."
rsync --rsh="$RSYNC_SSH" -z $DATA_DIR/$DATA_FILE $SSH_HOST:$DATA_DIR/$DATA_FILE
echo "done"
echo -n "Unlocking..."
$SSH -n $SSH_HOST "rm $lf"
echo "done"


More information about the gnucash-user mailing list