Manage Learn to apply best practices and optimize your operations.

How to automatically create a backup copy of your Domino Directory member Jari Riihimaki provides a Lotus Notes agent that automatically creates a backup copy of your Domino Directory. After implementing this agent, you'll never again need to restore documents back to your Domino Directory or check old configurations.

This Lotus Notes agent will automatically create a backup copy of your Domino Directory. Now you'll never need to restore documents back to Domino Directory or check your old configurations.




This Lotus Notes agent works by creating a new copy of the Domino Directory under an archive directory. It can be scheduled to run monthly and can be easily modified to create a backup copy of any database from any Lotus Domino server.

 Sub Initialize Dim dbOrigin As NotesDatabase Dim dbArchive As NotesDatabase Dim collection As NotesDocumentCollection Dim doc As NotesDocument 'Date format for the file name FormatDate = Format(Date, "yyyymmdd") 'Set the Original database Set dbOrigin = New NotesDatabase ( "Server1/ACME", "names.nsf" ) Set dbArchive = New NotesDatabase( "", "" ) 'Set the server where new archive copy is created archiveServer$ = "Server1/ACME" 'Build the path and add the date in the file name archiveFile$ = "archive" + FormatDate & dbOrigin.FileName If (Not(dbArchive.Open (archiveServer$, archiveFile$))) Then Set dbArchive = dbOrigin.CreateCopy ( archiveServer$, archiveFile$ ) End If 'Copy all documents from Orgin DB to Archive DB Set collection = dbOrigin.AllDocuments Set doc = collection.GetFirstDocument() While Not(doc Is Nothing) Call doc.CopyToDatabase( dbArchive ) Set doc = collection. GetNextDocument(doc) Wend End Sub


I think this works better:

 Dim session As NotesSession Dim dc As NotesDocumentCollection Dim dbNAB As NotesDatabase Dim dbCurrent As NotesDatabase Dim dbBackup As NotesDatabase Dim docNAB As NotesDocument Dim docTmp As NotesDocument Dim nNameServerActual As NotesName Dim nNameServerNAB As NotesName Dim dbFileName As String Dim processedDocuments As Long On Error Goto backupErrorHandler Print "Starting agent..." Set session = New NotesSession Set dbCurrent = session.currentDatabase processedDocuments = 0 dbFileName = Cstr(Year(Now)) & Cstr(Month(Now)) & Cstr(Day(Now)) Forall nab In session.addressBooks If (nab.isPublicAddressBook) Then Set dbNAB = nab Set nNameServerNAB = New NotesName(dbNAB.server) Set nNameServerActual = New NotesName(dbCurrent.server) If nNameServerActual.abbreviated = nNameServerNAB.abbreviated Then 'the NAB server is the same as the agent server Call dbNAB.Open("", "") Set dbBackup = session.getDatabase("", dbFileName & dbNAB.FileName) If Not(dbBackup.IsOpen) Then Set dbBackup = dbNAB.createCopy("", dbFileName & dbNAB.FileName) End If Else 'the NAB server is other than the agent server Call dbNAB.Open (nNameServerNAB.common, dbNAB.FilePath) Set dbBackup = session.getDatabase(nNameServerNAB.common, dbFileName & dbNAB.FileName) If Not(dbBackup.IsOpen) Then Set dbBackup = dbNAB.createCopy(nNameServerNAB.common, dbFileName & dbNAB.FileName) End If End If If dbNAB.isOpen Then Exit Forall End If End If End Forall If dbNAB Is Nothing Then Print "Domino Directory was not found" Exit Sub End If If Not(dbNAB.isOpen) Then Print "Domino Directory could not be opened" Exit Sub End If If Not(dbBackup.isOpen) Then Print "Backup database could not be opened" Exit Sub End If Set dc = dbNAB.allDocuments If Not(dc Is Nothing) Then If dc.count > 0 Then Set docNAB = dc.getFirstDocument While Not(docNAB Is Nothing) Call docNAB.copyToDatabase(dbBackup) processedDocuments = processedDocuments + 1 Set docNAB = dc.getNextDocument(docNAB) Wend End If End If Print "Documents processed: " & Cstr(processedDocuments) Print "Ending agent..." Exit Sub backupErrorHandler: Print "Error(s) found during agent execution" Exit Sub

—Alfonso F.

Do you have comments on this tip? Let us know.

Related information from


Dig Deeper on Lotus Domino Directory

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury