Backup and Restore a Site Collection using PowerShell
In a previous blog post, I was using the Copy-SPSite cmdlet to duplicate a Site Collection to another content database, within the same Web Application.
Today’s post will be about backing up a Site Collection & restoring it into another Web Application by using PowerShell.
Minimum requirements:
- Permissions to run PowerShell cmdlets
- Web Applications (source & target)
- Site Collection to backup & restore
Create a folder to save the backup file
Let’s start by creating a folder to put our backup in, so we keep things organised and simple.
Choose the Site Collection to backup
- Open PowerShell ISE (or SharePoint Management Shell if you prefer)
- [optional] – Add the SharePoint Snap-in (if you use the ISE)
I’ve created a Site Collection called “Production” under my “portal” Web Application.
This is the Site Collection we are going to backup.
Get-SPSite | Where-Object {$_.Url -like "http://portal*"}
Backup the Site Collection
Now is the time to use the Backup-SPSite cmdlet.
We need to have/know the following:
- Full URL for the Site Collection (-Identity parameter)
- Path to the folder “SPBackups” we created earlier (-Path parameter)
- Name for the file (to save as <file>.bak)
Backup-SPSite -Identity http://portal.sptradi.com/sites/production -Path C:\Users\spinstall\Documents\SPBackups\production.bak
Restore the Site Collection into another Web Application
It’s extremely important to test your backup, and make sure it’s fully working, before deleting the Site Collection from its original Web Application.
I’ve also created a “Testing” Web Application (with associated database) where we are going to restore our Site Collection into, by using the Restore-SPSite cmdlet.
Note:
The target Site Collection URL must not be created. It will be created during the “restore” process.
Only the Web Application URL must be valid.
Restore-SPSite -Identity http://testing.sptradi.com/sites/productionrestored -Path C:\Users\spinstall\Documents\SPBackups\production.bak
Select “Yes to all” to confirm the action
Verification
If all went successfully, you can check the results!