diff options
author | Chris Wilson <chris+github@qwirx.com> | 2007-09-01 20:56:26 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2007-09-01 20:56:26 +0000 |
commit | d2d2c47f0a4261fe53c1b3e5faba45f436b32e9e (patch) | |
tree | b1fe008ee8c9cbfd4329cfc9d7ee874185a009e2 /bin/bbackupd | |
parent | 86deff6eb3b2308ea88d78b2c4eba1208d9abfb4 (diff) |
Call the notify script whenever backup starts or finishes, but the
default script does nothing in this case. Requested by
scott <scott@lubetech.com.au>.
Diffstat (limited to 'bin/bbackupd')
-rw-r--r-- | bin/bbackupd/BackupDaemon.cpp | 35 | ||||
-rw-r--r-- | bin/bbackupd/BackupDaemon.h | 2 | ||||
-rwxr-xr-x | bin/bbackupd/bbackupd-config.in | 42 |
3 files changed, 61 insertions, 18 deletions
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp index 4d5b6fa4..46a76304 100644 --- a/bin/bbackupd/BackupDaemon.cpp +++ b/bin/bbackupd/BackupDaemon.cpp @@ -903,6 +903,9 @@ void BackupDaemon::Run2() // Delete any unused directories? DeleteUnusedRootDirEntries(clientContext); + // Notify administrator + NotifySysadmin(NotifyEvent_BackupStart); + // Go through the records, syncing them for(std::vector<Location *>::const_iterator i(mLocations.begin()); @@ -986,6 +989,9 @@ void BackupDaemon::Run2() // Log BOX_NOTICE("Finished scan of local files"); + // Notify administrator + NotifySysadmin(NotifyEvent_BackupFinish); + // -------------------------------------------------------------------------------------------- // We had a successful backup, save the store @@ -2231,7 +2237,8 @@ void BackupDaemon::TouchFileInWorkingDir(const char *Filename) // // Function // Name: BackupDaemon::NotifySysadmin(int) -// Purpose: Run the script to tell the sysadmin about events which need attention. +// Purpose: Run the script to tell the sysadmin about events +// which need attention. // Created: 25/2/04 // // -------------------------------------------------------------------------- @@ -2242,26 +2249,40 @@ void BackupDaemon::NotifySysadmin(int Event) "store-full", "read-error", "backup-error", + "backup-start", + "backup-finish", 0 }; + BOX_TRACE("sizeof(sEventNames) == " << sizeof(sEventNames)); + BOX_TRACE("sizeof(*sEventNames) == " << sizeof(*sEventNames)); + BOX_TRACE("NotifyEvent__MAX == " << NotifyEvent__MAX); + ASSERT((sizeof(sEventNames)/sizeof(*sEventNames)) == NotifyEvent__MAX + 1); + BOX_TRACE("BackupDaemon::NotifySysadmin() called, event = " << sEventNames[Event]); if(Event < 0 || Event >= NotifyEvent__MAX) { - THROW_EXCEPTION(BackupStoreException, BadNotifySysadminEventCode); + THROW_EXCEPTION(BackupStoreException, + BadNotifySysadminEventCode); } // Don't send lots of repeated messages - if(mNotificationsSent[Event]) + if(mNotificationsSent[Event] && + Event != NotifyEvent_BackupStart && + Event != NotifyEvent_BackupFinish) { + BOX_WARNING("Suppressing duplicate notification about " << + sEventNames[Event]); return; } // Is there a notifation script? const Configuration &conf(GetConfiguration()); - if(!conf.KeyExists("NotifyScript")) + if(!conf.KeyExists("NotifyScript") && + Event != NotifyEvent_BackupStart && + Event != NotifyEvent_BackupFinish) { // Log, and then return BOX_ERROR("Not notifying administrator about event " @@ -2271,7 +2292,8 @@ void BackupDaemon::NotifySysadmin(int Event) } // Script to run - std::string script(conf.GetKeyValue("NotifyScript") + ' ' + sEventNames[Event]); + std::string script(conf.GetKeyValue("NotifyScript") + ' ' + + sEventNames[Event]); // Log what we're about to do BOX_NOTICE("About to notify administrator about event " @@ -2285,7 +2307,8 @@ void BackupDaemon::NotifySysadmin(int Event) << script << "')"); } - // Flag that this is done so the administrator isn't constantly bombarded with lots of errors + // Flag that this is done so the administrator isn't constantly + // bombarded with lots of errors mNotificationsSent[Event] = true; } diff --git a/bin/bbackupd/BackupDaemon.h b/bin/bbackupd/BackupDaemon.h index 47ae1d55..ab64bbfa 100644 --- a/bin/bbackupd/BackupDaemon.h +++ b/bin/bbackupd/BackupDaemon.h @@ -85,6 +85,8 @@ public: NotifyEvent_StoreFull = 0, NotifyEvent_ReadError, NotifyEvent_BackupError, + NotifyEvent_BackupStart, + NotifyEvent_BackupFinish, NotifyEvent__MAX // When adding notifications, remember to add strings to NotifySysadmin() }; diff --git a/bin/bbackupd/bbackupd-config.in b/bin/bbackupd/bbackupd-config.in index cc8cc293..5dbd2dd9 100755 --- a/bin/bbackupd/bbackupd-config.in +++ b/bin/bbackupd/bbackupd-config.in @@ -211,12 +211,24 @@ $sendmail = 'sendmail' if $sendmail !~ m/\S/; print NOTIFY <<__EOS; #!/bin/sh +# This script is run whenever bbackupd changes state or encounters a +# problem which requires the system administrator to assist: +# +# 1) The store is full, and no more data can be uploaded. +# 2) Some files or directories were not readable. +# 3) A backup run starts or finishes. +# +# The default script emails the system administrator, except for backups +# starting and stopping, where it does nothing. + SUBJECT="BACKUP PROBLEM on host $hostname" SENDTO="$current_username" -if [ \$1 = store-full ] -then -$sendmail \$SENDTO <<EOM +if [ "\$1" = "" ]; then + echo "Usage: $0 <store-full|read-error|backup-error|backup-start|backup-finish>" >&2 + exit 2 +elif [ "\$1" = store-full ]; then + $sendmail \$SENDTO <<EOM Subject: \$SUBJECT (store full) To: \$SENDTO @@ -230,8 +242,7 @@ FILES ARE NOT BEING BACKED UP Please adjust the limits on account $account_num on server $server. EOM -elif [ \$1 = read-error ] -then +elif [ "\$1" = read-error ]; then $sendmail \$SENDTO <<EOM Subject: \$SUBJECT (read errors) To: \$SENDTO @@ -244,11 +255,14 @@ THESE FILES ARE NOT BEING BACKED UP =================================== Check the logs on $hostname for the files and directories which caused -these errors, and take appropraite action. +these errors, and take appropriate action. Other files are being backed up. EOM +elif [ "\$1" = backup-start -o "\$1" = backup-finish ]; then + # do nothing by default + true else $sendmail \$SENDTO <<EOM Subject: \$SUBJECT (unknown) @@ -287,11 +301,15 @@ TrustedCAsFile = $ca_root_cert DataDirectory = $working_dir -# This script is run whenever bbackupd encounters a problem which requires -# the system administrator to assist: +# This script is run whenever bbackupd changes state or encounters a +# problem which requires the system administrator to assist: +# # 1) The store is full, and no more data can be uploaded. # 2) Some files or directories were not readable. -# The default script emails the system administrator. +# 3) A backup run starts or finishes. +# +# The default script emails the system administrator, except for backups +# starting and stopping, where it does nothing. NotifyScript = $notify_script @@ -302,9 +320,9 @@ if($backup_mode eq 'lazy') # lazy mode configuration print CONFIG <<__E; -# The number of seconds between backup runs under normal conditions. A scan To -# avoid cycles of load on the server, this time is randomly adjusted by a -# small percentage as the daemon runs. +# The number of seconds between backup runs under normal conditions. To avoid +# cycles of load on the server, this time is randomly adjusted by a small +# percentage as the daemon runs. UpdateStoreInterval = 3600 |