#!/bin/sh
#  $Id: sm_disaster,v 1.5 2010/09/10 21:46:04 sesam Exp $
# ******************************************************************************
#  
#   Module    : sm_disaster
#   Copyright : (c) 2002 SEP AG G-83629 Weyarn
#   Project   : SESAM Backup Utility
#   Date      : 21.06.2008
# 
# ******************************************************************************
#
#  >>> This is a user programmable procedure <<<
#
#  >>> Dieses ist eine vom Benutzer programmierbare Prozedur <<<
#
# ******************************************************************************
# 
# Description : 
#    This procedure is called from a SESAM backup if job name contains string
#    "DISASTER" or "SESAM", e.g. "SESAM_BACKUP".
#
#    These backups should be designed to save files, which are needed to recover
#    the SESAM server itself - called disaster recovery.
#    These are the .\sesam\... directory and the LIS-directory, if it is not 
#    under .\sesam\..  .
#    Furtheron the files of the database.
#
#    SESAM sends the media label and the barcode of the used media and 
#    a valid restore command to this procedure.
#    Starting this command, the file of the currently running backup will be
#    copied back to their original places.
#
#    It is urgently recommended to sent it to several different locations to
#    keep them available in case of full crash of the SESAM server itself.
#
#    For example write them to files on other computers within your net, 
#    mail them etc. .
#                     
#      The values are as follows:
#
#         $1 = {label} {backup source} {barcode}
#         $2 = {sbc restore command}
#
#    There is already an example configured below. This works if in Sesam GUI
#    in menu line "Configratione/ Support / E-Mail-Settings" the account "sesam"
#    had been added.
#
#    It is easy to do user specified adaptations !!!
#
# ******************************************************************************
#
# Beschreibung 
#    Wird vom SESAM waehrend einer Sicherung gerufen, deren Name "DISASTER"
#    oder "SESAM" beinhaltet z.B. "SESAM_BACKUP".
#
#    Diese Sicherungen sollten Verzeichnisse kopieren, die fuer die Wieder-
#    herstellung des SESAM Servers selbst noetig sind, dem sogenannten 
#    Disaster Recovery.
#
#    Dieses sind das .\sesam\... Verzeichnis, sowie LIS-Verzeichnis, falls
#    sie nicht unter .\sesam liegen.
#    Desweiteren die Dateien der SESAM Datenbank.
#
#    SESAM sendet den Medienlabel und ggf. den Barcode des benutzten Mediums
#    und ein vollstaendiges Restaurierungskommando an diese Prozedur.
#    Startet man diese Prozedur von der Komandozeile, so werden alle Dateien 
#    der gelaufenen Sicherung wieder an ihre urspruenglichen Plaetze zurueckkopiert.
#               
#    Es wird dringendst empfohlen diese Werte in Dateien, Mails etc. auf mehrere
#    andere Rechner in ihrem Netz zu verlagern, um sie im Falle eines 
#    Systemausfalls des SESAM Servers verfuegbar zu haben.
#
#       Die Werte sind die folgenden:
#
#         $1 = {label} {backup source} {barcode}
#         $2 = {sbc restore command}
# 
#    Unten ist bereits ein Beispiel eingerichtet, bei dem im Vorfeld in der 
#    Sesam GUI im Menue unter "Konfiguration/ Support/ e-Mail-Einstellungen"
#    der Account "sesam" anzulegeni ist.
#
#    User-spezische Anpassungen sind damit leicht durchfuehrbar !!!
#
# ******************************************************************************
# 
#  Example / Beispiel
#
read_ini()
{
  source `grep -i '^sm_ini=' /etc/sesam2000.ini|cut -d"=" -f2` 2>/dev/null
}
read_ini
source ${gv_rw_ini}/sesam2000.profile > /dev/null 2>&1
echo "SEPsesam disaster information to restore SEPsesam system after data loss" > ${gv_rw_work}/disaster.tmp
echo "Media source and if existing barcode" >> ${gv_rw_work}/disaster.tmp
echo $1 >> ${gv_rw_work}/disaster.tmp
echo "Restore command to restore on command line" >> ${gv_rw_work}/disaster.tmp
echo $2 >> ${gv_rw_work}/disaster.tmp
# 
# remote copy disaster.tmp to other node via Linux mail:
# echo "Disaster values: $1 $2" | mail remoteNode!remoteUser 
# OR via SMTP interface with configured email account "sesam" in Sesam GUI
sm_smtp -A "sesam" -s "SEP sesam prepare for disaster information" -M "${gv_rw_work}/disaster.tmp"

