コンテンツのインポート/エクスポート
Windows SharePoint Services 3.0 の Microsoft.SharePoint.Deployment API は、Windows SharePoint Services Web サイト間でコンテンツを移行するための柔軟なツール セットです。Windows SharePoint Services ではコンテンツ移行パッケージの概念を採り入れ、1 つまたは複数の XML ファイルを組み込む機能と移行パッケージをエクスポートおよびインポートするための柔軟な API セットが用意されています。展開オブジェクト モデルのコンテンツのインポート/エクスポート機能を使用すれば、Web サイトのコンテンツだけではなく、セキュリティ機能、ユーザー ロール、バージョン管理データ、ワークフロー、その他のメタデータなどの既存の依存関係もエクスポートできます。
Microsoft.SharePoint.Deployment オブジェクト モデルのデータは、Web サイト全体、リストまたはライブラリ内の 1 つのアイテムなど、さまざまな単位で操作できます。移行するコンテンツについて、含めるメタデータのレベルを選択できるのに加え、完全移行を実行するか、または更新の増分のみを移行するかを選択できます。
展開オブジェクト モデルを使用したコンテンツの移行
Microsoft.SharePoint.Deployment オブジェクト モデルのインポート/エクスポート機能には 2 つの主要なオブジェクト (Microsoft.SharePoint.Deployment.SPImport および Microsoft.SharePoint.Deployment.SPExport) がありますが、これらのオブジェクトを使用してインポートまたはエクスポートの操作を実行する前に、Microsoft.SharePoint.Deployment.SPImportSettings オブジェクトおよび Microsoft.SharePoint.Deployment.SPExportSettings オブジェクトでインポートまたはエクスポートの設定を指定する必要があります。設定が完了したら、SPImport オブジェクトまたは SPExport オブジェクトの Run() メソッドを呼び出すだけで操作は完了します。
例
次のコードは、展開オブジェクト モデルで移行元から SharePoint サイトをエクスポートし、移行先にインポートする方法を示しています。
private void ExportImport(string sourceUrl, string destinationUrl)
{
string fileName = Export(sourceUrl);
Log.Comment("Local filename for this export/import is {0}", fileName);
Import(destinationUrl, fileName);
}
private string Export(string siteURL)
{
Microsoft.SharePoint.Deployment.SPExportSettings exportSettings =
new Microsoft.SharePoint.Deployment.SPExportSettings();
exportSettings.AutoGenerateDataFileName = true;
exportSettings.ExportMethod =
Microsoft.SharePoint.Deployment.SPExportMethodType.ExportAll;
exportSettings.SiteUrl = siteURL;
exportSettings.IncludeSecurity =
Microsoft.SharePoint.Deployment.SPIncludeSecurity.All;
exportSettings.IncludeVersions =
Microsoft.SharePoint.Deployment.SPIncludeVersions.All;
Microsoft.SharePoint.Deployment.SPExport export =
new Microsoft.SharePoint.Deployment.SPExport(exportSettings);
Log.Comment("Starting export of URL {0}", siteURL);
export.Run();
return exportSettings.FileLocation + "\\" + exportSettings.BaseFileName;
}
private void Import(string siteURL, string fileToImport)
{
Microsoft.SharePoint.Deployment.SPImportSettings importSettings =
new Microsoft.SharePoint.Deployment.SPImportSettings();
importSettings.BaseFileName = System.IO.Path.GetFileName(fileToImport);
importSettings.FileLocation = System.IO.Path.GetDirectoryName(fileToImport);
importSettings.SiteUrl = siteURL;
importSettings.RetainObjectIdentity = false;
importSettings.IncludeSecurity =
Microsoft.SharePoint.Deployment.SPIncludeSecurity.All;
importSettings.UpdateVersions =
Microsoft.SharePoint.Deployment.SPUpdateVersions.Append;
importSettings.UserInfoDateTime =
Microsoft.SharePoint.Deployment.SPImportUserInfoDateTimeOption. ImportAll;
Microsoft.SharePoint.Deployment.SPImport import =
new Microsoft.SharePoint.Deployment.SPImport(importSettings);
Log.Comment("Starting import to URL {0}", siteURL);
import.Run();
}
STSADM コマンドライン ツールを使用したコンテンツの移行
STSADM.exe コマンドライン ツールは基本的なインポートおよびエクスポート操作のみをサポートし、SharePoint Web サイト全体をインポートまたはエクスポートする場合、または Web サイトの親子関係を変更する場合にのみ役立ちます。このツールでコンテンツを移行した場合、オブジェクト GUID は保持されません。このユーティリティでは、アイテムやリストを個別にインポートまたはエクスポートすることはできません。
例
次の例は、STSADM.exe コマンドライン ツールで Web サイトのコンテンツをエクスポートする方法を示しています。
stsadm.exe -o export
-url <URL to be exported>
-filename <export file name>
[-overwrite]
[-includeusersecurity]
[-haltonwarning]
[-haltonfatalerror]
[-nologfile]
[-versions <1-4>
1 - Last major version for files and list items (default)
2 - The current version, either the last major or the last minor
3 - Last major and last minor version for files and list items
4 - All versions for files and list items]
[-cabsize <integer from 1-1024 megabytes>]
[-quiet]
注意
タイム スタンプ、セキュリティ情報、ユーザー データを保存するには、-includeusersecurity パラメータを使用する必要があります。
例
次の例は、STSADM.exe コマンドライン ツールで Web サイトのコンテンツをインポートする方法を示しています。
stsadm.exe -o import
-url <URL to import to>
-filename <import file name>
[-includeusersecurity]
[-haltonwarning]
[-haltonfatalerror]
[-nologfile]
[-updateversions <1-4>
1 - Add new versions to the current file (default)
2 - Overwrite the file and all its versions (delete then insert)
3 - Ignore the file
4 - Terminate with conflicts]
[-quiet]
例
次のコードは、一般的な設定でコンテンツをインポートおよびエクスポートする処理を行うサンプル バッチ ファイルです。このコードを .bat ファイルにコピーして貼り付けることができます。
@echo off
if not "%1"=="" goto ExportImport
echo **** Usage
echo This batch file will automatically export the default site collection to a newly created site collection
echo You need to specify the name of the newly created site collection as an argument
echo Example: PrimeIt.bat NewSite
echo The example will create https://localhost/sites/NewSite, and export https://localhost into it, preserving user security.
goto end
:ExportImport
echo ************* Determine the Location to stsadm.exe
if EXIST "%CommonProgramFiles%\Microsoft Shared Debug\Web Server Extensions\12\bin\stsadm.exe" set BinDir=%CommonProgramFiles%\Microsoft Shared Debug\Web Server Extensions\12\bin
if EXIST "%CommonProgramFiles%\Microsoft Shared\Web Server Extensions\12\bin\stsadm.exe" set BinDir=%CommonProgramFiles%\Microsoft Shared\Web Server Extensions\12\bin
echo Determined that the location to stsadm is %BinDir%
@echo on
@echo ************* Backup the root site collection
"%BinDir%\stsadm.exe" -o export -url https://localhost -filename %TEMP%\Export.cab -includeusersecurity -versions 4 -overwrite
@echo ************* Create a destination site
"%BinDir%\stsadm.exe" -o createsite -url https://localhost/sites/%1 -ownerlogin %UserDomain%\%UserName% -owneremail %UserName%@microsoft.com -sitetemplate STS
@echo ************* Import into the new site
"%BinDir%\stsadm.exe" -o import -url https://localhost/sites/%1 -filename %TEMP%\Export.cab -includeusersecurity
@echo off
:end
See Also
参照
Microsoft.SharePoint.Deployment