Freigeben über


Gewusst wie: Anpassen der Inhaltsbereitstellung für verbindungslose Szenarien

Letzte Änderung: Mittwoch, 22. September 2010

Gilt für: SharePoint Server 2010

Die Inhaltsbereitstellung ist gut geeignet, wenn zwischen der Quellfarm und der Zielfarm immer eine gute Verbindung verfügbar ist. Eine zuverlässige, funktionierende Verbindung zwischen einer Quellerstellungsfarm und einer Zielproduktionsfarm ist jedoch nicht immer verfügbar. Beispielsweise stellen geografische Hindernisse, Firewalls, die den Zugriff verhindern, oder Netzwerkausfälle Situationen dar, in denen die Verwendung einer Netzwerkverbindung zum Übertragen eines Exportpakets an eine Zielproduktionsfarm nicht zuverlässig ist. In diesen Situationen empfiehlt Microsoft, mit dem Microsoft SharePoint Server 2010-Objektmodell und der Inhaltsmigrations-API von SharePoint Foundation die Export- und Importschritte der Inhaltsmigration programmgesteuert auszuführen, und nach einer Alternative zum Übertragen des Exportpakets an die Zielproduktionsfarm und zum anschließenden Ausführen des benutzerdefinierten Importcodes zu suchen.

Wie in Bereitstellen von Inhalt für Server beschrieben besteht jede Inhaltsbereitstellung aus drei Schritten: Export, Übertragung und Import. In diesem Szenario erfolgt die Übertragung nicht programmgesteuert, sondern manuell. Beispielsweise können Sie das exportierte Inhaltspaket auf tragbaren Medien übertragen oder die Daten mithilfe eines FTP-Clients in eine unabhängige Dateifreigabe hochladen, aus der Sie importieren können.

So exportieren Sie ein Inhaltspaket mithilfe der Inhaltsmigrations-API

  1. Rufen Sie die Inhaltsmigrations-API mit den gewünschten Optionen auf.

  2. Speichern Sie ein Änderungstoken.

  3. Die Anwendung führt den Export aus, überprüft auf Ausnahmen und meldet ggf. Ausnahmen. Wenn die Ausführung erfolgreich ist, wird das exportierte Paket von der Anwendung mit dem angegebenen Namen erstellt und im angegebenen Speicherort gespeichert.

HinweisHinweis

Nachdem der Export abgeschlossen wurde und Sie ein Inhaltspaket erstellt haben, können Sie das exportierte Paket mithilfe von FTP, tragbaren Medien usw. übertragen. Wenn Sie die Daten an einen Dateispeicherort übertragen haben, auf den der Importvorgang Zugriff hat, können Sie mit dem Importieren beginnen.

So importieren Sie ein Inhaltspaket mithilfe der Inhaltsmigrations-API

  1. Suchen Sie nach der Datei, die Sie während des Exports mithilfe des Objektsmodells erstellt haben. Der Dateiname lautet export.cmp, falls Sie das bereitgestellte Codebeispiel verwenden.

  2. Führen Sie den Importcode aus. Der Importcode bewirkt Folgendes:

    1. Ein SPImportSettings-Objekt mit wie im Code definierten Eigenschaften wird erstellt.

    2. Ein neues SPImport-Objekt wird erstellt, und die Änderungstoken vor dem Import und nach dem Import, die Versionsverwaltung für Inhalte, Cacheeinstellungen und die Zeitplanung für neu bereitgestellte Inhalte werden verwaltet.

    HinweisHinweis

    Aus Leistungsgründen werden von SharePoint Server 2010 standardmäßig keine Ereignisempfänger aufgerufen. Standardmäßig werden Listener nicht ausgelöst, wenn von der Inhaltsbereitstellung Inhalt erstellt wird. Falls Sie allerdings Anwendungen anderer Hersteller oder benutzerdefinierten Code verwenden, für den während des Imports Ereignisempfänger ausgelöst werden müssen, können Sie die SuppressAfterEvents-Eigenschaft auf false festlegen. Die Festlegung dieses Kennzeichens kann eine erhebliche Leistungsbeeinträchtigung bedeuten, aber alle im Import angegebenen Anforderungen werden empfangen.

    HinweisHinweis

    Sie rufen die Inhaltsmigrations-API auf dem Quellserver auf und legen bestimmte Optionen, wie z. B. die RetainObjectIdentity-Eigenschaft, auf true fest.

Beispiel

Zur einfachere Handhabung der Inhaltsmigrations-API von SharePoint Foundation mit dem Inhaltsbereitstellungsfeature von SharePoint Server 2010 enthält dieses Thema ein Codebeispiel, in dem die Inhaltsmigrations-API zusammen mit der Inhaltsbereitstellung von SharePoint Server 2010 verwendet wird. Dieses Beispiel zeigt, wie das Inhaltsbereitstellungsfeature mit der Inhaltsmigrations-API interagiert, um einen Export zu erstellen. Außerdem werden erforderliche Konzepte und Syntax für den Export, Import und Pfad mithilfe der Inhaltsmigrations-API erläutert. Die Schritte für Auftragsdefinition und -ausführung der Inhaltsbereitstellung von SharePoint Server 2010 werden ebenfalls beschrieben.

Der Beispielcode ist in zwei kleinere Anwendungen unterteilt, nämlich eine Exportanwendung und eine Importanwendung.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Deployment;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.Administration;

/* Note: Before running this sample code, or any custom deployment solution, disable auto-spawning for the Variations feature
 * on your source site if it is enabled.
 **/
namespace CustomDeployment
{
    class Program
    {
        private static SavedCacheSettings savedCacheSettings;
        private static string sourceUrl = "http://samplesource/";
        private static string destinationUrl = "http://sampledestination/";
        private static string destinationRootWebUrl;

        static void Main(string[] args)
        {
            // This region defines content deployment export settings,
            // runs the export, and catches an exceptions during export
            // and outputs them.
            #region Export

            try
            {
                SPExportSettings exportSettings = new SPExportSettings();
                // Turn on extra output for testing
                exportSettings.CommandLineVerbose = true; 
                // The name of the file targeted by the export
                exportSettings.BaseFileName = "export.cmp"; 
                // The directory on the file system in which
                // to put the exported package
                exportSettings.FileLocation = @"%temp%"; 
                // If the file exists, overwrite it
                exportSettings.OverwriteExistingDataFile = true;
                // Export all security settings; change this if needed
                exportSettings.IncludeSecurity = SPIncludeSecurity.All;
                // The URL of the site being exported
                exportSettings.SiteUrl = sourceUrl;
                // The last major and minor versions
                exportSettings.IncludeVersions = SPIncludeVersions.LastMajorAndMinor;
                // Compress the exported file
                exportSettings.FileCompression = true; 
                // Create a new export object with the correct settings
                SPExport export = new SPExport(exportSettings); 
                // Optionally add event handlers to the export
                // object for:
                    // Started
                    // ProgressUpdated
                    // Completed
                    // Canceled
                    // Error
                    // Compressing
                // Run the export
                   export.Run(); 
                   }
                // Catch any exceptions during export and output them
                   catch (Exception ex) 
                   {
                   Console.Error.Write(ex.ToString());
                   throw;
                }
            #endregion //Export

            // This region defines import settings, creates a new
            // SPImportObject with those settings, manages versioning
            // and caching, and applies appropriate conditions if the
            // object is a Web site or root Web site
            #region Import
            try
            {
                SPImportSettings importSettings = new SPImportSettings();
                // Turn on extra output for testing
                importSettings.CommandLineVerbose = true; 
                // IMPORTANT: retains object IDs
                importSettings.RetainObjectIdentity = true; 
                // The directory of the file being imported
                importSettings.FileLocation = @"%temp%"; 
                // The name of the file being imported
                importSettings.BaseFileName = "export.cmp";
                // The URL of the site into which content is being imported
                importSettings.SiteUrl = destinationUrl; 
                //Import all the security settings from the package
                importSettings.IncludeSecurity = SPIncludeSecurity.All;
                // Retain author name during import; change if needed
                importSettings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
                // Don't fire event receivers during import; 
                // change if needed
                importSettings.SuppressAfterEvents = true;
                // Add new versions when importing items that 
                // already exist
                importSettings.UpdateVersions = SPUpdateVersions.Append; 
                // Create a new import object with specified settings
                SPImport import = new SPImport(importSettings); 
                // Turn down caching during the import
                  SiteCacheSettingsWriter.UpdateCacheSettingsDuringImport(importSettings.SiteUrl, true); 
                // Save the cache settings to restore after 
                // the import finishes
                savedCacheSettings = SiteCacheSettingsWriter.SaveCacheSettingsBeforeImport(importSettings.SiteUrl);
                // Change tokens for pre-import and post-import
                SPChangeToken startChangeToken, endChangeToken; 
                using (SPSite destinationSite = new SPSite(importSettings.SiteUrl))
                {
                    // Get the change token from the destination site
                    startChangeToken = destinationSite.CurrentChangeToken; 
                    // Save the root Web URL for future use
                    destinationRootWebUrl = destinationSite.RootWeb.ServerRelativeUrl; 
                }

                import.ObjectImported += new EventHandler<SPObjectImportedEventArgs>(import_ObjectImported);
                // Optionally add event handlers to the 
                // import object for:
                    // Started
                    // ProgressUpdated
                    // Completed
                    // Cancelled
                    // Error
                    // Uncompressing

                // Run the import
                import.Run();

                using (SPSite destinationSite = new SPSite(importSettings.SiteUrl))
                {
                    // Get the change token from the
                    // destination site AFTER import
                    endChangeToken = destinationSite.CurrentChangeToken; 

                    // Enable scheduling of the items just deployed
                    ScheduledItem.EnableSchedulingOnDeployedItems(destinationSite, startChangeToken, endChangeToken, "Succeeded");
                }
            }
            // Catch any exceptions during import and output them
            catch (Exception ex) 
            {
                Console.Error.Write(ex.ToString());
                throw;
            }
            finally
            {
                // Update the cache settings because import is done
                SiteCacheSettingsWriter.UpdateCacheSettingsDuringImport(destinationUrl, false);
            }
            #endregion
        }

        private static void import_ObjectImported(object sender, SPObjectImportedEventArgs e)
        {
            // Is the imported object a Web site?
            if ((e != null) && (e.Type == SPDeploymentObjectType.Web))
            {
                // Is the imported object the root Web site?
                if (string.Compare(e.TargetUrl, destinationRootWebUrl, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // The root Web site is being imported, so restore
                    // the cache-related root Web site properties.
                    SiteCacheSettingsWriter.RestoreCacheSettingsOnImport(destinationUrl, savedCacheSettings);
                }
            }

            return;
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SharePoint.Deployment
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Publishing
Imports Microsoft.SharePoint.Publishing.Administration

' Note: Before running this sample code, or any custom deployment solution, disable auto-spawning for the Variations feature
' * on your source site if it is enabled.
' *
Namespace CustomDeployment
    Friend Class Program
        Private Shared savedCacheSettings As SavedCacheSettings
        Private Shared sourceUrl As String = "http://samplesource/"
        Private Shared destinationUrl As String = "http://sampledestination/"
        Private Shared destinationRootWebUrl As String

        Shared Sub Main(ByVal args() As String)
            ' This region defines content deployment export settings,
            ' runs the export, and catches an exceptions during export
            ' and outputs them.
'            #Region "Export"

            Try
                Dim exportSettings As New SPExportSettings()
                ' Turn on extra output for testing
                exportSettings.CommandLineVerbose = True
                ' The name of the file targeted by the export
                exportSettings.BaseFileName = "export.cmp"
                ' The directory on the file system in which
                ' to put the exported package
                exportSettings.FileLocation = "%temp%"
                ' If the file exists, overwrite it
                exportSettings.OverwriteExistingDataFile = True
                ' Export all security settings; change this if needed
                exportSettings.IncludeSecurity = SPIncludeSecurity.All
                ' The URL of the site being exported
                exportSettings.SiteUrl = sourceUrl
                ' The last major and minor versions
                exportSettings.IncludeVersions = SPIncludeVersions.LastMajorAndMinor
                ' Compress the exported file
                exportSettings.FileCompression = True
                ' Create a new export object with the correct settings
                Dim export As New SPExport(exportSettings)
                ' Optionally add event handlers to the export
                ' object for:
                    ' Started
                    ' ProgressUpdated
                    ' Completed
                    ' Canceled
                    ' Error
                    ' Compressing
                ' Run the export
                   export.Run()
                ' Catch any exceptions during export and output them
                   Catch ex As Exception
                   Console.Error.Write(ex.ToString())
                   Throw
                   End Try
'            #End Region 'Export

            ' This region defines import settings, creates a new
            ' SPImportObject with those settings, manages versioning
            ' and caching, and applies appropriate conditions if the
            ' object is a Web site or root Web site
'            #Region "Import"
            Try
                Dim importSettings As New SPImportSettings()
                ' Turn on extra output for testing
                importSettings.CommandLineVerbose = True
                ' IMPORTANT: retains object IDs
                importSettings.RetainObjectIdentity = True
                ' The directory of the file being imported
                importSettings.FileLocation = "%temp%"
                ' The name of the file being imported
                importSettings.BaseFileName = "export.cmp"
                ' The URL of the site into which content is being imported
                importSettings.SiteUrl = destinationUrl
                'Import all the security settings from the package
                importSettings.IncludeSecurity = SPIncludeSecurity.All
                ' Retain author name during import; change if needed
                importSettings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll
                ' Don't fire event receivers during import; 
                ' change if needed
                importSettings.SuppressAfterEvents = True
                ' Add new versions when importing items that 
                ' already exist
                importSettings.UpdateVersions = SPUpdateVersions.Append
                ' Create a new import object with specified settings
                Dim import As New SPImport(importSettings)
                ' Turn down caching during the import
                  SiteCacheSettingsWriter.UpdateCacheSettingsDuringImport(importSettings.SiteUrl, True)
                ' Save the cache settings to restore after 
                ' the import finishes
                savedCacheSettings = SiteCacheSettingsWriter.SaveCacheSettingsBeforeImport(importSettings.SiteUrl)
                ' Change tokens for pre-import and post-import
                Dim startChangeToken, endChangeToken As SPChangeToken
                Using destinationSite As New SPSite(importSettings.SiteUrl)
                    ' Get the change token from the destination site
                    startChangeToken = destinationSite.CurrentChangeToken
                    ' Save the root Web URL for future use
                    destinationRootWebUrl = destinationSite.RootWeb.ServerRelativeUrl
                End Using

                AddHandler import.ObjectImported, AddressOf import_ObjectImported
                ' Optionally add event handlers to the 
                ' import object for:
                    ' Started
                    ' ProgressUpdated
                    ' Completed
                    ' Cancelled
                    ' Error
                    ' Uncompressing

                ' Run the import
                import.Run()

                Using destinationSite As New SPSite(importSettings.SiteUrl)
                    ' Get the change token from the
                    ' destination site AFTER import
                    endChangeToken = destinationSite.CurrentChangeToken

                    ' Enable scheduling of the items just deployed
                    ScheduledItem.EnableSchedulingOnDeployedItems(destinationSite, startChangeToken, endChangeToken, "Succeeded")
                End Using
            ' Catch any exceptions during import and output them
            Catch ex As Exception
                Console.Error.Write(ex.ToString())
                Throw
            Finally
                ' Update the cache settings because import is done
                SiteCacheSettingsWriter.UpdateCacheSettingsDuringImport(destinationUrl, False)
            End Try
'            #End Region
        End Sub

        Private Shared Sub import_ObjectImported(ByVal sender As Object, ByVal e As SPObjectImportedEventArgs)
            ' Is the imported object a Web site?
            If (e IsNot Nothing) AndAlso (e.Type = SPDeploymentObjectType.Web) Then
                ' Is the imported object the root Web site?
                If String.Compare(e.TargetUrl, destinationRootWebUrl, StringComparison.OrdinalIgnoreCase) = 0 Then
                    ' The root Web site is being imported, so restore
                    ' the cache-related root Web site properties.
                    SiteCacheSettingsWriter.RestoreCacheSettingsOnImport(destinationUrl, savedCacheSettings)
                End If
            End If

            Return
        End Sub
    End Class
End Namespace

Siehe auch

Aufgaben

Gewusst wie: Bereitstellen von Inhalt für Server

Referenz

Web

Konzepte

Bereitstellen von Inhalt für Server