Good to Know Database

Shell Skript: Cyrus Recovery Script for Raspbian Jessie


Mit diesem Shell Skript können Sie ein Cyrus-Backup (siehe Cyrus Backup Script for Raspbian Jessie) wiederherstellen. Beim Aufruf des Skripts geben Sie das Backuparchiv als Argument an.

###########################################################################
##                                                                       ##
##               Cyrus Recovery Script for Raspbian Jessie               ##
##                                                                       ##
## Creation:    16.06.2005                                               ##
## Last Update: 05.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

# Path to the backup archive
BACKUPFILE=$1

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

# Lock file
LOCK=/var/tmp/cyrus_recovery.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 [ -z ${BACKUPFILE} ] ; then
  error "Please specify backup archive."
fi

if [ ! -f ${BACKUPFILE} ] ; then
  error "Backup archive ${BACKUPFILE} does not exist."
fi

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

touch ${LOCK}

log "Shutting down mail system"
/etc/init.d/fetchmail stop
/etc/init.d/postfix stop
/etc/init.d/cyrus-imapd stop

log "Starting recovery process"
tar xjpf ${BACKUPFILE} -C /
if [ -f /var/lib/cyrus/mailboxes.db ] ; then
  rm -f /var/lib/cyrus/mailboxes.db
fi
if [ -z "$(cat /etc/passwd | grep ^cyrus | grep /sbin/nologin$)" ] ; then
  su - cyrus -c "/usr/lib/cyrus/bin/ctl_mboxlist -u" < /var/tmp/mailboxlist.txt
else
  usermod -s /bin/bash cyrus
  su - cyrus -c "/usr/lib/cyrus/bin/ctl_mboxlist -u" < /var/tmp/mailboxlist.txt
  usermod -s /sbin/nologin cyrus
fi
rm -f /var/tmp/mailboxlist.txt

log "Starting mail system"
/etc/init.d/cyrus-imapd start
/etc/init.d/postfix start
/etc/init.d/fetchmail start

rm -f ${LOCK}

exit 0


Dieser Eintrag wurde am 31.07.2016 erstellt.

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

[ Zur Startseite ]   [ Zur Kategorie ]


Valid XHTML 1.0 Transitional Valid CSS Valid Atom 1.0

© 2004-2018 by Georg Kainzbauer