diff --git a/ChangeLog b/ChangeLog index 9b3b25dae..54275283a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,12 @@ name, based on new property names. Added all new clashing properties to bannedProps. +2012-03-02 Jean Raby + + * Scripts/sogo-backup.sh: new script to automate backups. + Updated sogo.cron to include a commented out entry for sogo-backup.sh + Include updates.php in the packages + 2012-03-01 Wolfgang Sourdeau * SoObjects/SOGo/LDAPSource.m (_convertRecordToLDAPAttributes): diff --git a/Scripts/sogo-backup.sh b/Scripts/sogo-backup.sh new file mode 100755 index 000000000..58cffa445 --- /dev/null +++ b/Scripts/sogo-backup.sh @@ -0,0 +1,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 + + diff --git a/Scripts/sogo.cron b/Scripts/sogo.cron index 17b796820..350c2d50f 100644 --- a/Scripts/sogo.cron +++ b/Scripts/sogo.cron @@ -6,3 +6,10 @@ # Email alarms - runs every minutes #* * * * * sogo /usr/sbin/sogo-ealarms-notify + +# Daily backups +# - writes to /home/sogo/backups/ by default +# - will keep 31 days worth of backups by default +# - runs once a day by default, but can run more frequently +# - make sure to set the path to sogo-backup.sh correctly +#30 0 * * * sogo /usr/share/doc/sogo/sogo-backups.sh diff --git a/debian/sogo.docs b/debian/sogo.docs index 0ebd68c03..02b9d95c5 100644 --- a/debian/sogo.docs +++ b/debian/sogo.docs @@ -5,4 +5,6 @@ Scripts/sql-update-1.2.2_to_1.3.0-mysql.sh Scripts/sql-update-1.3.3_to_1.3.4.sh Scripts/sql-update-1.3.3_to_1.3.4-mysql.sh Scripts/sql-update-1.3.11_to_1.3.12.sh -Scripts/sql-update-1.3.11_to_1.3.12-mysql.sh \ No newline at end of file +Scripts/sql-update-1.3.11_to_1.3.12-mysql.sh +Scripts/sogo-backup.sh +Scripts/updates.php diff --git a/sogo.spec b/sogo.spec index 5a8e6e148..8d6a15105 100644 --- a/sogo.spec +++ b/sogo.spec @@ -234,7 +234,7 @@ rm -fr ${RPM_BUILD_ROOT} %config(noreplace) %{_sysconfdir}/cron.d/sogo %config(noreplace) %{_sysconfdir}/httpd/conf.d/SOGo.conf %config(noreplace) %{_sysconfdir}/sysconfig/sogo -%doc ChangeLog NEWS Scripts/sql*sh +%doc ChangeLog NEWS Scripts/*sh Scripts/updates.php %files -n sogo-tool %{_sbindir}/sogo-tool