locked
Anleitung – Wie kann man alle Websitesammlungen durch Power Shell im SharePoint 2010 sicherstellen RRS feed

  • Allgemeine Diskussion

  • Hallo Liebe Community,

    Gestern hat Patrick Lamber ein tolles Skript veröffentlicht das die Funktionalität bietet alle Websitesammlungen durch Power Shell sicherzustellen. Man kann das Skript im Produktion als auch im Testing Umgebungen benutzen, dort wo andere Sicherstellung Lösungen nicht verfügbar sind.

    Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue 
    
    # specify here your backup folder
    $backupRoot = "C:\Scripting\Backup\"
    $logPath = Join-Path $backupRoot "_logs"
    $tmpPath = Join-Path $backupRoot "_tmp"
    # removes all the old backup files on the target folder (valid values: 0 = do not remove; 1 = remove files
    $clearUpOldFiles = 0 
    # specifies the days for the backups that should be persisted
    $removeFilesOlderThanDays = -1
    # specifies the backupfolder based on the current weekday (Monday... etc.)
    $todaysBackupFolder = Join-Path $backupRoot ((Get-Date).DayOfWeek.toString()) 
    
    # generate all necessary folders if they are missing
    if (-not (Test-Path $logPath)) {  
      New-Item $logPath -type directory
    } 
    
    if (-not (Test-Path $tmpPath)) {  
      New-Item $tmpPath -type directory
    } 
    
    if (-not (Test-Path $todaysBackupFolder)) {  
      New-Item $todaysBackupFolder -type directory
    } 
    
    # creates a log file 
    Start-Transcript -Path (Join-Path $logPath ((Get-Date).ToString('yyyyMdd_hhmmss') + ".log")) 
    
    # loop over all web applications (specify filter criteria here if you want to filter them out)
    foreach ($webApplication in Get-SPWebApplication) {    
      Write-Host    
      Write-Host    
      Write-Host "Processing $webApplication"   
      Write-Host "*******************************"         
    
      foreach ($site in $webApplication.Sites) {                
        # we have to replace some characters from the url name        
        $name = $site.Url.Replace("http://", "").Replace("https://", "").Replace("/", "_").Replace(".", "_");        
        # replace all special characters from url with underscores        
        [System.Text.RegularExpressions.Regex]::Replace($name,"[^1-9a-zA-Z_]","_");                 
        # define the backup name        
        $backupPath = Join-Path $tmpPath ($name + (Get-Date).ToString('yyyyMdd_hhmmss') + ".bak")                 
    
        Write-Host "Backing up $site to $backupPath"        
        Write-Host                 
        
        # backup the site        
        Backup-SPSite -Identity $site.Url -Path $backupPath    
      }         
    
      Write-Host "*******************************"    
      Write-Host "*******************************"
    } 
    
    Write-Host
    Write-Host 
    
    # remove the old backup files in the todays folder if specified
    if ($clearUpOldFiles -eq 1) {  
      Write-Host "Cleaning up the folder $todaysBackupFolder"  
      Remove-Item ($todaysBackupFolder + "\*") 
    } 
    
    # move all backup files from the tmp folder to the target folder
    Write-Host "Moving backups from $tmpPath to $todaysBackupFolder"
    Move-Item -Path ($tmpPath + "\*") -Destination $todaysBackupFolder
    # you can specify an additial parameter that removes filders older than the days you specified
    if ($removeFilesOlderThanDays -gt 0) {  
      Write-Host "Checking removal policy on $todaysBackupFolder"  
      $toRemove = (Get-Date).AddDays(-$removeFilesOlderThanDays)  
      $filesToRemove = Get-ChildItem $todaysBackupFolder | Where {$_.LastWriteTime -le “$toRemove”}     
    
      foreach ($fileToRemove in $filesToRemove)  {    
        Write-Host "Removing the file $fileToRemove because it is older than $removeFilesOlderThanDays days"     
        Remove-Item (Join-Path $todaysBackupFolder $fileToRemove) | out-null  
      }
    }
     
    Stop-Transcript

    Mehr über das Skript und den Autor kann man HIER finden

    Gruss,

    Alex



    Alex Pitulice, MICROSOFT 
    Bitte haben Sie Verständnis dafür, dass im Rahmen dieses Forums, welches auf dem Community-Prinzip„IT-Pros helfen IT-Pros“ beruht, kein technischer Support geleistet werden kann oder sonst welche garantierten Maßnahmen seitens Microsoft zugesichert werden können.



    Donnerstag, 12. April 2012 12:52