今天我试图通过右键点击数据库来做一个数据库(设计和文档)的副本 - >新副本......我看到数据库的新副本具有源数据库的最小维度(源数据库900mb和新副本170mb)。 我也看到如果我访问这个数据库的新副本,大小从170mb传递到400mb(我想是因为笔记创建索引...) 但我只需要复制数据库来创建一个备份,所以大小很重要,因为我必须做每日备份,并仅在特定情况下进行咨询。
所以我构建了一个代理来执行此复制,但结果不一样,新副本具有与源数据库相同的维度。 是否有诀窍可以获得相同的"压缩"右击数据库 - >新副本......但是使用脚本代码?
我发布了我使用但没有压缩的代码:
Dim Db As NotesDatabase
Dim Ws As New NotesUIWorkspace
Dim Session As New NotesSession
Dim DbDir As NotesDbDirectory
Dim AllDocs As NotesView
Dim SourceDb As NotesDatabase
Dim ArchiveDb As NotesDatabase
Dim SourceDoc As NotesDocument
Set Db=Session.CurrentDatabase
Set DbDir=Session.GetDbDirectory(Db.Server)
Set SourceDb = DbDir.GetFirstDatabase(DATABASE)
Do While Not SourceDb Is Nothing
Print"BackUp Database "+Cstr(SourceDb.FileName)
Gosub BackUpDatabase
Set SourceDb = DbDir.GetNextDatabase
Loop
Exit Sub
BackUpDatabase:
If SourceDb.IsOpen=False Then Call SourceDb.Open( "", "" )
Set ArchiveDb = SourceDb.CreateCopy( "", "C:\Test\"+Cstr(Day(Date))+"-"+Cstr(Month(Date))+"-"+Cstr(Year(Date))+"\"+SourceDb.FilePath)
Set AllDocs = SourceDb.CreateView( "@AllDocs", "SELECT @All" )
Set SourceDoc=AllDocs.GetFirstDocument
Do While Not SourceDoc Is Nothing
Call SourceDoc.CopyToDatabase(ArchiveDb)
Set SourceDoc=AllDocs.GetNextDocument(SourceDoc)
Loop
Call AllDocs.Remove()
Return
答案 0 :(得分:2)
你称之为“压缩”只是视图索引的“缺席”。 数据库大小包括:
新副本(通过客户端)没有索引,但只要打开视图,数据库的大小就会增加。
您的脚本不适合备份:
等。
如果你真的想要朝这个方向发展,那么你必须使用compact -D压缩数据库以获得可用空间和视图索引, 但我永远不会像这样备份生产数据库...
另一种(更好的)可能性是使用LotusScript代码创建一个新的副本并对其进行备份:
Set ArchiveDb = SourceDb.CreateReplica( "", "C:\Test\"+Cstr(Day(Date))+"-"+Cstr(Month(Date))+"-"+Cstr(Year(Date))+"\"+SourceDb.FilePath)
如果在执行备份后保留该数据库,则可能需要使用以下代码更改数据库的副本:
Option Public
Option Declare
Const wAPIModule = "NNOTES" ' Windows/32
Type API_TIMEDATE
lngInnards(1) As Long
End Type
Type API_DBREPLICAINFO
ID As API_TIMEDATE 'ID that is same for all replica files
intFlags As Integer 'Replication flags
intCutoffInterval As Integer 'Automatic Replication Cutoff
Cutoff As API_TIMEDATE 'Replication cutoff date
End Type
Declare Private Function NSFDbOpen Lib wAPIModule Alias "NSFDbOpen" _
( ByVal P As String, hDB As Long) As Integer
Declare Private Function NSFDbClose Lib wAPIModule Alias "NSFDbClose" _
( ByVal hDB As Long) As Integer
Declare Private Function NSFDbReplicaInfoGet Lib wAPIModule Alias "NSFDbReplicaInfoGet" _
(ByVal hdb As Long, hdbr As API_DBREPLICAINFO) As Integer
Declare Private Function NSFDbReplicaInfoSet Lib wAPIModule Alias "NSFDbReplicaInfoSet" _
(ByVal hdb As Long, hdbr As API_DBREPLICAINFO) As Integer
Sub ChangeReplicaID( strServer As String, strFilePath As String, strReplicaID As String )
Dim intRc As Integer
Dim lngDb As Long
Dim RepInfo As API_DBREPLICAINFO
If strServer = "" Then
intRc = NSFDbOpen( strFilePath, lngDb )
Else
intRc = NSFDbOpen( strServer & "!!" & strFilePath, lngDb )
End If
If intRc <> 0 Then
MessageBox "Could not open DB"
Exit Sub
End If
intRc = NSFDbReplicaInfoGet(lngDb, RepInfo)
If intRc <> 0 Then
MessageBox "Could not get replication info"
Exit Sub
End If
RepInfo.ID.lngInnards(1) = Val( "&H"+Left$( strReplicaID, 8 ) )
RepInfo.ID.lngInnards(0) = Val( "&H"+Right$( strReplicaID, 8 ) )
intRc = NSFDbReplicaInfoSet( lngDb, RepInfo) ' take a deep breath... :-)
intRc = NSFDbReplicaInfoGet( lngDb, RepInfo)
If intRc <> 0 Then
MessageBox "Could not get replication info after setting"
Else
MessageBox "Success"
End If
End Sub
但我能给出最好的建议:使用专业的备份软件来完成这项工作。