Repository navigation
Expand file tree
/
Copy pathcomparedb.py
More file actions
78 lines (60 loc) · 1.96 KB
/
Copy pathcomparedb.py
File metadata and controls
78 lines (60 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Usage : python dbcompare.py SourceServer path\to\database.nsf TargetServer
# Use "" for local
# Result is unpredictable if target server contains multiple replicas with the same ReplicaID
# This script needs pywin32
import sys
from win32com.client import Dispatch
step=0
# Return UNID list of all the documents in the provided collection
def getids(coll):
ids=[]
doc=coll.getfirstdocument()
while doc !=None:
ids.append(doc.universalid)
if not doc.isValid :
print ("Invalid document")
doc=coll.getnextdocument(doc)
return ids
s=Dispatch("Lotus.NotesSession")
s.initialize()
srvsrc = sys.argv[1]
srvtgt =sys.argv[3]
# Open source db
dbdir=s.getDbDirectory(srvtgt)
dbsrc=s.getdatabase(srvsrc,sys.argv[2])
# Open target db
dbtgt=dbdir.OpenDatabaseByReplicaID(dbsrc.ReplicaId)
# retrieve a list of all documents in the database
step=step + 1
print ("%d - Retrieving documents" % step)
docsrc=dbsrc.AllDocuments
doctgt=dbtgt.AllDocuments
# make a list of UNID for each db
step=step + 1
print ("%d - Retrieving UNIDs" % step)
idsrc=getids(docsrc)
idtgt=getids(doctgt)
# Printing missing documents
missing=False
step=step + 1
print ("%d - Report :\n" %step)
# Id of documents present in source database and missing in target database
for id in idsrc:
if not id in idtgt:
conflict=""
form=dbsrc.getdocumentbyunid(id).getitemvalue("form")[0]
if dbsrc.getdocumentbyunid(id).hasitem("$conflict"):
conflict="conflit"
print ("document %s (%s) missing from target db on server '%s' /!\ %s" % (id,form,srvtgt,conflict ))
missing=True
# Id of documents present in target database and missing in source database
for id in idtgt:
if not id in idsrc:
conflict=""
form=dbtgt.getdocumentbyunid(id).getitemvalue("form")[0]
if dbtgt.getdocumentbyunid(id).hasitem("$conflict"):
conflict="conflit"
print ("document %s (%s) missing from source db on server '%s' /!\ %s" % (id,form,srvsrc,conflict))
missing=True
if not missing:
print ("Replicas are synchronized\n")