[Box Backup-dev] COMMIT r454 - box/chris/win32/vc2005-compile-fixes/bin/bbackupd

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sun Feb 12 22:39:18 GMT 2006


Author: chris
Date: 2006-02-12 22:39:14 +0000 (Sun, 12 Feb 2006)
New Revision: 454

Modified:
   box/chris/win32/vc2005-compile-fixes/bin/bbackupd/BackupDaemon.cpp
   box/chris/win32/vc2005-compile-fixes/bin/bbackupd/BackupDaemon.h
Log:
* BackupDaemon.cpp, BackupDaemon.h
- Only delete the serialised state when we're about to start a backup,
  since otherwise it's still valid and should be maintained


Modified: box/chris/win32/vc2005-compile-fixes/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/win32/vc2005-compile-fixes/bin/bbackupd/BackupDaemon.cpp	2006-02-12 20:36:00 UTC (rev 453)
+++ box/chris/win32/vc2005-compile-fixes/bin/bbackupd/BackupDaemon.cpp	2006-02-12 22:39:14 UTC (rev 454)
@@ -504,8 +504,8 @@
 		BackupClientContext::ClientStoreMarker_NotKnown;
 	// haven't contacted the store yet
 
- 	DeserializeStoreObjectInfo(clientStoreMarker, lastSyncTime, 
-		nextSyncTime);
+ 	bool deserialised = DeserializeStoreObjectInfo(clientStoreMarker, 
+		lastSyncTime, nextSyncTime);
  
 	// --------------------------------------------------------------------------------------------
 	
@@ -607,6 +607,17 @@
 				// but this should be OK, because the changes only upload should upload no data.
 				syncPeriodEndExtended += SecondsToBoxTime((time_t)(356*24*3600));
 			}
+
+			// Delete the serialised store object file,
+			// so that we don't try to reload it after a
+			// partially completed backup
+			if(!DeleteStoreObjectInfo())
+			{
+				::syslog(LOG_ERR, "Failed to delete the "
+					"StoreObjectInfoFile, backup cannot "
+					"continue safely.");
+				continue;
+			}
 			
 			// Do sync
 			bool errorOccurred = false;
@@ -2228,7 +2239,7 @@
 //		Created: 2005/04/11
 //
 // --------------------------------------------------------------------------
-void BackupDaemon::DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_time_t & theLastSyncTime, box_time_t & theNextSyncTime)
+bool BackupDaemon::DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_time_t & theLastSyncTime, box_time_t & theNextSyncTime)
 {
 	//
 	//
@@ -2240,7 +2251,7 @@
 	//
 	if(!GetConfiguration().KeyExists("StoreObjectInfoFile"))
 	{
-		return;
+		return false;
 	}
 
 	std::string StoreObjectInfoFile = 
@@ -2248,7 +2259,7 @@
 
 	if (StoreObjectInfoFile.size() <= 0)
 	{
-		return;
+		return false;
 	}
 
 	try
@@ -2268,7 +2279,7 @@
 				"is not a valid or compatible serialised "
 				"archive. Will re-cache from store.", 
 				StoreObjectInfoFile.c_str());
-			return;
+			return false;
 		}
 
 		//
@@ -2283,7 +2294,7 @@
 				"is not a valid or compatible serialised "
 				"archive. Will re-cache from store.", 
 				StoreObjectInfoFile.c_str());
-			return;
+			return false;
 		}
 
 		//
@@ -2296,11 +2307,11 @@
 		if (iVersion != STOREOBJECTINFO_VERSION)
 		{
 			::syslog(LOG_WARNING, "Store object info file '%s' "
-				"version [%d] unsupported. "
+				"version %d unsupported. "
 				"Will re-cache from store.", 
 				StoreObjectInfoFile.c_str(), 
 				iVersion);
-			return;
+			return false;
 		}
 
 		//
@@ -2315,7 +2326,7 @@
 			::syslog(LOG_WARNING, "Store object info file '%s' "
 				"out of date. Will re-cache from store", 
 				StoreObjectInfoFile.c_str());
-			return;
+			return false;
 		}
 
 		//
@@ -2363,12 +2374,7 @@
 			"version [%d]", StoreObjectInfoFile.c_str(), 
 			iVersion);
 
-		if (::unlink(StoreObjectInfoFile.c_str()) != 0)
-		{
-			::syslog(LOG_ERR, "Failed to delete the old "
-				"store object info file '%s': %s",
-				StoreObjectInfoFile.c_str(), strerror(errno));
-		}
+		return true;
 	}
 	catch (...)
 	{
@@ -2384,4 +2390,38 @@
 			"Will re-cache from store.", 
 			StoreObjectInfoFile.c_str());
 	}
+
+	return false;
 }
+
+// --------------------------------------------------------------------------
+//
+// Function
+//		Name:    BackupDaemon::DeleteStoreObjectInfo()
+//		Purpose: Deletes the serialised state file, to prevent us
+//			 from using it again if a backup is interrupted.
+//
+//		Created: 2006/02/12
+//
+// --------------------------------------------------------------------------
+
+bool BackupDaemon::DeleteStoreObjectInfo() const
+{
+	if(!GetConfiguration().KeyExists("StoreObjectInfoFile"))
+	{
+		return false;
+	}
+
+	std::string StoreObjectInfoFile = 
+		GetConfiguration().GetKeyValue("StoreObjectInfoFile");
+
+	if (::unlink(StoreObjectInfoFile.c_str()) != 0)
+	{
+		::syslog(LOG_ERR, "Failed to delete the old "
+			"store object info file '%s': %s",
+			StoreObjectInfoFile.c_str(), strerror(errno));
+		return false;
+	}
+
+	return true;
+}

Modified: box/chris/win32/vc2005-compile-fixes/bin/bbackupd/BackupDaemon.h
===================================================================
--- box/chris/win32/vc2005-compile-fixes/bin/bbackupd/BackupDaemon.h	2006-02-12 20:36:00 UTC (rev 453)
+++ box/chris/win32/vc2005-compile-fixes/bin/bbackupd/BackupDaemon.h	2006-02-12 22:39:14 UTC (rev 454)
@@ -45,10 +45,11 @@
 	BackupDaemon();
 	~BackupDaemon();
 
+private:
 	// methods below do partial (specialized) serialization of client state only
 	void SerializeStoreObjectInfo(int64_t aClientStoreMarker, box_time_t theLastSyncTime, box_time_t theNextSyncTime) const;
-	void DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_time_t & theLastSyncTime, box_time_t & theNextSyncTime);
-private:
+	bool DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_time_t & theLastSyncTime, box_time_t & theNextSyncTime);
+	bool DeleteStoreObjectInfo() const;
 	BackupDaemon(const BackupDaemon &);
 public:
 




More information about the Boxbackup-dev mailing list