Merging or importing/exporting data between mailbox .NSF files

Hi Guys -

Is there any way in Lotus Notes, or is there a third-party utility which can either merge or import/export data between .NSF files. A user of mine has somehow created three archive files, each are populated with different mail items and folders, and the idea is to get all the items from two of the .NSF files and merge them into the third, thus obviously creating one archive file with all the items in it.

The issue so far is that there are heaps of folders that the user has created in the various archived mailboxes, so cutting/pasting between the databases would take too long.

Any help would be appreciated.

Subject: Merging or importing/exporting data between mailbox .NSF files

One possible solution is to:

first - identify the target database that will hold all documents

second - write a lotusscript agent that will copy documents from one database to the target

third - include a condition in the agent which first checks to see if a document with that unique ID already exists in the target db, and if so, skip it

NOtesDoc.CopyToDatabase( TargetDB ) should work nicely for this.

Subject: RE: Merging or importing/exporting data between mailbox .NSF files

I’ve thrown something together to do this. If anyone wants to add to/improve it, be my guest. It basically merges 2 directories. If a databse of the same filename exists in the target directory, it copies (moves) the documents from the source db into the existing db. Doesn’t cater for folders yet.


Sub Initialize

'Dim uiw As New NotesUIWorkspace

Dim s As New NotesSession	

Dim sourceFiles List As String

Dim destFiles List As String

Dim sourceDB As notesDatabase

Dim destDB As NotesDatabase



Dim allDocs As NotesDocumentCollection

Dim srcDoc As NotesDocument

Dim dstDoc As notesDocument



Msgbox "Started archive merge"



On Error Goto ErrorTrap



'Get the source directory

'sourceDir = uiw.Prompt(PROMPT_OKCANCELEDIT,"Source Directory","Enter the source path (relative to the server):")

sourceDir = "f:\lotus\domino\data\archive"



'Get the destination directory

'destDir = uiw.Prompt(PROMPT_OKCANCELEDIT,"Destination Directory","Enter the destination path (relative to the server):")	

destDir = "g:\mail_archive\mail_archive_2008"



'Get a list of DB's in the source

sourceFile = Dir(sourceDir + "/*.nsf")

Do Until sourceFile=""

	sourceFiles(sourceFile) = ""

	sourceFile = Dir

Loop 



'Get a list of DB's in the destination

destFile = Dir(destDir + "/*.nsf")

Do Until destFile=""

	destFiles(destFile) = ""

	destFile = Dir

Loop





Forall srcFile In sourceFiles		

	Msgbox "Merging " & (sourceDir & "/" & Listtag(srcFile))

	Set sourceDB = New notesDatabase("","")

	Set destDB = New NotesDatabase("","")

	

	If Not (Iselement(destFiles(Listtag(srcFile)))) Then

		'If there is not a corresponding destination db, move the entire database

		On Error Goto replicate

		Name (sourceDir & "/" & Listtag(srcFile)) As (destDir & "/" & Listtag(srcFile))

		Goto renamedOK

replicate:

		Err = 0			

		On Error Goto ErrorTrap

		Call sourceDB.Open("",(sourceDir & "/" & Listtag(srcFile)))

		Set destDB = notesDatabase.CreateReplica( "", (destDir & "/" & Listtag(srcFile)))

		Call sourceDB.Remove

renamedOK:

	Else

		'If there is a corresponding destination, move all documents in the source to the destination

		Call sourceDB.Open("",(sourceDir & "/" & Listtag(srcFile)))

		Call destDB.Open("",(destDir & "/" & Listtag(srcFile)))

		

		If Not sourceDB.IsOpen Then

			Call sourceDB.Open("","")

		End If

		

		If Not destDB.IsOpen Then

			Call destDB.Open("","")

		End If

		

		Set allDocs = sourceDB.AllDocuments

		Set srcDoc = allDocs.getFirstDocument

		'sourceDB.FolderReferencesEnabled=True

		

		While Not srcDoc Is Nothing

			Set dstDoc = srcDoc.CopyToDatabase(destDB)

			

		'	Forall folderName In srcDoc.FolderReferences

		'		If folderName<>"" Then Call dstDoc.PutInFolder(folderName,True)

		'	End Forall

			

			Set srcDoc = allDocs.getNextDocument(srcDoc)

		Wend

		

		Call sourceDB.Remove

		

	End If

	

End Forall



Rmdir sourceDir



Msgbox "Finished archive merge"

Exit Sub

ErrorTrap:

Msgbox  "ERROR: - " & Err & ": " & Error & " (" & Getthreadinfo(1) & "-" & Getthreadinfo(2) & "-" & Getthreadinfo(3) & ") - Line " & Erl & Chr(13)

Exit Sub

End Sub