Friday 30 March 2012

SharePoint 2010: Backup/Restore with PowerShell Command

If you want to backup/restore your site collection in SharePoint 2010, you can do with PowerShell command. I’ll spilt the post in two sections. One is on how to backup/restore in the same site collection and another is how to backup from one server/site collection to another. For the former (backup/restore in the same site collection), SharePoint provides nice easy GUI page in Central Administration page. However, for second one (backup/restore between different server) you need to run PowerShell scripts.

Backup/Restore in the same server and same site  collection


Sometimes you may want to backup from a site collection and your intention is to restore the backup in the same site collection. One example might be you have a site collection, say “http://myserver” and you are going to run code to test something against the site. However, you fear that running the code may break something and before you run the code, you want to backup the site so that in case running the code breaks something you can restore the backup taken before running the code. In the case, where you need to backup/restore is centered around same server and site collection, you can take SharePoint Central administration UI to do the backup/restore.
Backup Steps

1. Navigate to the Central Administration => Backup and Restore

2. Under “Farm Backup and Restore” section click “Perform a backup”.

3. Now you’ll be landed in the following page where you can select the site or site collection you want to take backup:

image

4. Click next and you’ll be navigated to the following page where you can select backup type (full or differential) and backup location:

image

 
Restoring Steps

To restore follow the steps:

1. Navigate to the Central Administration => Backup and Restore.

2. Under “Farm Backup and Restore” section click “Restore from a backup”. Follow the wizard to restore from a backup.

 

Backup/Restore from one server to another or from one Site Collection to another (with PowerShell command)


In some cases, you have developed a SharePoint site collection in your dev or stg machine and now you want to move the site with data from dev/stg to production. In such cases the process shown in the section “Backup/Restore in the same server and same site  collection” will not work. The recommended way is to use PowerShell command to take backup and restore the backup.
Backup a Site collection with PowerShell command

In SharePoint 2010, PowerShell command Backup-SPSite is used for taking backup. you can get details of the command from the msdn link. The following command will backup the site collection ‘http://myserver’.

Backup-SPSite -Identity http://myserver -Path "c:\backup\file.bak"
Restore a Site Collection with PowerShell command

To restore site collection you’ll use the following command. Use –Force if you want to overwrite the existing site collection

Restore-SPSite -Identity http://myserver -Path "c:\backup\file.bak"

However, once I had restored the backup I could not access the site. The problem was that I needed to deploy the custom SharePoint solution. So in case of site collection migration (with backup/restore) from one server to another or from one site collection to another, the steps should be:

  1. Restore the backup.

  2. If your source site collection (from where you taken backup) uses custom SharePoint solution, then deploy the solution in the destination site collection (where you are restoring the backup). If you try to access the site without deploying solution then you may get the site non-functional.

  3. Now you can try to access the site.


The important point here is that if you take backup from one server to another and restore it, the custom solution related to backup doesn’t go with backup. So after restoring backup you need to manually deploy the solution on the destination server. Then it’ll hopefully work.

Add existing Content database to a Site collection using STSADM

Stsadm Addcontentdb

 

Scenario
- You have an old content database (mdf/ldf or a backup) that you want to use as a content database for a new site collection.
or
- You want to create a new site collection, and to use an already existing content database (that holds your old data) for this site collection.

Assumption
- At the back-end SQL server you have a content database (in this example i will name it WSS_Content_Web1) attached to the SQL server, that is not linked to any site collection yet.
or
-At the back-end SQL server you’ve created a new database (in this example i will name it WSS_Content_Web1) using SQL management studio and restored a backed-up content database to it, to be used as a content database for you new site collection.

Steps
I will refer to this content database as WSS_Content_Web1, and the site collection as http://www.xyz.com/Web1

 

What we are up to do is:

  1. Create a content database using Sharepoint central administration.

  2. Create site collection that will use this content db.

  3. delete this content db.

  4. use STSADM to link this newly created site collection to the existing content database (in this example i will name it WSS_Content_Web1) in the back-end SQL.


 

So let us start:

  1. Launch “SharePoint 3.0 Centeral Administration”, and under the category “SharePoint Web Application Management” Select “Web application list” then select the web application that will contain the site collection.

  2. Select content databases, and click to add a new content database, name it WSS_Content_test and click ok.

  3. Create a new site collection, name it Web1. (notice that the new site collection will be attached to the newly created content database (WSS_content_test).

  4. Go back to the link “content databases” and delete the content database you’ve created “WSS_Content_test”.

  5. Launch Command prompt (CMD) … Start > Run > cmd and hit enter.

  6. write the following command line:
    Stsadm –o addcontentdb –url http://www.xyz.com/Web1 –databasename WSS_Content_Web1

  7. press enter to execute the command.


Go and browse to your newly created site collection, and enjoy.

 

notes:

  1. The STSADM tool is usually located in the following path (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN).

  2. For details about using the command addcontentdb visit this article in TechNet Addcontentdb: Stsadm operation (Office SharePoint Server).

DisableLoopbackCheck on Windows Server 2008

Recently I was troubleshooting a SharePoint farm of a customer. The crawl of the content sources did not work and always ended with a “access denied” error in the crawl log. In the eventlog event ID 2436 appeared: “Access is denied. Check that the Default Content Access Account has access to this content, or add a crawl rule to crawl this content.”
To solve this you have to make a DisableLoopbackCheck registry key. Follow these steps to do so:

  • Click Start, click Run, type regedit, and then click OK.

  • In Registry Editor, locate and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa

  • Right-click Lsa, point to New, and then click DWORD Value.

  • Type DisableLoopbackCheck, and then press ENTER.

  • Right-click DisableLoopbackCheck, and then click Modify.

  • In the Value data box, type 1, and then click OK.

  • Quit Registry Editor, and then restart your computer.


 

Monday 5 March 2012

Play a Playlist using YouTube JavaScript API

If you have been enjoying our <iframe> embed announced back in July we have some good news for you. Starting today, the <iframe> embed code is the default way to share videos on YouTube.com. We are also introducing an initial beta version of the <iframe> embed JavaScript Player API, making it a viable alternative for developers who previously used the API exposed by the ActionScript players. Let’s look at an example of the API usage:

<!DOCTYPE HTML>
<html>
<body>
<div id="player"></div>
<script>
//Load player api asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var done = false;
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'JW5meKfy3fY',
playerVars: { 'autoplay': 0, 'controls': 1, 'playlist':['your_video_id', '...']},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(evt) {
evt.target.playVideo();
}
function onPlayerStateChange(evt) {
if (evt.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>

This example will play a video for several seconds and then stop playback. An instance of YT.Player is used to control the player, defined by script loaded from http://www.youtube.com/player_api .  For more information about the API usage, as always, please consult our Player API documentation and let us know what you think on our Developer Forum.

Pulling in YouTube Videos from Specific Channel

class ChannelFeed {

function __construct($username){
$this->username=$username;
echo $this->username;
$this->feedUrl=$url='http://gdata.youtube.com/feeds/api/users/'.$username.'/uploads?orderby=updated';
$this->feed=simplexml_load_file($url);
}

public function getYTid() {

$ytURL = $this->feed->entry->link['href'];

$ytvIDlen = 11; // This is the length of YouTube's video IDs

// The ID string starts after "v=", which is usually right after
// "youtube.com/watch?" in the URL
$idStarts = strpos($ytURL, "?v=");

// In case the "v=" is NOT right after the "?" (not likely, but I like to keep my
// bases covered), it will be after an "&":
if($idStarts === FALSE)
$idStarts = strpos($ytURL, "&v=");
// If still FALSE, URL doesn't have a vid ID
if($idStarts === FALSE)
die("YouTube video ID not found. Please double-check your URL.");

// Offset the start location to match the beginning of the ID string
$idStarts +=3;

// Get the ID string and return it
$ytvID = substr($ytURL, $idStarts, $ytvIDlen);
return $ytvID;
}

public function showFullFeed(){
$vidarray = array();
foreach($this->feed->entry as $video){
$vidarray[] = $video->link['href'];
}
return $vidarray ;
}


};
$youtube = new ChannelFeed('channel_name');
$vids = $youtube->showFullFeed();
$vidIDs = array_map(array(&$youtube, "getYTid"), $vids);

Thursday 1 March 2012

sharepoint _layouts/ManageFeatures runtime error

sharepont publishing feature

portal/_layouts/ManageFeatures.aspx

Runtime Error

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.

It gives this error massage

 

Solution:
 <asp:panel runat="server" visible="false"> 
<asp:ContentPlaceHolder id="PlaceHolderSiteName" runat="server"/>
</asp:panel>

Add the above in your master page.

Also Change the Custom Errors in the layouts web.config to "Off". You will then see errors.

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\web.config