Good to Know Database

Shell Skript: Cyrus Backup Script for Raspbian Jessie


Mit diesem Shell Skript können Sie ein Backup ihrer Cyrus-Postfächer erstellen. Bevor Sie das Skript ausführen, sollten Sie den Backuppfad anpassen. Zum Wiederherstellen des erstellten Backups dient das Cyrus Recovery Script for Raspbian Jessie.

###########################################################################
##                                                                       ##
##                Cyrus Backup Script for Raspbian Jessie                ##
##                                                                       ##
## Creation:    16.06.2005                                               ##
## Last Update: 25.06.2016                                               ##
##                                                                       ##
## Copyright (c) 2004-2016 by Georg Kainzbauer <http://www.gtkdb.de>     ##
##                                                                       ##
## This program is free software; you can redistribute it and/or modify  ##
## it under the terms of the GNU General Public License as published by  ##
## the Free Software Foundation; either version 2 of the License, or     ##
## (at your option) any later version.                                   ##
##                                                                       ##
###########################################################################
#!/bin/bash

# Location of the backup directory
BACKUPDIR=/data/backup/cyrus/

# Name of the backup archive
BACKUPFILE=cyrus_backup_`date +%Y%m%d%H%M`.tar.bz2

# Path of the Cyrus spool and account directory
SPOOLDIR=/var/spool/cyrus
ACCOUNTINGDIR=/var/lib/cyrus/user

# Log file
LOGFILE=/var/log/cyrus_backup.log

# Lock file
LOCK=/var/tmp/cyrus_backup.lock

###################################################################
# NORMALLY THERE IS NO NEED TO CHANGE ANYTHING BELOW THIS COMMENT #
###################################################################

function log()
{
  echo `date +%d.%m.%Y%t%H:%M:%S` "    LOG:" $1 | tee -a ${LOGFILE}
}

function error()
{
  echo `date +%d.%m.%Y%t%H:%M:%S` "    ERROR:" $1 | tee -a ${LOGFILE}
  exit 1
}

if [ -f ${LOCK} ] ; then
  error "Lockfile ${LOCK} exists."
fi

touch ${LOCK}

if [ ! -d ${BACKUPDIR} ] ; then
  log "Creating backup directory"
  mkdir -p ${BACKUPDIR}
fi

log "Suspending mail system"
echo "Server Suspended ..." > /var/lib/cyrus/msg/shutdown

log "Starting backup process"
umask 066
if [ -z "$(cat /etc/passwd | grep ^cyrus | grep /sbin/nologin$)" ] ; then
  su - cyrus -c "/usr/lib/cyrus/bin/ctl_mboxlist -d" > /var/tmp/mailboxlist.txt
else
  usermod -s /bin/bash cyrus
  su - cyrus -c "/usr/lib/cyrus/bin/ctl_mboxlist -d" > /var/tmp/mailboxlist.txt
  usermod -s /sbin/nologin cyrus
fi
tar cjpf ${BACKUPDIR}${BACKUPFILE} ${SPOOLDIR} ${ACCOUNTINGDIR} /var/tmp/mailboxlist.txt
rm -f /var/tmp/mailboxlist.txt

log "Resuming mail system"
rm -f /var/lib/cyrus/msg/shutdown
postqueue -f

rm -f ${LOCK}

exit 0


Dieser Eintrag wurde am 31.07.2016 erstellt.

Direkter Link zu dieser Seite: http://www.gtkdb.de/index_36_2802.html

[ Zur Startseite ]   [ Zur Kategorie ]


Valid XHTML 1.0 Transitional Valid CSS Valid Atom 1.0

© 2004-2018 by Georg Kainzbauer