Sharepoint Export Import Details


Sharepoint Export Import Details


Export: For Exporting Sharepoint data from one farm to another, Sharepoint provides a class SPExportSettings which contains various settings to export data from source server in the form of .cab files. Some of the important settings are described below .

1. AutoGenerateDataFileName : Gets and sets the value that indicates whether a file name for the content migration package should be automatically generated.

2. ExportChangeToken : Gets or sets the change token to use when exporting incremental changes based on changes since the last export.

a.  Understanding Change Tokens
Share point creates change log if we have made any changes in SPObject and is stored in the EventCache table of the content database. This table stores the information about all content changes in the content database. Each entry in the Change log contains the following information:

  •  A sequential number (Id) identifying the row in the event cache table

  •  The timestamp (EventTime) when the change has happened

  • The type of the object (ObjectType) that has changed

  • Identification (one or multiple IDs) of the object that was changed

  • URL to the object that was changed (if the object has a URL)

  • The type of modification (EventType)


b.  About the Change Token

Each time the change log is queried for changes, it returns the changes together with a Change Token which corresponds to a database entry up to which the querying application has been synchronized. This change token is of the format Int1; Int2; Guid; Time; Int3.

Example: 1;1;df6828cf-c303-453e-9eb6-e733f85611ac;633782543234470000;1510 Where,

  •  Int1: Contains version information for the change token. Currently this value is always 1.

  •  Int2: The scope the change token has been requested for. For example, if you ask for changes in the site collection this value will have the scope "Site". If you request changes for a sub site, it will       contain the scope "Web". See the following table for possible values. Related to content deployment and the underlying API, this value is always 1 as content deployment always generates a change token with a scope of the whole site collection.

  •  Guid: Guid of the object the change token belongs to. If the change token was requested for a site collection this will be the Id of the SPSite object.

  •  Time: Timestamp (in ticks) of the change the token belongs to.

  •   Int3: change number in the event cache table the change belongs to.


c.  Code To Get change Token

[java]
using (SPSite siteCollection = new SPSite("http://localhost"))
{
using (SPWeb webSite = siteCollection.RootWeb)
{

// Create a change token.
DateTime startTime = DateTime.UtcNow.AddDays(-60);//default 60 days
SPChangeToken startToken = new SPChangeToken(SPChangeCollection.CollectionScope.Web, webSite.ID, startTime);//Create token by itself by passing web Id

// Retrieve the first batch of changes.
SPChangeCollection changes = webSite.GetChanges(startToken);

// Get another batch.
startToken = changes.LastChangeToken;
changes = webSite.GetChanges(startToken);

}
}

[/java]

3. ExportMethod : This property has two possible values

a. Full Export : After setting this flag to ExportMethod property Sharepoint Exports all the objects from source site collection.
b.Incremental Export : After settings this flag to ExportMethod property Sharepoint export only change objects    calculated from ExportChangeToken.

4. IncludeSecurity : Determines whether site security groups and the group membership information is exported or imported, this property has three possible values

a.  All : To migrate user and group information to include during an export or import operation.
b. None : No User Information migrated.
c. Wss Only : Only role assignments such as out of the box roles like Web Designer, or any custom roles that extend from the out of the box role.

5.  IncludeVersions : Determines what content is selected for export based on version information,

a. All
b. Current Version
c. Last Major
d. Last Major And minor

6. SiteUrl : absolute URL of a source or destination Web site.

7.  ExcludeDependencies : whether to exclude dependencies from the export package when exporting objects of type SPFile or SPListItem.

Sample Code  :


[java]

private void Export(string siteURL)
{
Microsoft.SharePoint.Deployment.SPExportSettings exportSettings = new Microsoft.SharePoint.Deployment.SPExportSettings();
exportSettings.AutoGenerateDataFileName = true;
exportSettings.ExportMethod = Microsoft.SharePoint.Deployment.SPExportMethodType.ExportChanges;
exportSettings.SiteUrl = siteURL;
exportSettings.IncludeSecurity = Microsoft.SharePoint.Deployment.SPIncludeSecurity.All;
exportSettings.IncludeVersions = Microsoft.SharePoint.Deployment.SPIncludeVersions.LastMajorAndMinor;
using (SPSite siteCollection = new SPSite(siteURL))
{
using (SPWeb webSite = siteCollection.RootWeb)
{
SPChangeToken startToken = new SPChangeToken(SPChangeCollection.CollectionScope.Web, webSite.ID, startTime);

// Retrieve the first batch of changes.
SPChangeCollection changes = webSite.GetChanges(startToken);
exportSettings.ExportChangeToken = changes.LastChangeToken.ToString();
}
}

Microsoft.SharePoint.Deployment.SPExport export = new Microsoft.SharePoint.Deployment.SPExport(exportSettings);
export.Run();

}

[/java]
Share on Google Plus

About JK STACK

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

6 comments: