File: sogo-backup.sh

package info (click to toggle)
sogo 1.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 21,620 kB
  • sloc: objc: 99,218; python: 4,840; sh: 1,217; perl: 861; makefile: 132; sql: 53; php: 43; ansic: 4
file content (67 lines) | stat: -rwxr-xr-x 1,357 bytes parent folder | download | duplicates (2)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
set -o pipefail

#set -x
PROGNAME="$(basename $0)"

BACKUP_DIR=/home/sogo/backups
SOGO_TOOL=/usr/sbin/sogo-tool
DAYS_TO_KEEP="30"

DATE=$(date +%F_%H%M)
LOG="logger -t $PROGNAME -p daemon.info"

# log to stdout if on a tty
tty -s && LOG="cat -"

function initChecks {
  if [ ! -d "$BACKUP_DIR" ]; then
    mkdir -m700  -p "$BACKUP_DIR" 
    if [ $? -ne 0 ]; then
  	  echo "BACKUP_DIR doesn't exist and couldn't create it, aborting ($BACKUP_DIR)" | $LOG
  	  exit 1
    fi
  fi

  if [ ! -w "$BACKUP_DIR" ]; then
    echo "$BACKUP_DIR not writable. Aborting" | $LOG
    exit 1
  fi
}

function removeOldBackups {

  if [ ! -z $DRYRUN ]; then
    RM="echo \"not deleted\""
  else
    RM="rm -rf"
  fi
  
  echo "Deleting old backups..." | $LOG
  find ${BACKUP_DIR}/ -maxdepth 1 -type d -iname "sogo-*" -mtime "+$DAYS_TO_KEEP" -ls -exec $RM {} \; 2>&1 | $LOG
  echo "Done deleting old backups." | $LOG
}


function dumpit {
  mkdir -m700  "$BACKUP_DIR/sogo-${DATE}" 2>&1  | $LOG
  if [ $? -ne 0 ]; then
    exit 1
  fi
  $SOGO_TOOL backup "$BACKUP_DIR/sogo-${DATE}/" ALL 2>&1 | $LOG
  RC=$?
  if [ $RC -ne 0 ]; then
    echo -e "FAILED, error while dumping sogo data" | $LOG
    exit $RC
  else
    echo -e "OK: dumped sogo data" | $LOG
  fi
}

echo "$PROGNAME starting" | $LOG
initChecks
dumpit
removeOldBackups
echo "$PROGNAME exiting" | $LOG