Home > moss > Sauvegarder un ensemble de site collection WSS

Sauvegarder un ensemble de site collection WSS

November 11th, 2009 nb888 Leave a comment Go to comments

J’ai développé un petit script PowerShell qui permet de sauvegarder toutes les sites collections WSS d’une ferme hors site collection d’administration.

Il ne prend pas de paramètre car il sauvegarde la ferme local.

[system.reflection.assembly]::LoadWithPartialName(“Microsoft.Sharepoint”)

#Pour resoudre Prb output
$bindingFlags = [Reflection.BindingFlags] “Instance,NonPublic,GetField”
$objectRef = $host.GetType().GetField(“externalHostRef”, $bindingFlags).GetValue($host)

$bindingFlags = [Reflection.BindingFlags] “Instance,NonPublic,GetProperty”
$consoleHost = $objectRef.GetType().GetProperty(“Value”, $bindingFlags).GetValue($objectRef, @())

[void] $consoleHost.GetType().GetProperty(“IsStandardOutputRedirected”, $bindingFlags).GetValue($consoleHost, @())
$bindingFlags = [Reflection.BindingFlags] “Instance,NonPublic,GetField”
$field = $consoleHost.GetType().GetField(“standardOutputWriter”, $bindingFlags)
$field.SetValue($consoleHost, [Console]::Out)
$field2 = $consoleHost.GetType().GetField(“standardErrorWriter”, $bindingFlags)
$field2.SetValue($consoleHost, [Console]::Out)

$backupDir = ‘E:\backup\’;
$webServices = new-object Microsoft.SharePoint.Administration.SPWebServiceCollection([microsoft.sharepoint.administration.spfarm]::local)
ForEach ($webService in $webServices)
{
#Write-Output $webService;
ForEach($webApp in $webService.WebApplications)
{
Write-Output ‘——————————-’;
Write-Output $webApp.Name $webApp.DefaultServerComment ;
If(!$webApp.IsAdministrationWebApplication)
{
ForEach($site in $webApp.Sites)
{
Write-Output ‘~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~’;
$msg = ([DateTime]::Now).toString() + ‘- Sauvegarde de ‘ + $site.url;
Write-Output $msg ;

$msg = ([DateTime]::Now).toString()+ ‘ – Lock de la collection’;
Write-Output $msg ;
stsadm -o setsitelock -url $site.url -lock readonly;

$backupFile = $backupDir + $site.hostname + ‘-’ + $site.ID +’.bak’;
$msg = ([DateTime]::Now).toString() + ‘ – Sauvegarde de la collection sous ‘+ $backupFile;
Write-Output $msg ;
stsadm -o backup -url $site.url -overwrite -filename $backupFile;

$msg = ([DateTime]::Now).toString() + ‘ – UnLock de la collection’;
Write-Output $msg ;
stsadm -o setsitelock -url $site.url -lock none;

$msg= ([DateTime]::Now).toString() + ‘ – Fin Sauvegarde de ‘ + $site.url;
Write-Output $msg ;
}
}
else
{
Write-Output ‘Administration WebApp – Skipping’;
}
}
}

  • LinkedIn
  • Twitter
  • Delicious
  • Facebook
  • Share/Bookmark
Categories: moss Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.