[Box Backup-commit] COMMIT r1234 - in box/chris/merge: bin/bbackupd lib/backupclient

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Thu Jan 11 22:47:36 GMT 2007


Author: chris
Date: 2007-01-11 22:47:35 +0000 (Thu, 11 Jan 2007)
New Revision: 1234

Modified:
   box/chris/merge/bin/bbackupd/BackupClientDirectoryRecord.cpp
   box/chris/merge/bin/bbackupd/BackupClientDirectoryRecord.h
   box/chris/merge/bin/bbackupd/BackupDaemon.cpp
   box/chris/merge/bin/bbackupd/BackupDaemon.h
   box/chris/merge/lib/backupclient/BackupDaemonConfigVerify.cpp
Log:
Added a new config option, LogAllFileAccess, which will log access to every 
file and scanning every directory. The current implementation is taken
straight from the Boxi branch. To be extended shortly. (refs #3)


Modified: box/chris/merge/bin/bbackupd/BackupClientDirectoryRecord.cpp
===================================================================
--- box/chris/merge/bin/bbackupd/BackupClientDirectoryRecord.cpp	2006-12-29 23:51:06 UTC (rev 1233)
+++ box/chris/merge/bin/bbackupd/BackupClientDirectoryRecord.cpp	2007-01-11 22:47:35 UTC (rev 1234)
@@ -164,8 +164,8 @@
 		{
 			// The directory has probably been deleted, so just ignore this error.
 			// In a future scan, this deletion will be noticed, deleted from server, and this object deleted.
-			TRACE1("Stat failed for '%s' (directory)\n", 
-				rLocalPath.c_str());
+			rParams.GetProgressNotifier().NotifyDirStatFailed(
+				this, rLocalPath, strerror(errno));
 			return;
 		}
 		// Store inode number in map so directories are tracked in case they're renamed
@@ -202,6 +202,19 @@
 			dirHandle = ::opendir(rLocalPath.c_str());
 			if(dirHandle == 0)
 			{
+				// Report the error (logs and 
+				// eventual email to administrator)
+				if (errno == EACCES)
+				{
+					rParams.GetProgressNotifier().NotifyDirListFailed(
+						this, rLocalPath, "Access denied");
+				}
+				else
+				{
+					rParams.GetProgressNotifier().NotifyDirListFailed(this, 
+						rLocalPath, strerror(errno));
+				}
+				
 				// Report the error (logs and eventual email to administrator)
 				SetErrorWhenReadingFilesystemObject(rParams, rLocalPath.c_str());
 				// Ignore this directory for now.
@@ -254,6 +267,10 @@
 				{
 					// Report the error (logs and 
 					// eventual email to administrator)
+ 					rParams.GetProgressNotifier().NotifyFileStatFailed(this, 
+ 						filename, strerror(errno));
+					
+					// FIXME move to NotifyFileStatFailed()
 					SetErrorWhenReadingFilesystemObject(
 						rParams, filename.c_str());
 
@@ -337,8 +354,8 @@
 					// Log that this has happened
 					if(!rParams.mHaveLoggedWarningAboutFutureFileTimes)
 					{
-						::syslog(LOG_ERR, "Some files have modification times excessively in the future. Check clock syncronisation.\n");
-						::syslog(LOG_ERR, "Example file (only one shown) : %s\n", filename.c_str());
+						rParams.GetProgressNotifier().NotifyFileModifiedInFuture(
+							this, filename);
 						rParams.mHaveLoggedWarningAboutFutureFileTimes = true;
 					}
 				}
@@ -594,6 +611,8 @@
 			struct stat st;
 			if(::lstat(filename.c_str(), &st) != 0)
 			{
+				rParams.GetProgressNotifier().NotifyFileStatFailed(this, 
+					filename, strerror(errno));
 				THROW_EXCEPTION(CommonException, OSFileError)
 			}
 			
@@ -806,6 +825,8 @@
 				{
 					// Connection errors should just be passed on to the main handler, retries
 					// would probably just cause more problems.
+					rParams.GetProgressNotifier().NotifyFileUploadException(this,
+						filename, e);
 					throw;
 				}
 				catch(BoxException &e)
@@ -815,7 +836,8 @@
 					// Log it.
 					SetErrorWhenReadingFilesystemObject(rParams, filename.c_str());
 					// Log error.
-					::syslog(LOG_ERR, "Error code when uploading was (%d/%d), %s", e.GetType(), e.GetSubType(), e.what());
+					rParams.GetProgressNotifier().NotifyFileUploadException(this,
+						filename, e);
 				}
 
 				// Update structures if the file was uploaded successfully.
@@ -828,6 +850,11 @@
 					}
 				}
 			}
+			else
+			{
+				rParams.GetProgressNotifier().NotifyFileSkippedServerFull(this,
+					filename);
+			}
 		}
 		else if(en != 0 && en->GetAttributesHash() != attributesHash)
 		{
@@ -909,6 +936,9 @@
 				}
 			}
 		}
+		
+		rParams.GetProgressNotifier().NotifyFileSynchronised(this, 
+			filename, fileSize);
 	}
 
 	// Erase contents of files to save space when recursing
@@ -1225,7 +1255,11 @@
 			
 			if(diffFromID != 0)
 			{
-				// Found an old version -- get the index
+				// Found an old version
+				rParams.GetProgressNotifier().NotifyFileUploadingPatch(this, 
+					rFilename);
+
+				// Get the index
 				std::auto_ptr<IOStream> blockIndexStream(connection.ReceiveStream());
 			
 				//
@@ -1298,6 +1332,8 @@
 		throw;
 	}
 
+	rParams.GetProgressNotifier().NotifyFileUploaded(this, rFilename, FileSize);
+
 	// Return the new object ID of this file
 	return objID;
 }
@@ -1317,8 +1353,11 @@
 	// Zero hash, so it gets synced properly next time round.
 	::memset(mStateChecksum, 0, sizeof(mStateChecksum));
 
-	// Log the error
-	::syslog(LOG_ERR, "Backup object failed, error when reading %s", Filename);
+	// Log the error - already done by caller
+	/*
+	rParams.GetProgressNotifier().NotifyFileReadFailed(this, 
+		Filename, strerror(errno));
+	*/
 
 	// Mark that an error occured in the parameters object
 	rParams.mReadErrorsOnFilesystemObjects = true;
@@ -1334,8 +1373,10 @@
 //		Created: 8/3/04
 //
 // --------------------------------------------------------------------------
-BackupClientDirectoryRecord::SyncParams::SyncParams(BackupDaemon &rDaemon, BackupClientContext &rContext)
-	: mSyncPeriodStart(0),
+BackupClientDirectoryRecord::SyncParams::SyncParams(BackupDaemon &rDaemon, 
+	ProgressNotifier &rProgressNotifier, BackupClientContext &rContext)
+	: mrProgressNotifier(rProgressNotifier),
+	  mSyncPeriodStart(0),
 	  mSyncPeriodEnd(0),
 	  mMaxUploadWait(0),
 	  mMaxFileTimeInFuture(99999999999999999LL),

Modified: box/chris/merge/bin/bbackupd/BackupClientDirectoryRecord.h
===================================================================
--- box/chris/merge/bin/bbackupd/BackupClientDirectoryRecord.h	2006-12-29 23:51:06 UTC (rev 1233)
+++ box/chris/merge/bin/bbackupd/BackupClientDirectoryRecord.h	2007-01-11 22:47:35 UTC (rev 1234)
@@ -25,6 +25,66 @@
 // --------------------------------------------------------------------------
 //
 // Class
+//		Name:    ProgressNotifier
+//		Purpose: Provides methods for the backup library to inform the user
+//		         interface about its progress with the backup
+//		Created: 2005/11/20
+//
+// --------------------------------------------------------------------------
+class BackupClientDirectoryRecord;
+	
+class ProgressNotifier
+{
+	public:
+	virtual ~ProgressNotifier() { }
+	virtual void NotifyScanDirectory(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath) = 0;
+	virtual void NotifyDirStatFailed(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath,
+		const std::string& rErrorMsg) = 0;
+	virtual void NotifyFileStatFailed(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath,
+		const std::string& rErrorMsg) = 0;
+	virtual void NotifyDirListFailed(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath,
+		const std::string& rErrorMsg) = 0;
+	virtual void NotifyFileReadFailed(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath,
+		const std::string& rErrorMsg) = 0;
+	virtual void NotifyFileModifiedInFuture(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath) = 0;
+	virtual void NotifyFileSkippedServerFull(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath) = 0;
+	virtual void NotifyFileUploadException(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath,
+		const BoxException& rException) = 0;
+	virtual void NotifyFileUploading(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath) = 0;
+	virtual void NotifyFileUploadingPatch(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath) = 0;
+	virtual void NotifyFileUploaded(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath,
+		int64_t FileSize) = 0;
+	virtual void NotifyFileSynchronised(
+		const BackupClientDirectoryRecord* pDirRecord,
+		const std::string& rLocalPath,
+		int64_t FileSize) = 0;
+};
+
+// --------------------------------------------------------------------------
+//
+// Class
 //		Name:    BackupClientDirectoryRecord
 //		Purpose: Implementation of record about directory for backup client
 //		Created: 2003/10/08
@@ -59,14 +119,18 @@
 	class SyncParams
 	{
 	public:
-		SyncParams(BackupDaemon &rDaemon, BackupClientContext &rContext);
+		SyncParams(
+			BackupDaemon &rDaemon,
+			ProgressNotifier &rProgressNotifier,
+			BackupClientContext &rContext);
 		~SyncParams();
 	private:
 		// No copying
 		SyncParams(const SyncParams&);
 		SyncParams &operator=(const SyncParams&);
+		ProgressNotifier &mrProgressNotifier;
+		
 	public:
-
 		// Data members are public, as accessors are not justified here
 		box_time_t mSyncPeriodStart;
 		box_time_t mSyncPeriodEnd;
@@ -81,6 +145,11 @@
 		// Member variables modified by syncing process
 		box_time_t mUploadAfterThisTimeInTheFuture;
 		bool mHaveLoggedWarningAboutFutureFileTimes;
+	
+		ProgressNotifier& GetProgressNotifier() const 
+		{ 
+			return mrProgressNotifier;
+		}
 	};
 
 	void SyncDirectory(SyncParams &rParams, int64_t ContainingDirectoryID, const std::string &rLocalPath,

Modified: box/chris/merge/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/merge/bin/bbackupd/BackupDaemon.cpp	2006-12-29 23:51:06 UTC (rev 1233)
+++ box/chris/merge/bin/bbackupd/BackupDaemon.cpp	2007-01-11 22:47:35 UTC (rev 1234)
@@ -113,7 +113,8 @@
 BackupDaemon::BackupDaemon()
 	: mState(BackupDaemon::State_Initialising),
 	  mpCommandSocketInfo(0),
-	  mDeleteUnusedRootDirEntriesAfter(0)
+	  mDeleteUnusedRootDirEntriesAfter(0),
+	  mLogAllFileAccess(false)
 {
 	// Only ever one instance of a daemon
 	SSLLib::Initialise();
@@ -697,6 +698,13 @@
 						"ExtendedLogFile");
 				}
 				
+				if (conf.KeyExists("LogAllFileAccess"))
+				{
+					mLogAllFileAccess = 
+						conf.GetKeyValueBool(
+							"LogAllFileAccess");
+				}
+				
 				// Then create a client context object (don't 
 				// just connect, as this may be unnecessary)
 				BackupClientContext clientContext
@@ -711,7 +719,7 @@
 				);
 					
 				// Set up the sync parameters
-				BackupClientDirectoryRecord::SyncParams params(*this, clientContext);
+				BackupClientDirectoryRecord::SyncParams params(*this, *this, clientContext);
 				params.mSyncPeriodStart = syncPeriodStart;
 				params.mSyncPeriodEnd = syncPeriodEndExtended; // use potentially extended end time
 				params.mMaxUploadWait = maxUploadWait;

Modified: box/chris/merge/bin/bbackupd/BackupDaemon.h
===================================================================
--- box/chris/merge/bin/bbackupd/BackupDaemon.h	2006-12-29 23:51:06 UTC (rev 1233)
+++ box/chris/merge/bin/bbackupd/BackupDaemon.h	2007-01-11 22:47:35 UTC (rev 1234)
@@ -16,9 +16,12 @@
 
 #include "BoxTime.h"
 #include "Daemon.h"
+#include "BackupClientDirectoryRecord.h"
 #include "Socket.h"
 #include "SocketListen.h"
 #include "SocketStream.h"
+#include "Logging.h"
+
 #ifdef WIN32
 	#include "WinNamedPipeStream.h"
 #endif
@@ -39,7 +42,7 @@
 //		Created: 2003/10/08
 //
 // --------------------------------------------------------------------------
-class BackupDaemon : public Daemon
+class BackupDaemon : public Daemon, ProgressNotifier
 {
 public:
 	BackupDaemon();
@@ -180,6 +183,118 @@
 	box_time_t mDeleteUnusedRootDirEntriesAfter;	// time to delete them
 	std::vector<std::pair<int64_t,std::string> > mUnusedRootDirEntries;
 
+public:
+ 	bool StopRun() { return this->Daemon::StopRun(); }
+ 
+private:
+	bool mLogAllFileAccess;
+
+ 	/* ProgressNotifier implementation */
+public:
+ 	virtual void NotifyScanDirectory(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath) 
+	{
+		if (mLogAllFileAccess)
+		{
+			BOX_INFO("Scanning directory: " << rLocalPath);
+		} 
+	}
+ 	virtual void NotifyDirStatFailed(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath, 
+ 		const std::string& rErrorMsg)
+ 	{
+		BOX_WARNING("Failed to access directory: " << rLocalPath
+			<< ": " << rErrorMsg);
+ 	}
+ 	virtual void NotifyFileStatFailed(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath,
+ 		const std::string& rErrorMsg)
+ 	{
+		BOX_WARNING("Failed to access file: " << rLocalPath
+			<< ": " << rErrorMsg);
+ 	}
+ 	virtual void NotifyDirListFailed(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath,
+ 		const std::string& rErrorMsg)
+ 	{
+		BOX_WARNING("Failed to list directory: " << rLocalPath
+			<< ": " << rErrorMsg);
+ 	}
+ 	virtual void NotifyFileReadFailed(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath,
+ 		const std::string& rErrorMsg)
+ 	{
+		BOX_WARNING("Error reading file: " << rLocalPath
+			<< ": " << rErrorMsg);
+ 	}
+ 	virtual void NotifyFileModifiedInFuture(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath)
+ 	{
+		BOX_WARNING("Some files have modification times excessively "
+			"in the future. Check clock synchronisation. "
+			"Example file (only one shown): " << rLocalPath);
+ 	}
+ 	virtual void NotifyFileSkippedServerFull(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath) 
+	{
+		BOX_WARNING("Skipped file: server is full: " << rLocalPath);
+	}
+ 	virtual void NotifyFileUploadException(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath,
+ 		const BoxException& rException)
+ 	{
+		BOX_ERROR("Failed to upload file: " << rLocalPath 
+			<< ": caught exception: " << rException.what() 
+			<< " (" << rException.GetType()
+			<< "/"  << rException.GetSubType() << ")");
+ 	}
+ 	virtual void NotifyFileUploading(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath) 
+	{ 
+		if (mLogAllFileAccess)
+		{
+			BOX_INFO("Uploading file: " << rLocalPath);
+		} 
+	}
+ 	virtual void NotifyFileUploadingPatch(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath) 
+	{
+		if (mLogAllFileAccess)
+		{
+			BOX_INFO("Uploading patch to file: " << rLocalPath);
+		} 
+	}
+ 	virtual void NotifyFileUploaded(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath,
+ 		int64_t FileSize) 
+	{
+		if (mLogAllFileAccess)
+		{
+			BOX_INFO("Uploaded file: " << rLocalPath);
+		} 
+	}
+ 	virtual void NotifyFileSynchronised(
+ 		const BackupClientDirectoryRecord* pDirRecord,
+ 		const std::string& rLocalPath,
+ 		int64_t FileSize) 
+	{
+		if (mLogAllFileAccess)
+		{
+			BOX_INFO("Synchronised file: " << rLocalPath);
+		} 
+	}
+
 #ifdef WIN32
 	public:
 	void RunHelperThread(void);

Modified: box/chris/merge/lib/backupclient/BackupDaemonConfigVerify.cpp
===================================================================
--- box/chris/merge/lib/backupclient/BackupDaemonConfigVerify.cpp	2006-12-29 23:51:06 UTC (rev 1233)
+++ box/chris/merge/lib/backupclient/BackupDaemonConfigVerify.cpp	2007-01-11 22:47:35 UTC (rev 1234)
@@ -83,6 +83,7 @@
 	{"StoreHostname", 0, ConfigTest_Exists, 0},
 	{"ExtendedLogging",	"no", ConfigTest_IsBool, 0}, // extended log to syslog
 	{"ExtendedLogFile",	NULL, 0, 0}, // extended log to a file
+	{"LogAllFileAccess", "no", ConfigTest_IsBool, 0},
 
 	{"CommandSocket", 0, 0, 0},				// not compulsory to have this
 	{"KeepAliveTime", 0, ConfigTest_IsInt, 0},				// optional




More information about the Boxbackup-commit mailing list