Bug fix; the "month of the key" is 6 characters from index 0
[rrq/buckap.git] / duplicity-daily
1 #!/bin/bash
2 #
3 # Backup directories daily. Configuration at /etc/duplicity-daily
4
5 # Requires dupltool
6 [ -x /usr/bin/dupltool ] || exit 0
7
8 CONFIG=/etc/duplicity-daily.conf
9 grep -q ^ENABLE=yes $CONFIG || exit 0
10
11 # Detail backup options
12 OPTIONS=( $(grep ^OPTIONS= $CONFIG | sed 's/^OPTIONS=//') )
13
14 # The default backup target
15 TARGET="$(grep ^TARGET= -m1 $CONFIG | sed 's/^TARGET=//')"
16
17 # Backup lines start with full path, optionally with =target
18 # No spaces in pathname or target, e.g.
19 # /home
20 # /opt/other/x=user@host/backup/x
21
22 SRCS=( $(grep ^/ $CONFIG) )
23
24 # add --exlude option for any path of $SRCS that extends $1
25 excludes() {
26     local SRC X
27     for SRC in "${SRCS[@]}" ; do
28         SRC=${SRC%%=*}
29         [ "$SRC" = "$1" ] && continue
30         [ -z "${SRC%$1*}" ] && echo -n " --exclude $SRC"
31     done
32 }
33
34 for SRC in "${SRCS[@]}" ; do
35     if [ "${SRC#*=}" = "$SRC" ] ; then
36         DST=$TARGET$SRC
37     else
38         DST="${SRC##*=}"
39         SRC="${SRC%%=*}"
40     fi
41     echo "** Backing up $SRC to $DST" 
42     echo dupltool $(excludes "$SRC") ${OPTIONS[*]} $SRC pexpect+scp://$DST
43     dupltool $(excludes "$SRC") ${OPTIONS[*]} $SRC pexpect+scp://$DST
44 done |& logger -t backup