Copy documents from a database to another

Hi everybody.I have this situation:

2 different DB.

I wanto to open destination DB DATABASE1 (which has 2 views A1 & A2) and have an agent that first delete all documents he has inside and then copies documents from the other DB DATABASE2 (which has 2 views B1 & B2).

Any idea how to do this.

Thanks in advance for your help.

Subject: Copy documents from a database to another

Create an agent in DATABASE1.Copy this code in it:

Sub Initialize

Dim Session As New NotesSession

Dim DB1 As NotesDatabase, DB2 As NotesDatabase

Dim Collection As NotesDocumentCollection

Dim Document As NotesDocument

Set DB1 = Session.CurrentDatabase

Set DB2 = Session.GetDatabase(DB2_Server,"DB2_Folder\DB2_File_Name.nsf")

Set Collection = DB1.AllDocuments

Call Collection.RemoveAll(True)

Set Collection = DB2.AllDocuments

Set Document = Collection.GetFirstDocument

While Not Document Is Nothing

	Call Document.CopyToDatabase(DB1)

	Set Document = Collection.GetNextDocument(Document)

Wend

End Sub

Choose the target as “None”

All what you need to change is DB2_Server and DB2_Folder\DB2_File_Name.nsf to have the right values

Run the agent.

Regards,

Fadi Kiwan

Subject: RE: Copy documents from a database to another

Fadi,many thanks your script is working fine!

It does exactly what I meant.

Thanks a lot.

Subject: RE: Copy documents from a database to another

Fadi, only one issue.I tested the script in local and as said it is perfect.

If I use it on the server it says that the DB2 has not been opened yet…

I don’t understand why. Anyhow the two DBs are on the same server.

A hint would be apreciated.

Thanks a lot and regards.

Subject: RE: Copy documents from a database to another

Ruggia,

Try to replace DB2_Server by DB1.server

Regards,

Fadi Kiwan

Subject: Copy documents from a database to another

It can be done pretty easily, but can’t you use replication? Would be a much more robust approach.

Subject: RE: Copy documents from a database to another

Well thanks for the suggestion but it’s about 2 different DB type. The solution presented by Fadi on the previous response is exactly what I meant. Thanks anyhow for your hint.regards.

Subject: RE: Copy documents from a database to another

If this is just what you need, that’s fine.

Just remember, that replicas don’t have to be identical. You can replicate only selected documents and have completely different designs. However, configuring replication settings and ACLs might take some care.

If this is a one-time copy (or happens only occasionally), copying is much more reasonable. However, if there are many documents being copied day by day, be aware of the fact that many many deletion stubs will build up over time. This will also impact replicas of the target database, if any.

Again, if all this is no issue, the Script is a good solution.