Bewerken

Share via


LogStore.CreateLogArchiveSnapshot Method

Definition

Takes a snapshot of the log store state necessary to make a backup.

Overloads

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

Returns

A LogArchiveSnapshot object that contains the state necessary to make an archive.

Exceptions

The log store is not archivable.

The method was called after the sequence has been disposed of.

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.

Examples

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

Applies to

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

Parameters

first
SequenceNumber

The starting sequence number in the range to archive.

last
SequenceNumber

The ending sequence number in the range to archive.

Returns

A LogArchiveSnapshot object that contains the state necessary to make an archive.

Exceptions

first or last is not between the base and last sequence numbers of this sequence.

first is larger than last.

An invalid operation has been executed.

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.

Remarks

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. In addition, when using this method, the start SequenceNumber must be equal to the BaseSequenceNumber in order for the archive to be consistent.

Applies to