Thursday, April 15, 2010

Daily and Weekly SharePoint 2010 Site Collection backup using Powershell

Backup instructions for Site Collection, read TechNet http://technet.microsoft.com/en-us/library/ee748617(office.14).aspx
I want to backup the site collection daily and keep a backup of every week of the year. I created a Powershell script and scheduled the script.

The Powershell script does the following:

  • checks if SharePoint Powershell Snapin is loaded;
  • checks if backup location exists;
  • backups the site collection;
  • copies the daily backup to the weekly if necassary;

The ‘Backup Site Collection.ps1’ code:

"-------------------------------------"
"Yellow & Red SharePoint Backup script"
"-------------------------------------"
"- One daily backup"
"- And weekly backup"
#Backup location
$backupLocation = "\\XXX\d$\_backups\XXX\"
#Site collection location
$sitecollection = "http://XXX"
#daily filename
$dailybackupfile = Join-Path -Path $backupLocation -ChildPath "backup_yarintranet_daily.bak"
#weekly filename (using uformat as format doesn't have week option)
$weeklybackupfile = Join-Path -Path $backupLocation -ChildPath ("backup_yarintranet_" + (Get-Date -UFormat %Y%W) + ".bak")
# check to ensure Microsoft.SharePoint.PowerShell is loaded
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
    Write-Host "Loading SharePoint Powershell Snapin"
    Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
if(!(test-path $backupLocation -PathType Container))
{
    "Backup location (" + $backupLocation + ") not found."
    break
}
"Starting backup process"
Backup-SPSite -Identity $sitecollection -Path $dailybackupfile -Force
"Finshed backup process"
"Copy daily backup to weekly if necessary"
if((test-path $weeklybackupfile -PathType Leaf))
{
    "Weekly backup file found, so no backup will be made"
    break
}
copy $dailybackupfile $weeklybackupfile -Force
"Finished"

 

Schedule the a task using the Windows 2008 scheduler.

image

Make sure that:

  • you set the correct Identity that has access to the backup location;
  • task runs even when user is not logged in;
  • Set interval of script execution in ‘Trigger’ tab;

image 

In ‘Action’ Tab set the execution of the Powershell script:

  • Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • Arguments: -file "<full path location to your Site Collection backup Powershell script>" (exclude the <, include the ")

And as always, make sure you test your backup. Otherwise you’ll have a very bad day when disaster strikes.

Wednesday, April 14, 2010

SharePoint 2010 - PDF iFilter comparison

Very interesting results in the PDF iFilter products for SharePoint 2010 (beta). Check out this article. Foxit wins big time.

Thursday, April 8, 2010

Schema.xml, onet.xml and baseview doesn’t pick up scope attribute

Again some strange things with SharePoint 2010 (maybe also with MOSS 2007) when using custom list template and a list view web part. It turns out that not all settings from the schema.xml are used in the web part view.

So I created a list template based on document library, added a custom view like this:

<View BaseViewID="41" Type="HTML" WebPartZoneID="Main" DisplayName="LatestChanges" Scope="Recursive" DefaultView="FALSE" TabularView="FALSE" MobileView="FALSE" MobileDefaultView="FALSE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/dlicon.png" Url="Forms/LastChanges.aspx">
        <XslLink Default="TRUE">main.xsl</XslLink>
        <RowLimit Paged="TRUE">10</RowLimit>
        <Toolbar Type="Standard">
        </Toolbar>
        <ViewFields>
          <FieldRef Name="DocIcon" />
          <FieldRef Name="LinkFilename" />
          <FieldRef Name="Modified" />
          <FieldRef Name="Editor" />
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="Modified" Ascending="FALSE" />
          </OrderBy>
        </Query>
        <ParameterBindings>
          <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noitemsinview_doclibrary)" />
          <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noitemsinview_doclibrary_howto2)" />
        </ParameterBindings>
      </View>

The view should display the last 10 modified documents, without showing folders. So I changed the Rowlimit, the Orderby and set Scope attribute to Recursive.

To provision a site with a page, with (my custom) document list I added this line to the onet.xml:

<List FeatureId="f8525c7b-c680-4431-94aa-4bb6e55827b5" Type="10000" Title="$Resources:core,shareddocuments_Title;" Url="$Resources:core,shareddocuments_Folder;" QuickLaunchUrl="$Resources:core,shareddocuments_Folder;/Forms/AllItems.aspx"/>

Make sure the web part is set to the correct view added this line to the onet.xml:

<View List="$Resources:core,shareddocuments_Folder;" BaseViewID="41" WebPartZoneID="TopRow" WebPartOrder="2" />

After depoying, and testing the provisioned page with the web part view is created and it looks like all settings of the BaseViewID, in this case 41, are copied to the view settings of the web part. However it does not copy all settings, the Scope="Recursive" is not copied. It turns out that the Scope="Recursive" should be set on the <View> element in the onet.xml itself. So the onet.xml should have a line like this:

<View List="$Resources:core,shareddocuments_Folder;" BaseViewID="41" Scope="Recursive" WebPartZoneID="TopRow" WebPartOrder="2" />

Now the scope is set correctly and the folders are not shown in the web part.

BTW: I don’t know if this is a bug. However when you change the web part view by hand and select the view ‘LatestChanges’, than it does copy the Scope attribute.

“Open the tool pane” javascript error in SharePoint 2010

I was running into trouble when using the out-of-the-box RSS Feed Web Part of SharePoint 2010 on a publishing page. Especially when the Web Part wasn’t configured with a RSS feed, because it shows the following message:
image

If you want to configure the RSS Web Part, you click “Open the tool pane” link. However it displays the following javascript errors:
image

 image

Not much help in this error. A work-around would be to set the publishing page in Edit mode, and than click the “Open the tool pane” link. Not very user friendly.

The “open the tool pane” link calls a function MSOTlPn_ShowToolPane2. Strange thing is that when the Publishing Page is in Edit mode and clicking the “open the tool pane” link doesn’t raise the error. After some research I found out that the “Edit mode” includes a javascript file named “ie55up.js”.

I included the ie55up.js in the Master Page using the <SharePoint:ScriptLink> and it solved the problem.

<SharePoint:ScriptLink language="javascript" name="ie55up.js" OnDemand="false" runat="server" />

Make sure you set OnDemand="false", otherwise the javascript file will not be loaded.