LogStore.CreateLogArchiveSnapshot 方法

定义

拍摄制作备份所需的日志存储区状态的快照。Takes a snapshot of the log store state necessary to make a backup.

重载

CreateLogArchiveSnapshot()

拍摄日志存储区状态的快照,以制作备份。Takes a snapshot of the log store state for making a backup.

CreateLogArchiveSnapshot(SequenceNumber, SequenceNumber)

拍摄指定序列号之间的日志存储区状态的快照,以制作备份。Takes a snapshot of the log store state between the specified sequence numbers for making a backup.

CreateLogArchiveSnapshot()

拍摄日志存储区状态的快照,以制作备份。Takes a snapshot of the log store state for making a backup.

public:
 System::IO::Log::LogArchiveSnapshot ^ CreateLogArchiveSnapshot();
public System.IO.Log.LogArchiveSnapshot CreateLogArchiveSnapshot ();
member this.CreateLogArchiveSnapshot : unit -> System.IO.Log.LogArchiveSnapshot
Public Function CreateLogArchiveSnapshot () As LogArchiveSnapshot

返回

一个包含制作存档所需状态的 LogArchiveSnapshot 对象。A LogArchiveSnapshot object that contains the state necessary to make an archive.

例外

日志存储区不可存档。The log store is not archivable.

该方法是在序列已释放之后调用的。The method was called after the sequence has been disposed of.

创建存档快照时发生 I/O 错误。An I/O error occurs when creating the archive snapshot.

自变量无效。An argument is not valid.

执行了无效的操作。An invalid operation has been executed.

没有足够的内存来继续执行程序。There is not enough memory to continue the execution of a program.

记录序列已满。The record sequence is full.

操作系统拒绝了对指定的日志存储区的访问。Access for the specified log store is denied by the operating system.

示例

下面的示例演示如何将 LogStore 存档到 XML 文档。The following example shows how to archive a LogStore to an XML document.

class LogBackup
{ 
    static void ArchiveToXML(LogStore logStore, string fileName) 
    {  
        LogArchiveSnapshot snapshot = logStore.CreateLogArchiveSnapshot();
        
        XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.ASCII);
        
        writer.WriteStartElement("logArchive");
        foreach(FileRegion region in snapshot.ArchiveRegions) 
        {
            writer.WriteStartElement("fileRegion"); 
            writer.WriteElementString("path", region.Path); 
            writer.WriteElementString("length", region.FileLength.ToString()); 
            writer.WriteElementString("offset", region.Offset.ToString()); 
            using(Stream dataStream = region.GetStream()) 
            { 
                byte[] data = new byte[dataStream.Length]; 
                dataStream.Read(data, 0, data.Length); 
                writer.WriteElementString("data", Convert.ToBase64String(data)); 
            }
            writer.WriteEndElement();
        }
        writer.WriteEndElement(); 
        writer.Close(); 
        logStore.SetArchiveTail(snapshot.LastSequenceNumber); 
    }
    static void RestoreFromXML(string fileName) 
    { 
        using(XmlTextReader reader = new XmlTextReader(fileName)) 
        {
            reader.ReadStartElement("logArchive"); 
            while(reader.IsStartElement()) 
            { 
                string path = reader.ReadElementString("path"); 
                long length = Int64.Parse(reader.ReadElementString("length")); 
                long offset = Int64.Parse(reader.ReadElementString("offset")); 
                string dataString = reader.ReadElementString("data"); 
                byte[] data = Convert.FromBase64String(dataString); 
                FileStream fileStream;
                using(fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) 
                { 
                    fileStream.SetLength(length); 
                    fileStream.Position = offset; fileStream.Write(data, 0, data.Length); 
                }
            } 
        reader.ReadEndElement(); 
        } 
    } 
}
Friend Class LogBackup
    Private Shared Sub ArchiveToXML(ByVal logStore As LogStore, ByVal fileName As String)
        Dim snapshot As LogArchiveSnapshot = logStore.CreateLogArchiveSnapshot()

        Dim writer As New XmlTextWriter(fileName, Encoding.ASCII)

        writer.WriteStartElement("logArchive")
        For Each region As FileRegion In snapshot.ArchiveRegions
            writer.WriteStartElement("fileRegion")
            writer.WriteElementString("path", region.Path)
            writer.WriteElementString("length", region.FileLength.ToString())
            writer.WriteElementString("offset", region.Offset.ToString())
            Using dataStream As Stream = region.GetStream()
                Dim data(dataStream.Length - 1) As Byte
                dataStream.Read(data, 0, data.Length)
                writer.WriteElementString("data", Convert.ToBase64String(data))
            End Using
            writer.WriteEndElement()
        Next region
        writer.WriteEndElement()
        writer.Close()
        logStore.SetArchiveTail(snapshot.LastSequenceNumber)

    End Sub
    Private Shared Sub RestoreFromXML(ByVal fileName As String)
        Using reader As New XmlTextReader(fileName)
            reader.ReadStartElement("logArchive")
            Do While reader.IsStartElement()
                Dim path = reader.ReadElementString("path")
                Dim length = Int64.Parse(reader.ReadElementString("length"))
                Dim offset = Int64.Parse(reader.ReadElementString("offset"))
                Dim dataString = reader.ReadElementString("data")
                Dim data() = Convert.FromBase64String(dataString)
                Dim fileStream As FileStream
                fileStream = New FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)
                Using fileStream
                    fileStream.SetLength(length)
                    fileStream.Position = offset
                    fileStream.Write(data, 0, data.Length)
                End Using
            Loop
            reader.ReadEndElement()
        End Using
    End Sub
End Class

CreateLogArchiveSnapshot(SequenceNumber, SequenceNumber)

拍摄指定序列号之间的日志存储区状态的快照,以制作备份。Takes a snapshot of the log store state between the specified sequence numbers for making a backup.

public:
 System::IO::Log::LogArchiveSnapshot ^ CreateLogArchiveSnapshot(System::IO::Log::SequenceNumber first, System::IO::Log::SequenceNumber last);
public System.IO.Log.LogArchiveSnapshot CreateLogArchiveSnapshot (System.IO.Log.SequenceNumber first, System.IO.Log.SequenceNumber last);
member this.CreateLogArchiveSnapshot : System.IO.Log.SequenceNumber * System.IO.Log.SequenceNumber -> System.IO.Log.LogArchiveSnapshot
Public Function CreateLogArchiveSnapshot (first As SequenceNumber, last As SequenceNumber) As LogArchiveSnapshot

参数

first
SequenceNumber

要存档的范围中的起始序列号。The starting sequence number in the range to archive.

last
SequenceNumber

要存档的范围中的结束序列号。The ending sequence number in the range to archive.

返回

一个包含制作存档所需状态的 LogArchiveSnapshot 对象。A LogArchiveSnapshot object that contains the state necessary to make an archive.

例外

firstlast 不在此序列的基序列号和最新序列号之间。first or last is not between the base and last sequence numbers of this sequence.

first 大于 lastfirst is larger than last.

执行了无效的操作。An invalid operation has been executed.

创建存档快照时发生 I/O 错误。An I/O error occurs when creating the archive snapshot.

日志存储区不可存档。The log store is not archivable.

该方法是在序列已释放之后调用的。The method was called after the sequence has been disposed of.

没有足够的内存来继续执行程序。There is not enough memory to continue the execution of a program.

记录序列已满。The record sequence is full.

操作系统拒绝了对指定的日志存储区的访问。Access for the specified log store is denied by the operating system.

注解

此方法返回的存档快照包含从基序列号或存档序列号(两者的较低者)到最新序列号之间的信息。The archive snapshot returned from this method encompasses information from either the base sequence number or the archive sequence number, whichever is lower, to the last sequence number. 其中不包含最新序列号,这表示,存档仅包含截至但不包括最后一条的记录。It is not inclusive for the last sequence number, which means that the archive only includes records up to but not including last. 此外,使用此方法时,起始 SequenceNumber 必须等于 BaseSequenceNumber,以保证存档的一致性。In addition, when using this method, the start SequenceNumber must be equal to the BaseSequenceNumber in order for the archive to be consistent.

适用于