none
Perform multiple site collections backup/restore in 1-execution file in PowerShell like DOS batch file

    Question

  • How to perform multiple site collections backup/restore in 1-execution file similar to DOS batch file?  I'm having issues in perfroming multiple site collections backup and restore. I'm migrating SharePoint 2010 demo site to current production SharePoint 2010. It only allows me to do one site collection at a time. I have 104 site collections. With STSAdmin in the past, I was able to create a batch file to execute the line by line iteration in a single .bat file. I tried painfully writing "for loop statement but no joy. Please HELP.
    Elsa Yee
    Friday, July 29, 2011 12:25 PM

Answers

  • try below scripts

     

    # Backup all site collections in your farm
    Get-SPSite -Limit All | ForEach-Object {Backup-SPSiteCollections -SPSiteID $_.ID -BackupFolder "C:\Backups\" -SiteName $_.Url -BackupFilesLimit 5 -Email "your-email@contoso.com" -SmtpServer "smtp.contoso.com"}
    #
    #Backup a site collection whose URL equals http://intranet.contoso.com
    Get-SPSite | Where {$_.Url -eq "http://intranet.contoso.com"} | ForEach-Object {Backup-SPSiteCollections -SPSiteID $_.ID -BackupFolder "C:\Backups\" -SiteName $_.Url -BackupFilesLimit 5 -Email "your-email@contoso.com" -SmtpServer "smtp.contoso.com"}
    #
    #Backup all site collections whose URL is not equal to http://no-backup.contoso.com, no emails will be sent
    Get-SPSite | where {$_.Url -ne "http://no-backup.contoso.com"} | ForEach-Object {Backup-SPSiteCollections -SPSiteID $_.ID -BackupFolder "C:\Backups\" -SiteName $_.Url -BackupFilesLimit 5}


     

     

    refer url http://www.sharepointusecases.com/index.php/2011/07/backup-sharepoint-2010-site-collections-with-powershell/


    Rahul Sharma -------------------------- Coding is all about passion !!!!!!

    • Proposed as answer by Shimin Huang Monday, August 01, 2011 6:52 AM
    • Marked as answer by Shimin Huang Friday, August 05, 2011 9:36 AM
    Friday, July 29, 2011 7:33 PM

All replies

  • try below scripts

     

    # Backup all site collections in your farm
    Get-SPSite -Limit All | ForEach-Object {Backup-SPSiteCollections -SPSiteID $_.ID -BackupFolder "C:\Backups\" -SiteName $_.Url -BackupFilesLimit 5 -Email "your-email@contoso.com" -SmtpServer "smtp.contoso.com"}
    #
    #Backup a site collection whose URL equals http://intranet.contoso.com
    Get-SPSite | Where {$_.Url -eq "http://intranet.contoso.com"} | ForEach-Object {Backup-SPSiteCollections -SPSiteID $_.ID -BackupFolder "C:\Backups\" -SiteName $_.Url -BackupFilesLimit 5 -Email "your-email@contoso.com" -SmtpServer "smtp.contoso.com"}
    #
    #Backup all site collections whose URL is not equal to http://no-backup.contoso.com, no emails will be sent
    Get-SPSite | where {$_.Url -ne "http://no-backup.contoso.com"} | ForEach-Object {Backup-SPSiteCollections -SPSiteID $_.ID -BackupFolder "C:\Backups\" -SiteName $_.Url -BackupFilesLimit 5}


     

     

    refer url http://www.sharepointusecases.com/index.php/2011/07/backup-sharepoint-2010-site-collections-with-powershell/


    Rahul Sharma -------------------------- Coding is all about passion !!!!!!

    • Proposed as answer by Shimin Huang Monday, August 01, 2011 6:52 AM
    • Marked as answer by Shimin Huang Friday, August 05, 2011 9:36 AM
    Friday, July 29, 2011 7:33 PM
  • This is very helpful!
    Elsa Yee
    Tuesday, August 02, 2011 5:38 PM