Changeset 1805

Show
Ignore:
Timestamp:
01/09/2007 21:57:13 (16 months ago)
Author:
chris
Message:

Call the notify script whenever backup starts or finishes, but the
default script does nothing in this case. Requested by
scott <scott@…>. (merges [1804])

Location:
box/chris/general/bin/bbackupd
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • box/chris/general/bin/bbackupd/BackupClientDirectoryRecord.cpp

    r1781 r1805  
    888888                                        // Connection errors should just be passed on to the main handler, retries 
    889889                                        // would probably just cause more problems. 
    890                                         // Already logged by UploadFile 
     890                                        rParams.GetProgressNotifier() 
     891                                                .NotifyFileUploadException( 
     892                                                        this, filename, e); 
    891893                                        throw; 
    892894                                } 
  • box/chris/general/bin/bbackupd/BackupDaemon.cpp

    r1746 r1805  
    904904                                DeleteUnusedRootDirEntries(clientContext); 
    905905                                                                 
     906                                // Notify administrator 
     907                                NotifySysadmin(NotifyEvent_BackupStart); 
     908 
    906909                                // Go through the records, syncing them 
    907910                                for(std::vector<Location *>::const_iterator  
     
    986989                                // Log 
    987990                                BOX_NOTICE("Finished scan of local files"); 
     991 
     992                                // Notify administrator 
     993                                NotifySysadmin(NotifyEvent_BackupFinish); 
    988994 
    989995                                // -------------------------------------------------------------------------------------------- 
     
    22162222// Function 
    22172223//              Name:    BackupDaemon::NotifySysadmin(int) 
    2218 //              Purpose: Run the script to tell the sysadmin about events which need attention. 
     2224//              Purpose: Run the script to tell the sysadmin about events 
     2225//                       which need attention. 
    22192226//              Created: 25/2/04 
    22202227// 
     
    22272234                "read-error",  
    22282235                "backup-error", 
     2236                "backup-start", 
     2237                "backup-finish", 
    22292238                0 
    22302239        }; 
    22312240 
     2241        BOX_TRACE("sizeof(sEventNames)  == " << sizeof(sEventNames)); 
     2242        BOX_TRACE("sizeof(*sEventNames) == " << sizeof(*sEventNames)); 
     2243        BOX_TRACE("NotifyEvent__MAX == " << NotifyEvent__MAX); 
     2244        ASSERT((sizeof(sEventNames)/sizeof(*sEventNames)) == NotifyEvent__MAX + 1); 
     2245 
    22322246        BOX_TRACE("BackupDaemon::NotifySysadmin() called, event = " <<  
    22332247                sEventNames[Event]); 
     
    22352249        if(Event < 0 || Event >= NotifyEvent__MAX) 
    22362250        { 
    2237                 THROW_EXCEPTION(BackupStoreException, BadNotifySysadminEventCode); 
     2251                THROW_EXCEPTION(BackupStoreException, 
     2252                        BadNotifySysadminEventCode); 
    22382253        } 
    22392254 
    22402255        // Don't send lots of repeated messages 
    2241         if(mNotificationsSent[Event]) 
    2242         { 
     2256        if(mNotificationsSent[Event] && 
     2257                Event != NotifyEvent_BackupStart && 
     2258                Event != NotifyEvent_BackupFinish) 
     2259        { 
     2260                BOX_WARNING("Suppressing duplicate notification about " << 
     2261                        sEventNames[Event]); 
    22432262                return; 
    22442263        } 
     
    22462265        // Is there a notifation script? 
    22472266        const Configuration &conf(GetConfiguration()); 
    2248         if(!conf.KeyExists("NotifyScript")) 
     2267        if(!conf.KeyExists("NotifyScript") && 
     2268                Event != NotifyEvent_BackupStart && 
     2269                Event != NotifyEvent_BackupFinish) 
    22492270        { 
    22502271                // Log, and then return 
     
    22562277 
    22572278        // Script to run 
    2258         std::string script(conf.GetKeyValue("NotifyScript") + ' ' + sEventNames[Event]); 
     2279        std::string script(conf.GetKeyValue("NotifyScript") + ' ' + 
     2280                sEventNames[Event]); 
    22592281         
    22602282        // Log what we're about to do 
     
    22702292        } 
    22712293 
    2272         // Flag that this is done so the administrator isn't constantly bombarded with lots of errors 
     2294        // Flag that this is done so the administrator isn't constantly 
     2295        // bombarded with lots of errors 
    22732296        mNotificationsSent[Event] = true; 
    22742297} 
  • box/chris/general/bin/bbackupd/BackupDaemon.h

    r1781 r1805  
    8686                NotifyEvent_ReadError, 
    8787                NotifyEvent_BackupError, 
     88                NotifyEvent_BackupStart, 
     89                NotifyEvent_BackupFinish, 
    8890                NotifyEvent__MAX 
    8991                // When adding notifications, remember to add strings to NotifySysadmin() 
  • box/chris/general/bin/bbackupd/bbackupd-config.in

    r1800 r1805  
    212212#!/bin/sh 
    213213 
     214# This script is run whenever bbackupd changes state or encounters a 
     215# problem which requires the system administrator to assist: 
     216# 
     217# 1) The store is full, and no more data can be uploaded. 
     218# 2) Some files or directories were not readable. 
     219# 3) A backup run starts or finishes. 
     220# 
     221# The default script emails the system administrator, except for backups 
     222# starting and stopping, where it does nothing. 
     223 
    214224SUBJECT="BACKUP PROBLEM on host $hostname" 
    215225SENDTO="$current_username" 
    216226 
    217 if [ \$1 = store-full ] 
    218 then 
    219 $sendmail \$SENDTO <<EOM 
     227if [ "\$1" = "" ]; then 
     228        echo "Usage: $0 <store-full|read-error|backup-error|backup-start|backup-finish>" >&2 
     229        exit 2 
     230elif [ "\$1" = store-full ]; then 
     231        $sendmail \$SENDTO <<EOM 
    220232Subject: \$SUBJECT (store full) 
    221233To: \$SENDTO 
     
    231243 
    232244EOM 
    233 elif [ \$1 = read-error ] 
    234 then 
     245elif [ "\$1" = read-error ]; then 
    235246$sendmail \$SENDTO <<EOM 
    236247Subject: \$SUBJECT (read errors) 
     
    245256 
    246257Check the logs on $hostname for the files and directories which caused 
    247 these errors, and take appropraite action. 
     258these errors, and take appropriate action. 
    248259 
    249260Other files are being backed up. 
    250261 
    251262EOM 
     263elif [ "\$1" = backup-start -o "\$1" = backup-finish ]; then 
     264        # do nothing by default 
     265        true 
    252266else 
    253267$sendmail \$SENDTO <<EOM 
     
    288302 
    289303 
    290 # This script is run whenever bbackupd encounters a problem which requires 
    291 # the system administrator to assist: 
     304# This script is run whenever bbackupd changes state or encounters a 
     305# problem which requires the system administrator to assist: 
     306# 
    292307# 1) The store is full, and no more data can be uploaded. 
    293308# 2) Some files or directories were not readable. 
    294 # The default script emails the system administrator. 
     309# 3) A backup run starts or finishes. 
     310# 
     311# The default script emails the system administrator, except for backups 
     312# starting and stopping, where it does nothing. 
    295313 
    296314NotifyScript = $notify_script 
     
    303321        print CONFIG <<__E; 
    304322 
    305 # The number of seconds between backup runs under normal conditions. A scan To  
    306 # avoid cycles of load on the server, this time is randomly adjusted by a  
    307 # small percentage as the daemon runs. 
     323# The number of seconds between backup runs under normal conditions. To avoid  
     324# cycles of load on the server, this time is randomly adjusted by a small  
     325# percentage as the daemon runs. 
    308326 
    309327UpdateStoreInterval = 3600