ShowTable of Contents
Introduction
Archiving is one of the popular tool with IBM Notes users. It has been observed that users continue to use only 1 archive, resulting in the archive file becoming too large (several mega-bytes). Multiple issues arise if the database grows to a large size (> 10 GB).
This article describes how a user can customize archive agents in the mail file using IBM Domino Designer to create a new archive database automatically when the current archive database size reaches a specific threshold value in case of local and manual archiving.
For customers who customize the mail template, this can be added to the custom mail template, which will then get passed onto individual users mail file when they refresh from it.
Prerequisites:
1. IBM Notes Client (8.5 or above)
2. IBM Domino Designer Client (8.5 or above)
3. Designer access to the Mail-File or Mail Template to be customized.
4. Local Archiving is enabled
Document archiving tool
Archiving is one of the popular features in IBM Notes mailbox. Users or server administrators can copy documents in a database that meet specified criteria to an archive database and then delete the documents from the database, or reduce the sizes of the documents. When documents that meet the specified criteria are deleted from the database, replica stubs remain so that deletions can replicate if there are replicas of the database.
Users or administrators can archive documents based on days since the documents were last read, last modified, last accessed and/or marked as expired. From the Notes client, you enable archiving and specify settings that control what happens when a database is archived.
Refer to Notes Help for details on Enabling Archive tool.
The tool creates an archive database with the title of the source database followed by the word "Archive" in parentheses -- for example, "Sales (Archive)." By default, the archive database is stored on a client or server within the data folder in a folder called \archive. The file name for the archive database is “a_xxxxx.nsf” where xxxxx represents the first five characters in the source database file name -- for example, a_sales.nsf. You can customize the location and file name of the archive database as enclosed in the screen below.
As an example let's imagine that, you have this Archive database that now has around 400,000 documents, and grows to 45 Gigabytes for this single database. This is a scenario that a lot of us have experienced.
It may then be a good idea to create new archive database to prevent this single database from growing too large.
A most common scenario could be that a limit be placed on the archive size, and when the current archive grows to that limit, a new archive automatically gets created and the archive operation continues. This will ensure any given archive DB never grows to be too big.
Following are the two agents related to manual archiving -
1. (Archive Now)
2. Archive Selected Documents)
Customizing Archiving Agents
After customizing, the Archive agent will do the following:
-
If a user's mail file name is “xxxxx.nsf “ then existing archive database “a_xxxxx.nsf “.
-
If the existing archive database “a_xxxxx.nsf “ has exceeded limit specified by constant in the code, ARCHIVE_MAX_SIZE then it creates new archive database with name as “a_xxxxx_N.nsf “ with N=1 i.e. “a_xxxxx_1.nsf “ .
-
If this Archive database also exceeds limit then it creates new Archive database by incrementing N. e.g. “a_xxxxx_2.nsf “.
-
New database name is set in the Archive criteria shown in the above screen.
-
If a user clicks on the Archive criteria under “Archive” in the Mailbox navigator pane, it will then open the new Archive database.
-
Notification email will be sent to the user about the newly created archive database creation.
-
A link to old archive database is also included in the mail for reference.
Steps to Open the agent in designer for customization
1. Open the mail file or mail template in IBM Domino designer client.
2. Click on Code → Agents in navigation pane. On right hand side list of agents will be displayed. (Ref screen below).
3. Open the above two agents. Replace the agent code with the following code enclosed in the table below, if its 853 template.
4. Add the yellow highlighted code lines to the agent code at appropriate places in case of template other than 853 template.
Customizing the Agent - (Archive now)
This agent is triggered when user clicks on Actions - Archive – Archive now.
Design elements changed – Agent - (Archive now)
|
Function/Sub name changed – Initialize
|
Archive Size Max Limit is set to - 4.0 GB (Change the value to your required value)
The Base code used is from 853 Mail Template.
Changed/added lines of code in between the ******.
-
Replace the agent code with the following code in case of 853 template.
-
Add the highlighted lines to the code appropriately in case of templates other than 853 template.
|
Option Public
Option Declare
Use "Common"
Sub Initialize
Const CRLF = {
}
Const ArcProhibit = "Archiving is prohibited by a policy an administrator set."
Const ArcNotInit = "Before archiving, you must confirm your archive settings."_
& CRLF & CRLF & "Click OK on the next window to confirm your archive settings."
Const ArcTitle = "Archive"
'****************************************************
Const dlgTitle = "Move to Archive Destination"
'** Configure Archive Size here **************
Const ARCHIVE_MAX_SIZE = 4.0 'GB
'****************************************************
Dim oneGB As Long
oneGB = 1073741824
Dim oneMB As Long
oneMB = 1048576
'****************************************************
On Error GoTo Trap
Dim StringTable As New mailtoolsstringtable
Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim lngReturn As Long
'****************************************************
Dim oneliner, twoliner As String
Dim answer As Integer
Dim policyList As Variant
Dim PolicyArchPath As String
Dim index, index1, result, preRNext As Integer
Dim stopflag, warningflag, NewDBflag, alertFlag As Boolean
Dim WarningDBlist, exceedDBlist, needsSetup As String
Dim OldPolicyArchPath List As String
Dim uidb As NotesUIDatabase
Dim oldb As NotesDatabase
Dim coll As NotesDocumentCollection
Dim dlgNote As NotesDocument
Dim pdoc As NotesDocument
Dim Adb As New NotesDatabase("","")
Set uidb = ws.currentdatabase
NewDBflag = False
oneliner = ""
answer =0
'****************************************************
Set db = s.currentdatabase
If YesNoPrompt(StringTable.GetString(TOOL_STRING+77,Null),StringTable.GetString(TOOL_STRING+75,Null)) Then
'****************************************************
' Begin Adding code for Size check
'________________ for sending notification
Dim calprof As NotesDocument
Set calprof = db.GetProfileDocument("calendarprofile")
Dim mfOwner As Variant
mfOwner = calprof.Owner
Dim ntdoc As NotesDocument
Dim rtitem As NotesRichTextItem
Set ntdoc = New NotesDocument( db )
ntdoc.Form = "Memo"
ntdoc.SendTo = mfOwner
ntdoc.Subject = "Archive: New archive database created."
Set rtitem = New NotesRichTextItem( ntdoc, "Body" )
Call rtitem.AppendText( "Your Archive database(s) reached the Maximum Size Limit of " + CStr(ARCHIVE_MAX_SIZE) +"GB." )
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "New Archive database(s) created. Same can be opened by clicking Archive --> Select Criteria from the main navigator.")
Call rtitem.AddNewLine( 2 )
'______________________
policyList = db.ArchiveDestinations
If Not IsEmpty(policylist) Then
For index=0 To UBound(policylist)
PolicyArchPath = db.GetArchivePath(policyList(index))
OldPolicyArchPath(index+1) = db.GetArchivePath(policyList(index))
Set pdoc = db.GetProfileDocument(policyList(index))
Set Adb = New NotesDatabase( "", PolicyArchPath )
Set oldb = New NotesDatabase( "", PolicyArchPath )
Dim Apath As String, tempApath As String
Dim AdbNum1 As String, AdbNum2 As String, AdbNum3 As String
Do
If Not Adb.IsOpen Then
Exit Do
End If
If (Adb.size > (ARCHIVE_MAX_SIZE * oneGB)) Then
Apath = PolicyArchPath
NewDBflag = True
AdbNum1 = Mid$(Apath, (CInt(Len(Apath))-4), 1)
AdbNum2 = Mid$(Apath, (CInt(Len(Apath))-5), 2)
AdbNum3 = Mid$(Apath, (CInt(Len(Apath))-6), 3)
If IsNumeric(AdbNum3) Then
tempApath = Mid$(Apath, 1, (CInt(Len(Apath))-4))
pdoc.ArchivePath = tempApath + "_1" +".nsf"
Else
If IsNumeric(AdbNum2) Then
tempApath = Mid$(Apath, 1, (CInt(Len(Apath))-6))
pdoc.ArchivePath = tempApath + CStr(CInt(AdbNum2)+1)+".nsf"
Else
If IsNumeric(AdbNum1) Then
tempApath = Mid$(Apath, 1, (CInt(Len(Apath))-5))
pdoc.ArchivePath = tempApath + CStr(CInt(AdbNum1)+1)+".nsf"
Else
tempApath = Mid$(Apath, 1, (CInt(Len(Apath))-4))
pdoc.ArchivePath = tempApath + "_1" +".nsf"
End If
End If
End If
Call pdoc.save(True, True)
PolicyArchPath = pdoc.ArchivePath(0)
Set Adb = New NotesDatabase( "", PolicyArchPath )
If Adb.IsOpen Then
Else
Exit Do
End If
End If
Loop Until (Adb.size < (ARCHIVE_MAX_SIZE * oneGB))
If NewDBflag Then
AlertFlag = True
Call rtitem.AppendText( "Archive Criteria: " + policyList(index) )
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "Old Archive Database Path: " + oldb.Filepath + " - " )
Call rtitem.AppendDocLink( oldb, oldb.Filepath )
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "New Archive Database Path:" + pdoc.ArchivePath(0))
Call rtitem.AddNewLine( 2 )
End If
NewDBFlag = False
Next
End If
If Alertflag Then
twoLiner = |Archive database(s) has reached the Max size limit of | & ARCHIVE_MAX_SIZE &|GB.| + Chr(13) + |
New Archive database(s) will be created automatically and the details will be sent to you by email.|++chr(13) + |Do you want to continue?|
answer= MessageBox (twoLiner, MB_YESNO+MB_ICONQUESTION, ArcTitle)
If answer = 7 Then
For index1=0 To UBound(policylist)
Set pdoc = db.GetProfileDocument(policyList(index1))
pdoc.ArchivePath = OldPolicyArchPath(index1+1)
Call pdoc.save(True, True)
Next
Exit Sub
End If
End If
' End Adding code for Size check
'****************************************************
'Archive:
lngReturn = db.archiveNow()
'******************** sending notification *********
If (Alertflag And (answer = 6)) Then
Call ntdoc.Send( False )
End If
'****************************************************
End If
If Not(ws.CurrentView Is Nothing) Then
If Not(ws.CurrentView.View Is Nothing) Then
Call ws.CurrentView.DeselectAll
End If
End If
Exit Sub
Trap:
On Error Resume Next
Dim sterr As String
If Err = 184 Then
sterr= MsgBox (ArcProhibit, MB_OK+MB_ICONEXCLAMATION,ArcTitle)
Else
Dim profColl As NotesDocumentCollection
Set profColl = db.Getprofiledoccollection("archive profile")
If Not(profColl.Count>= 1) Then
sterr= MsgBox (ArcNotInit, MB_OK+MB_ICONEXCLAMATION,ArcTitle)
Dim setAgent As NotesAgent
Set setAgent = db.GetAgent("(archivesettings)")
Call setAgent.Run
Else
Call DisplayWarn(Error$ & Chr(10),MB_OK,StringTable.GetString(TOOL_STRING+75,Null))
End If
End If
If Not(ws.CurrentView Is Nothing) Then
If Not(ws.CurrentView.View Is Nothing) Then
Call ws.CurrentView.DeselectAll
End If
End If
Exit Sub
End Sub
Customizing the Agent: (Archive Selected Documents)
This agent is triggered when user clicks on Actions - Archive – Archive selected documents.
Design elements changed – Agent - (Archive Selected Documents)
|
Function/Sub name changed – Initialize
|
Archive Size Max Limit is set to - 4.0 GB (Change the value to your required value)
The Base code used is from 853 Mail Template.
Changed/added lines of code in between the ******.
-
Replace the agent code with the following code in case of 853 template.
-
Add the highlighted lines to the code appropriately in case of templates other than 853 template.
|
Option Public
Option Declare
Use "Common"
Sub Initialize
Const CRLF = {
}
Const ArcProhibit = "Archiving is prohibited by a policy an administrator set."
Const ArcNotInit = "Before archiving, you must confirm your archive settings."_
& CRLF & CRLF & "Click OK on the next window to confirm your archive settings."
Const ArcTitle = "Archive"
Const dlgTitle = "Move to Archive Destination"
'****************************************************
'** Configure Archive Size here **************
Const ARCHIVE_MAX_SIZE = 4.0 'GB
'****************************************************
Dim oneGB As Long
oneGB = 1073741824
Dim oneMB As Long
oneMB = 1048576
'****************************************************
On Error GoTo Trap
Dim s As New NotesSession
Dim uiws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim coll As NotesDocumentCollection
Dim StringTable As New mailtoolsstringtable
Dim policyList As Variant
Dim result As Integer
Dim policy As String
Dim collection As NotesDocumentCollection
Dim dlgNote As NotesDocument
Dim preRNext As Integer
Dim needsSetup As String
'****************************************************
Dim uidb As NotesUIDatabase
Dim oldb As NotesDatabase
Dim twoliner As String
Dim answer As Integer
Dim PolicyArchPath As String, OldPolicyArchPath As string
Dim NewDBflag As Boolean
Set uidb = uiws.currentdatabase
Dim n As Integer
n=1
'****************************************************
Set db = s.currentdatabase
Set collection = db.unprocesseddocuments
If s.Notesbuildversion < 167 Then
GoTo ArchivePreRnext
End If
Archive:
policyList = db.ArchiveDestinations
If ( IsNull(policyList)) Or (IsEmpty(policylist)) Then
needsSetup =|In order to archive selected documents, you must have at least one archive criteria enabled that specifies
an archive database destination.
To change your archive settings, use the Actions - Archive - Settings menu item.|
GoTo Trap
End If
'prompt for which policy to archive to
Set dlgNote = s.currentDatabase.createDocument
Call dlgNote.replaceitemvalue("tmpListOfPolicies", FullTrim(policyList)) 'DNT
Call dlgNote.replaceitemvalue("tmpPrompt", |Select an Archive Destination:|) 'DNT
' load up ArchivePolicyList Dialog
result = uiws.DialogBox("(RepeatOpenList)", True, True, False, , , , dlgTitle, dlgNote, True) 'DNT
' if user didn't cancel, send collection to selected policy
If result <> False Then
policy = dlgNote.GetItemValue("tmpPolicySelected")(0) 'DNT
'****************************************************
' Begin Adding code for Size check
PolicyArchPath = db.GetArchivePath(policy)
OldPolicyArchPath = db.GetArchivePath(policy)
Dim Adb As New NotesDatabase("","")
Dim profColl_1 As NotesDocumentCollection
Set profColl_1 = db.Getprofiledoccollection(Policy)
Dim pdoc As NotesDocument
Set pdoc = db.GetProfileDocument(Policy)
'MsgBox PolicyArchPath
Set Adb = New NotesDatabase( "", PolicyArchPath )
Set oldb = New NotesDatabase( "", PolicyArchPath )
Dim Apath As String, tempApath As String
Dim AdbNum1 As String, AdbNum2 As String, AdbNum3 As String
Do
If Not (Adb.IsOpen) Then
Exit Do
Else
'Max size
If Adb.size > ARCHIVE_MAX_SIZE * oneGB Then
Apath = pdoc.ArchivePath(0)
NewDBflag = True
AdbNum1 = Mid$(Apath, (CInt(Len(Apath))-4), 1)
AdbNum2 = Mid$(Apath, (CInt(Len(Apath))-5), 2)
AdbNum3 = Mid$(Apath, (CInt(Len(Apath))-6), 3)
If IsNumeric(AdbNum3) Then
tempApath = Mid$(Apath, 1, (CInt(Len(Apath))-4))
pdoc.ArchivePath = tempApath + "_1" +".nsf"
Else
If IsNumeric(AdbNum2) Then
tempApath = Mid$(Apath, 1, (CInt(Len(Apath))-6))
pdoc.ArchivePath = tempApath + CStr(CInt(AdbNum2)+1)+".nsf"
Else
If IsNumeric(AdbNum1) Then
tempApath = Mid$(Apath, 1, (CInt(Len(Apath))-5))
pdoc.ArchivePath = tempApath + CStr(CInt(AdbNum1)+1)+".nsf"
Else
tempApath = Mid$(Apath, 1, (CInt(Len(Apath))-4))
pdoc.ArchivePath = tempApath + "_1" +".nsf"
End If
End If
End If
Call pdoc.save(True, True)
PolicyArchPath = pdoc.ArchivePath(0)
Set Adb = New NotesDatabase( "", PolicyArchPath )
If Adb.IsOpen Then
Else
Exit Do
End If
End If
End if
Loop Until (Adb.size < ARCHIVE_MAX_SIZE * oneGB)
If NewDBflag Then
twoLiner = |Archive database has reached the Max size limit of | & ARCHIVE_MAX_SIZE &|GB.| + Chr(13) + |
New Archive database will be created automatically and the details will be sent to you by email.|++chr(13) + |Do you want to continue?|
answer= MessageBox (twoLiner, MB_YESNO+MB_ICONQUESTION, ArcTitle)
If answer = 7 Then
pdoc.ArchivePath = OldPolicyArchPath
Call pdoc.save(True, True)
Exit Sub
End If
End If
'****************************************************
Call db.archiveNow( collection, policy )
Call uiws.Viewrefresh()
'******************** sending notification *********
If (NewDBflag And (answer = 6)) Then
Dim calprof As NotesDocument
Set calprof = db.GetProfileDocument("calendarprofile")
Dim mfOwner As Variant
mfOwner = calprof.Owner
Dim ntdoc As NotesDocument
Dim rtitem As NotesRichTextItem
Set ntdoc = New NotesDocument( db )
ntdoc.Form = "Memo"
ntdoc.SendTo = mfOwner
ntdoc.Subject = "Archive: New archive database created."
'--------
Set rtitem = New NotesRichTextItem( ntdoc, "Body" )
Call rtitem.AppendText( "Your Archive database reached the Maximum Size Limit of " + CStr(ARCHIVE_MAX_SIZE) +"GB." )
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "Archive Criteria: " + policy )
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "Archive Database Path: " + oldb.Filepath + " - " )
Call rtitem.AppendDocLink( oldb, oldb.Filepath )
Call rtitem.AddNewLine( 1 )
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "Following New Archive database is created. Same can be opened by clicking Archive --> Select Criteria from the main navigator.")
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "New Archive Database Path:" + pdoc.ArchivePath(0))
Call rtitem.AddTab( 1 )
Call ntdoc.Send( False )
End If
'****************************************************
End If
Exit Sub
ArchivePreRNext:
If YesNoPrompt(StringTable.GetString(TOOL_STRING+76,coll.count),StringTable.GetString(TOOL_STRING+75,Null)) Then
Call db.archiveNow( collection )
Call uiws.Viewrefresh()
End If
Exit Sub
Trap:
On Error Resume Next
Dim sterr As String
Dim profColl As NotesDocumentCollection
Set profColl = db.Getprofiledoccollection("archive profile")
If Err = 184 Then
sterr= MsgBox (ArcProhibit, MB_OK+MB_ICONEXCLAMATION,ArcTitle)
ElseIf Not(profColl.Count>= 1) Then
sterr= MsgBox (ArcNotInit, MB_OK+MB_ICONEXCLAMATION,ArcTitle)
Dim setAgent As NotesAgent
Set setAgent = db.GetAgent("(archivesettings)")
Call setAgent.Run
Else
Call DisplayWarn(needsSetup & Error$ & Chr(10),MB_OK,StringTable.GetString(TOOL_STRING+75,Null))
End If
Exit Sub
End Sub
Conclusion
Your archive roll-over set up is now complete. When the threshold size of an archive database is met, a new database will be created.
References:
About the Author
Maitreyee Patukale is working with IBM - India Software Labs, as Senior Software Engineer. She is a Notes Client developer and is interested in Template development. You can reach Maitreyee at Maitreyeep@in.ibm.com.