[Box Backup] keeping files 28 days patch

Torsten boxbackup@boxbackup.org
Thu, 9 Jul 2009 16:21:33 +0200


--Boundary-00=_vzfVKNfYXskq5qL
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

i build a very little patch that only deletes files from store that are old or 
deleted and more than 28 days old. So files less that 28 days old are kept.

I think such a feature is important for Box Backup but i do not unterstand it 
completely.

- I think this patch generates a new class of file that i do not have a name 
for. Old and deleted but securely saved. The known old and deleted perhaps 
saved, because they are deleted if soft limit reached. Should there be new 
names for the new files? I do not know how other online backup solutions 
solve this.

- So the new soft limit should be calculated from actual data and secure old 
and deleted files. How could this be done?

- Is there a way for the client to tell the server how long to keep the files?

Any annotations or ideas?

thanks for reading
  Torsten

--Boundary-00=_vzfVKNfYXskq5qL
Content-Type: text/x-diff;
  charset="iso 8859-15";
  name="boxbackup_0.11_keep_old_and_deleted_files_28_days.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="boxbackup_0.11_keep_old_and_deleted_files_28_days.diff"

Index: bin/bbstored/HousekeepStoreAccount.cpp
===================================================================
--- bin/bbstored/HousekeepStoreAccount.cpp	(Revision 2546)
+++ bin/bbstored/HousekeepStoreAccount.cpp	(Arbeitskopie)
@@ -25,12 +25,17 @@
 #include "autogen_BackupStoreException.h"
 #include "BackupStoreFile.h"
 #include "BufferedStream.h"
+#include "BoxTime.h"
 
 #include "MemLeakFindOn.h"
 
 // check every 32 directories scanned/files deleted
 #define POLL_INTERPROCESS_MSG_CHECK_FREQUENCY	32
 
+// microseconds of a day
+#define MICROSECONDS_OF_A_DAY 1000*1000*3600*24;
+
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -461,6 +466,9 @@
 		BackupStoreDirectory::ReverseIterator i(dir);
 		BackupStoreDirectory::Entry *en = 0;
 
+		// timestamp four weeks ago
+		box_time_t keep_files_msecs = GetCurrentBoxTime() - 28 * (box_time_t)MICROSECONDS_OF_A_DAY;
+
 		while((en = i.Next(BackupStoreDirectory::Entry::Flags_File)) != 0)
 		{
 			// This directory references this object
@@ -494,9 +502,11 @@
 			}
 			// enVersionAge is now the age of this version.
 			
-			// Potentially add it to the list if it's deleted, if it's an old version or deleted
-			if((enFlags & (BackupStoreDirectory::Entry::Flags_Deleted | BackupStoreDirectory::Entry::Flags_OldVersion)) != 0)
+			// Potentially add it to the list if it's deleted, if it's an old version or deleted, but only if it older than keep_files_msecs
+			if(((enFlags & (BackupStoreDirectory::Entry::Flags_Deleted | BackupStoreDirectory::Entry::Flags_OldVersion)) != 0) 
+			&& ( keep_files_msecs >= en->GetModificationTime()))
 			{
+				BOX_INFO("File is older than 4 weeks - adding it to deletion list" << en->GetModificationTime() << "-" << en->GetName().GetEncodedFilename() << "-" << en->GetMarkNumber() );
 				// Is deleted / old version.
 				DelEn d;
 				d.mObjectID = en->GetObjectID();

--Boundary-00=_vzfVKNfYXskq5qL--