[Box Backup-commit] COMMIT r1805 - box/chris/general/bin/bbackupd

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sat Sep 1 21:57:14 BST 2007


Author: chris
Date: 2007-09-01 21:57:13 +0100 (Sat, 01 Sep 2007)
New Revision: 1805

Modified:
   box/chris/general/bin/bbackupd/BackupClientDirectoryRecord.cpp
   box/chris/general/bin/bbackupd/BackupDaemon.cpp
   box/chris/general/bin/bbackupd/BackupDaemon.h
   box/chris/general/bin/bbackupd/bbackupd-config.in
Log:
Call the notify script whenever backup starts or finishes, but the
default script does nothing in this case. Requested by
scott <scott at lubetech.com.au>. (merges [1804])


Modified: box/chris/general/bin/bbackupd/BackupClientDirectoryRecord.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupClientDirectoryRecord.cpp	2007-09-01 20:56:26 UTC (rev 1804)
+++ box/chris/general/bin/bbackupd/BackupClientDirectoryRecord.cpp	2007-09-01 20:57:13 UTC (rev 1805)
@@ -887,7 +887,9 @@
 				{
 					// Connection errors should just be passed on to the main handler, retries
 					// would probably just cause more problems.
-					// Already logged by UploadFile
+					rParams.GetProgressNotifier()
+						.NotifyFileUploadException(
+							this, filename, e);
 					throw;
 				}
 				catch(BoxException &e)

Modified: box/chris/general/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-09-01 20:56:26 UTC (rev 1804)
+++ box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-09-01 20:57:13 UTC (rev 1805)
@@ -903,6 +903,9 @@
 				// 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 @@
 				// Log
 				BOX_NOTICE("Finished scan of local files");
 
+				// Notify administrator
+				NotifySysadmin(NotifyEvent_BackupFinish);
+
 				// --------------------------------------------------------------------------------------------
 
 				// We had a successful backup, save the store 
@@ -2215,7 +2221,8 @@
 //
 // 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
 //
 // --------------------------------------------------------------------------
@@ -2226,26 +2233,40 @@
 		"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 "
@@ -2255,7 +2276,8 @@
 	}
 
 	// 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 "
@@ -2269,7 +2291,8 @@
 			<< 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;
 }
 

Modified: box/chris/general/bin/bbackupd/BackupDaemon.h
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.h	2007-09-01 20:56:26 UTC (rev 1804)
+++ box/chris/general/bin/bbackupd/BackupDaemon.h	2007-09-01 20:57:13 UTC (rev 1805)
@@ -85,6 +85,8 @@
 		NotifyEvent_StoreFull = 0,
 		NotifyEvent_ReadError,
 		NotifyEvent_BackupError,
+		NotifyEvent_BackupStart,
+		NotifyEvent_BackupFinish,
 		NotifyEvent__MAX
 		// When adding notifications, remember to add strings to NotifySysadmin()
 	};

Modified: box/chris/general/bin/bbackupd/bbackupd-config.in
===================================================================
--- box/chris/general/bin/bbackupd/bbackupd-config.in	2007-09-01 20:56:26 UTC (rev 1804)
+++ box/chris/general/bin/bbackupd/bbackupd-config.in	2007-09-01 20:57:13 UTC (rev 1805)
@@ -211,12 +211,24 @@
 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 @@
 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 @@
 ===================================
 
 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 @@
 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 @@
 	# 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
 




More information about the Boxbackup-commit mailing list