Automated Daily Site Collection Back up
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:\FPBackup\DailySiteCollectionBackUp\$today\Backup.dat"
# Log file location
$logFile = "$backupDirectory\BackupLog.log"
# Address of the Site Collection to backup
$Site = "http://moss01/"
# 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
}
No comments:
Post a Comment