Home > Domino Tips > Developer > Agent > How to automatically create a backup copy of your Domino Directory
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

AGENT

How to automatically create a backup copy of your Domino Directory


Jari Riihim?ki
04.17.2007
Rating: -2.54- (out of 5)


Lotus Notes and Domino tips, tutorials and how-to articles
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


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.
VIEW MEMBER FEEDACK TO THIS TIP

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.

    Rate this Tip
    To rate tips, you must be a member of SearchDomino.com.
    Register now to start rating these tips. Log in if you are already a member.




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


    RELATED CONTENT
    Lotus Domino Directory
    Find a Lotus Notes user within NAB Deny Access groups
    Troubleshoot Lotus Notes Out of Office (OOO) agent error messages
    Create a computed Lotus Notes field to list Personal Address Book names
    Domino Directory management tips and tutorials
    How to correct Lotus Notes public key mismatches in four easy steps
    Address book that was added to server doesn't show up on client
    JavaScript Domino directory name validation
    Get all members of Domino Directory Group
    "NAB" your Domino directory problems before they spread
    Person document lost from the Domino Directory

    Lotus Notes Domino Agents
    Open documents in Lotus Notes from the Web without a UNID
    Fix and update Lotus Notes documents with limited access
    Verify scheduled agent status with Domino Extensible Language (DXL)
    Top 10 Lotus Notes Domino programming and development tips of 2007
    How to export data from a Lotus Notes database to a CSV file
    Must-know Lotus Notes Domino agents -- 10 tips in 10 minutes
    Enable or disable scheduled agents without opening the Lotus Notes database design
    Creating custom views in Lotus Notes databases
    Editing fields in a Lotus Notes view with Ajax
    Troubleshooting a scheduled agent not running on a Global Notes Architecture (GNA) server

    Lotus Notes Domino Backup and Recovery
    Lotus Notes and Domino Server backup and recovery
    Replication best practices for Lotus Domino disaster recovery
    The truth about AutoSave in Lotus Notes/Domino 7
    Restoring a corrupt Lotus Notes certlog.nsf file
    Lotus Notes replication snafu: Accidentally deleted archived email
    Nine steps to less expensive, more reliable backups
    Microsoft repackages e-mail hosting service
    Error restoring an NSF archive file: 'File truncated - file may have been damaged'
    CA buys iLumin, joins email archiving space
    What, where and how long? The issues of archiving e-mail

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



  • Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
    HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts