Add-PsSnapin Microsoft.SharePoint.Powershell –ErrorAction SilentlyContinue
try
{
$today = (Get-Date -Format dd-MM-yyyy)
$backupDirectory = "D:\Backup\DailySiteCollectionBackUp\$today"
# Backup file Location
$backupFile = "D:\Backup\DailySiteCollectionBackUp\$today\Backup.bak"
# Log file location
$logFile = "$backupDirectory\BackupLog.log"
# Address of the Site Collection to backup
$Site = "http://globas:1060/"
# Location of the Backup Folder
if (-not (Test-Path $backupDirectory))
{
[IO.Directory]::CreateDirectory($backupDirectory)
#New-Item $logPath -type $backupDirectory
}
# Get backup start date and time
$backupStart = Get-Date -format "MM-dd-yyyy HH.mm.ss"
# creates a log file Start-Transcript -Path
Start-Transcript -Path $logFile
# This will actually initiate the backup process.
Write-Host
Write-Host
Write-Host "Backup starting at $backupStart for $Site "
Write-Host "******************************************"
Backup-SPSite -Identity $Site -Path $backupFile -Force
$backupComplete = Get-Date -format "MM-dd-yyyy HH.mm.ss"
Write-Host
Write-Host
Write-Host "Backup Completed at $backupComplete for $Site "
Write-Host "******************************************"
Stop-Transcript
}
Catch
{
$ErrorMessage = $_.Exception.Message
write "$today BackUp Failed $ErrorMessage ">>$logFile
}
Saturday, October 20, 2012
Daily Site Backup Powershell
Labels:
Powershell
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment