Lotus Notes 脚本:备份所有服务器数据库
LotusNotes Script: backup All server database
今天我尝试通过右键单击数据库-> 新副本来创建数据库(设计和文档)的副本...我看到数据库的新副本具有源数据库的最小维度(源数据库 900mb 和新副本 170mb)。
我还看到如果我访问这个数据库的新副本,大小从 170mb 到 400mb(我认为是因为笔记创建索引......)
但是我只需要复制数据库来创建备份,所以大小很重要,因为我必须每天进行备份并且只在特定情况下查阅它。
所以我构建了一个代理来执行此副本但结果不一样,新副本与源数据库具有相同的维度。
是否有获得相同"compression" 右键单击数据库-> 新副本...但使用脚本代码的技巧?
我post我使用但没有压缩的代码:
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
您所说的 "compression" 只是视图索引的 "absence"。
数据库大小包括:
- 所有文档的大小
- 数据库的设计大小
- 空Space(如果数据已删除,但数据库未压缩)
- 查看指数
新副本(通过客户端)没有索引,但是一旦打开视图,数据库的大小就会增加。
您的脚本不适合备份:
- 所有文档都获得一个新的 Creation Stamp
- 所有文档都获得一个新的副本 ID - 响应- 层次结构将在您复制后完全丢失
等
如果你真的想朝那个方向发展,那么你将不得不使用 compact -D 来压缩数据库以获得免费 space 和视图索引,
但我永远不会像这样备份生产数据库...
另一种(更好的)可能性是使用 LotusScript- 代码创建一个新副本并对其进行备份:
Set ArchiveDb = SourceDb.CreateReplica( "", "C:\Test\"+Cstr(Day(Date))+"-"+Cstr(Month(Date))+"-"+Cstr(Year(Date))+"\"+SourceDb.FilePath)
如果您在备份后保留该数据库,那么您可能需要使用以下代码更改数据库的副本 ID:
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
但我能给出的最佳建议是:使用专业的备份软件来完成这项工作。
今天我尝试通过右键单击数据库-> 新副本来创建数据库(设计和文档)的副本...我看到数据库的新副本具有源数据库的最小维度(源数据库 900mb 和新副本 170mb)。 我还看到如果我访问这个数据库的新副本,大小从 170mb 到 400mb(我认为是因为笔记创建索引......) 但是我只需要复制数据库来创建备份,所以大小很重要,因为我必须每天进行备份并且只在特定情况下查阅它。
所以我构建了一个代理来执行此副本但结果不一样,新副本与源数据库具有相同的维度。 是否有获得相同"compression" 右键单击数据库-> 新副本...但使用脚本代码的技巧?
我post我使用但没有压缩的代码:
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
您所说的 "compression" 只是视图索引的 "absence"。 数据库大小包括:
- 所有文档的大小
- 数据库的设计大小
- 空Space(如果数据已删除,但数据库未压缩)
- 查看指数
新副本(通过客户端)没有索引,但是一旦打开视图,数据库的大小就会增加。
您的脚本不适合备份:
- 所有文档都获得一个新的 Creation Stamp
- 所有文档都获得一个新的副本 ID - 响应- 层次结构将在您复制后完全丢失
等
如果你真的想朝那个方向发展,那么你将不得不使用 compact -D 来压缩数据库以获得免费 space 和视图索引, 但我永远不会像这样备份生产数据库...
另一种(更好的)可能性是使用 LotusScript- 代码创建一个新副本并对其进行备份:
Set ArchiveDb = SourceDb.CreateReplica( "", "C:\Test\"+Cstr(Day(Date))+"-"+Cstr(Month(Date))+"-"+Cstr(Year(Date))+"\"+SourceDb.FilePath)
如果您在备份后保留该数据库,那么您可能需要使用以下代码更改数据库的副本 ID:
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
但我能给出的最佳建议是:使用专业的备份软件来完成这项工作。