Export (0) Print
Expand All

LogStore.CreateLogArchiveSnapshot Method

Takes a snapshot of the log store state for making a backup.

Namespace:  System.IO.Log
Assembly:  System.IO.Log (in System.IO.Log.dll)

public LogArchiveSnapshot CreateLogArchiveSnapshot()

Return Value

Type: System.IO.Log.LogArchiveSnapshot
A LogArchiveSnapshot object that contains the state necessary to make an archive.

ExceptionCondition
NotSupportedException

The log store is not archivable.

ObjectDisposedException

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

IOException

An I/O error occurs when creating the archive snapshot.

ArgumentException

An argument is not valid.

InvalidOperationException

An invalid operation has been executed.

OutOfMemoryException

There is not enough memory to continue the execution of a program.

SequenceFullException

The record sequence is full.

UnauthorizedAccessException

Access for the specified log store is denied by the operating system.

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(); 
        } 
    } 
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft