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
MEMBER FEEDBACK TO THIS TIP
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 SearchDomino.com:
Tip: JavaScript Domino Directory name validation
Tip: Calculate business days between two dates using Domino Directory
Tip: Get all members in a Domino Directory group
Expert Advice: Copy and replace an old Domino Directory during an upgrade
Reference Center: Agent tips and resources
This tip was submitted to the SearchDomino.com tip library by member Jari Riihimaki. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.