Saturday, January 19, 2013

Back up the farm using power shell

I got a requirement from my client to take the backup of the farm on a weekly basis using automated scheduler.

we do have a standard powershell cmdlet, that helps us in taking the back up of farm using backup-spfarm cmdlet.

We could do the job on a dialy or weekly basis with power shell script and windows task scheduler.

After I searched for some time , I got an excellent blog from http://sharepointpolice.com/ .

Here is the same script , I used for my farm.

Add-PSSnapin Microsofot.SharePoint.Powershell -erroraction silentlycontinue
try
{
--create the directory with the today's date
$today=Get-Date -format "dd-MM-yyyy"
[IO.Directory]::CreateDirectory("\\SPQABackup\$today")
Backup-SPFarm -directory SPQABackup\$today -Backupmethod full
$emailfrom="homeq@domain.com"
$emailto="emilgroup@domain.com"
$subject="Farm backup schedule updated "+$today
$body="The sharepoint QA farm back up was successfull for "+$today
--check central admin for outbound email settings and get that adderss here
$smtpserver="mailhost.domain.com"
$smtp=new-object Net.Mail.Smtpclient($smtpserver)
$smtp.send($emailfrom,$emailto,$subject,$body);
}
catch
{
$errormessage=$_.Exception.Message
$emailfrom="SPAdmin@domain.com"
$emailto="people@domain.com"
$subject="Farm Back up schedule status "+$today
$body="The sharepoint QA farm back up was failed for "+$today+" "+$errormessage;
$smtpserver="mailhost.domain.com"
$smtp=new-object Net.Mail.Smtpclient($smtpserver)
$smtp.send($emailfrom,$emailto,$subject,$body)
}
view raw gistfile1.txt hosted with ❤ by GitHub

No comments: