File: kmm-safe

package info (click to toggle)
kmymoney 5.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 62,472 kB
  • sloc: cpp: 150,812; sh: 469; python: 425; xml: 249; perl: 169; makefile: 13
file content (49 lines) | stat: -rwxr-xr-x 1,260 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#
# make a copy of KMyMoney files in a 'safe' directory whenever
# the contents of the orignal changed since the last run of this program.
# In order to make it work for you, please modify the parameters
# and erase the line following it.
#
# in order to automate the process, I entered the following two lines
# into my crontab using 'crontab -e'
#
#   # make a copy of the valuable KMyMoney data every 20 minutes
#   */20 * * * * /home/thb/bin/kmm-safe
#
# (C) 2005 by Thomas Baumgart (ipwizard at users.sourceforge.net)

# DATA_FILES="$HOME/thb.xml $HOME/thb.kmy"
DATA_FILES="$HOME/thb.kmy"
SAFE_DIR="$HOME/kmymoney-safe"
DATE_FORM="%Y-%m-%d-%H-%M-%S"

echo "Please configure to your likings and comment these two lines"
exit 1

for i in $DATA_FILES; do
  NEWFN=$SAFE_DIR/`basename $i`-`date +$DATE_FORM`
  OLDFN=$SAFE_DIR/`basename $i`-last

  # check if we need to keep a copy
  NEEDSAVE=0
  if test ! -e $OLDFN; then
    NEEDSAVE=1
  fi
  if test $NEEDSAVE -eq 0; then
    CS1=`md5sum $i | cut -d' ' -f1`
    CS2=`md5sum $OLDFN | cut -d' ' -f1`
    if test $CS1 != $CS2; then
      NEEDSAVE=1
    fi
  fi 

  if test $NEEDSAVE -eq 1; then
    cp $i $NEWFN
    if test -e $OLDFN; then
      rm $OLDFN
    fi
    ln -s $NEWFN $OLDFN
  fi
done