The issue:
Our company is creating their own backup restoration tool. The tool itself will be able to look into a backup file and pull out and restore a Document, Library or Site to a restoration location in the Central Administration Site Collection. How will that tool work? Don’t ask me, I’m no developer. However I’ve been assured it will be so cool and not leak memory, or bring down my SharePoint Farms! We’ll just see.
For this tool, I was asked to create a simple script to create a directory and push the Site Collection backups to a new directory based on date and time format. I figured I’d share it with you all, it’s pretty simple. Generally I’ve setup my backups to run a .bat file script which calls on a PowerShell script which does all the real work. The batch file is a simple one liner that says: ‘powershell –command <location><filename>.ps1’
The called PowerShell script is also pretty simple. You don’t need much head scratching for this trust me. We’ll step through it.
1 – Open the SharePoint Snapin
‘Add-PSSnapin Microsoft.SharePoint.PowerShell’
2 – Get the Date and Time to a variable
‘$DTS = Get-Date -format “yyy_MM_dd_hh-mm” ‘ - Here is a guide for date time formats. Stay away from something with special characters etc. You never know how that stuff behaves.
3 – Set the location of your backups to be used in the commands that you’ll make later.
‘$Location = “f:\backup\” ‘
4 – Make the call to actually perform the Site Collection Backups
This comes in two parts, making the new directory:
‘New-Item $location\Whale\$DTS\ -type directory’ – This is per site in your collection. I’m certain you can create an additional step to call Get-SPSIte and then for each site… etc. But that was beyond the scope of my mission.
And secondly running the backup:
‘backup-spsite -identity http://whale.<domain>.com -path $location\whale\$DTS\whale_<domain>_com.bak –force’
So essentially it all looks like this:
Add-PSSnapin Microsoft.SharePoint.PowerShell
$DTS = Get-Date -format “yyy_MM_dd_hh-mm”
$Location = “f:\backup\”
New-Item $location\Whale\$DTS\ -type directory
backup-spsite -identity http://whale.<domain>.com -path $location\whale\$DTS\whale_<domain>_com.bak -force
What you’ll end up with in your directory structure is something like this.
Using windows task manager on the server you can create a simple task to call the batch file at whatever interval you need, hourly, daily, weekly whatever gets your goat.
