File indexing completed on 2024-07-21 04:36:26

0001 #!/bin/bash
0002 #
0003 # make a copy of KMyMoney files in a 'safe' directory whenever
0004 # the contents of the original changed since the last run of this program.
0005 # In order to make it work for you, please modify the parameters
0006 # and erase the line following it.
0007 #
0008 # in order to automate the process, I entered the following two lines
0009 # into my crontab using 'crontab -e'
0010 #
0011 #   # make a copy of the valuable KMyMoney data every 20 minutes
0012 #   */20 * * * * /home/thb/bin/kmm-safe
0013 #
0014 # (C) 2005 by Thomas Baumgart (ipwizard at users.sourceforge.net)
0015 
0016 # DATA_FILES="$HOME/thb.xml $HOME/thb.kmy"
0017 DATA_FILES="$HOME/thb.kmy"
0018 SAFE_DIR="$HOME/kmymoney-safe"
0019 DATE_FORM="%Y-%m-%d-%H-%M-%S"
0020 
0021 echo "Please configure to your likings and comment these two lines"
0022 exit 1
0023 
0024 for i in $DATA_FILES; do
0025   NEWFN=$SAFE_DIR/`basename $i`-`date +$DATE_FORM`
0026   OLDFN=$SAFE_DIR/`basename $i`-last
0027 
0028   # check if we need to keep a copy
0029   NEEDSAVE=0
0030   if test ! -e $OLDFN; then
0031     NEEDSAVE=1
0032   fi
0033   if test $NEEDSAVE -eq 0; then
0034     CS1=`md5sum $i | cut -d' ' -f1`
0035     CS2=`md5sum $OLDFN | cut -d' ' -f1`
0036     if test $CS1 != $CS2; then
0037       NEEDSAVE=1
0038     fi
0039   fi 
0040 
0041   if test $NEEDSAVE -eq 1; then
0042     cp $i $NEWFN
0043     if test -e $OLDFN; then
0044       rm $OLDFN
0045     fi
0046     ln -s $NEWFN $OLDFN
0047   fi
0048 done
0049