Archiving DBs with LotusScript

5 pts.
Tags:
Lotus Notes Development
LotusScript
I am a new contractor w/ no experience in  Lotusscript but have this daunting task of archiving 4600+ databases for a conversion of in-house applications to Domino.  Is there an easy way in lotus script, lets say via a button, to take a database, create a copy of that database and place it in an "Archives" directory, then add the word ARCHV to the Title and the filename, and then set the ACL to READERS for everyone but the Admin Team ,and then create a record of the database with a link  to the database for record keeping? Hope this makes sense Bill

Software/Hardware used:
Windows XP, Lotus Notes 8.0.x

Answer Wiki

Thanks. We'll let you know when a new response is added.

This approach might be reasonable, I haven’t tested any of the code but it should give you some ideas:

1. Create a new database, let’s call it Archive Manager.
In this database, we will create a record (notes document) for every database on the current server, to track progress of our archiving function, and to meet your final requirement (record of each database with link to database and to the archive).

2. Create an agent in the Archive Manager database, to analyse all databases on server.
This will build a NotesDbDirectory, and will create a NotesDocument in the current database for every database on the server. Something like:
<pre>
Dim s as New NotesSession
Dim dbCurrent as NotesDatabase
Dim db as NotesDatabase
Set dbCurrent = s.currentDatabase
Dim dbdir as New NotesDbDirectory( db.server )
set db = dbdir.getFirstDatabase(TEMPLATE_CANDIDATE) ‘ see help for parameter detail
Do while not db is nothing
call registerDatabase( dbCurrent, db )
Set db = dbdir.getNextDatabase
Loop

‘ this function is called from within loop above
‘ this will create a NotesDocument in the current database, which is a record for a database on the current server
Function registerDatabase(dbCurrent as NotesDatabase, db as NotesDatabase)
‘ NOTE: if you are likely to run this more than once, then put your own logic in to detect if db already has a record created for it – no point in having more than one record per database
Dim doc as NotesDocument
Set doc = dbCurrent.CreateDocument()
doc.Form=”DatabaseRecord”
doc.DbTitle = db.Title
doc.DbFilePath = db.FilePath
doc.ArchiveStatus=”Not Started”
doc.save true,true
End Function
</pre>

3. When the above has been done, you should have a Database Record document in the Archive Manager database for every database on the current server.

4. Write an agent that will run on selected Database Record documents (or via your own selection formula). For each Database Record document being processed, this agent will create a copy of the database in the archive directory, and set the ACL.
<pre>
Dim s as New NotesSession
Dim dbCurrent as NotesDatabase
Dim db as NotesDatabase
Dim dbArchive as NotesDatabase
Dim dc as NotesDocumentCollection
Dim doc as NotesDocument
set dbCurrent = s.currentDatabase
Set dc = dbCurrent.UnprocessedDocuments ‘ (assuming agent is run on selected docs)
set doc = dc.getFirstDocument
Do while not doc is nothing
‘ get database to archive
set db = s.getDatabase( dbCurrent.server, doc.filePath, false )
‘ create archive database
set dbArchive = db.createCopy( dbCurrent.server, “Archive”+doc.filePath )
‘ set title
dbArchive.Title = “ARCHV ” + dbArchive.Title
‘ copy docs from source database to archive
call copyDocs( db, dbArchive )
‘ set ACL
call setACL( dbArchive )
‘ update status
doc.Status = “Done”
doc.DbArchiveFilePath=dbArchive.filePath
doc.save true,true
set doc = dc.getNextDocument( doc )
Loop

Function copyDocs( dbSource, dbTarget )
Dim dc as NotesDocumentCollection
Dim doc as NotesDocument
set dc = dbSource.AllDocuments
set doc = dc.getFirstDocument
Do while not doc is nothing
call doc.copyToDatabase(dbTarget)
set doc = dc.getNextDocument( doc )
Loop
End Function

Function setACL( dbArchive )
Dim acl as NotesACL
Dim entry as NotesACLEntry
set acl = dbArchive.ACL
set entry = acl.getFirstEntry

‘ remove all entries except for servers
do while not entry is nothing
Select case entry.Name
Case “LocalDomainServers”, “OtherDomainServers”, “SERVERNAME” ‘enter your own server name here
Case else
entry.Remove
End Select
set entry = acl.getNextEntry( entry )
loop

‘ add entry for Admin Team (person running this agent should be a member
set entry = acl.CreateACLEntry( “Admin Team”, 6 ) ‘see help for params
call entry.EnableRole( “Role” ) ‘do this for any roles that the Admin Team needs

Call acl.Save

End Function
</pre>

5. Suggestions for improvement;
i). fix the bugs (above code was written ad lib in this forum, no error syntax/checking)
ii). In RegisterDatabase function, check if database is already registered to avoid having duplicate records.
iii). Add some error reporting.
iv). Consider changing to scheduled agents, so that code can run overnight on the server – quicker and less impact on performance.
v). On DatabaseRecord form, rather than pasting a link to the archive database programmatically, suggest putting a button with code to open archive database:
<pre>
Dim ws as New NotesUIWorkspace
Dim uidoc as NotesUIDocument
Dim doc as NotesDocument
set uidoc = ws.currentDocument
Set doc = uidoc.document
call ws.openDatabase( doc.parentDatabase.server, doc.DbArchiveFilePath(0) )
</pre>
vi). Create an additional button to open the original database (use code above, just change doc.DbArchiveFilePath to doc.DbFilePath).

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following