Free SharePoint Backups (2 of 4)

This entry is part [part not set] of 4 in the series Free SharePoint Backups

In the first article, I showed you one way to use a Windows script, batch file and task scheduler to perform a backup of each Site Collection in your farm.

Next up: Backing up the entire farm

This is really very simple. As you may know, you can use the Backup/Restore function in the SharePoint Central Administration interface. Unfortunately, you can’t schedule that. The solution is to use STSADM instead. This small batch file will log the time your backup starts and completes. It uses STSADM to backup the farm to a file share. Additionally, so we don’t have to login to go check out this log file, we can have it emailed to us.

Step 1:
Create the batch file using notepad or another text editor (I like Notepad++)

@ECHO ================================================
@ECHO Backup Script For Office SharePoint Server 2007
@ECHO        Written By: Wahid Saleemi
@ECHO ================================================
@ECHO %date - %time% Backup Started >> D:\BackupBatch\farmbackup.log
stsadm -o backup -backupmethod full -directory \\Backups\Farm -overwrite
@ECHO %date - %time% Backup Complete >> D:\BackupBatch\farmbackup.log
@ECHO Execute the reporter script to email us that backups are done.
cscript D:\BackupBatch\reportfarm.vbs

Step 2:
Create a scheduled task that calls the batch file. I set mine to run using the farm service account at 3am everyday.

Step 3:
Create the vbs file using notepad, paste the following lines in.

' Send Email
Dim FSO, objShell
Dim strVirt, strPath, strReportTo
Dim strFileName, strTempFile, strLogFile
Dim dtmThisMinute, dtmThisHour
Dim dtmThisDay, dtmThisMonth, dtmThisYear

'dtmThisSecond = PadDigits(Second(Now), 2)
'dtmThisMinute = PadDigits(Minute(Now), 2)
'dtmThisHour = PadDigits(Hour(Now), 2)
'dtmThisDay = PadDigits(Day(Now), 2)
'dtmThisMonth = PadDigits(Month(Now), 2)
'dtmThisYear = Year(Now)

	' Define consts
	Const cdoSendUsingMethod = ""
	Const cdoSendUsingPort = 2
	Const cdoSMTPServer = ""
	' This is the sender of the report
	strVirt = ""
	strSMTPServer = "mailserver1"
	strReportTo = ""
	strFrom = ""
	strLogFile = "D:\BackupBatch\farmbackup.log"	

	' This is the subject
	strSubject = "MOSS Farm-level Backup Report for " & dtmThisYear & "-" & dtmThisMonth & "-" & dtmThisDay & "-" & dtmThisHour
	Set objMessage = CreateObject("CDO.Message")
	Set objConfig = CreateObject("CDO.Configuration")
	Set objFields = objConfig.Fields
	With objFields
		.Item(cdoSendUsingMethod) = cdoSendUsingPort
		.Item(cdoSMTPServer) = strSMTPServer
	End With
	With objMessage
		Set .Configuration = objConfig
			.To = strReportTo
			.From = strFrom
			.Subject = strSubject
			.AddAttachment strLogFile
			.HTMLBody = "Attached is your farm-level backup for " & strVirt
	End With

	Set objMessage = Nothing
	Set objConfig = Nothing
	Set objFields = Nothing
	strHTMLBody = vbNullString
    strFrom = vbNullString
    strSubject = vbNullString
	arrEmailAddress = vbNullString
	intArraySize = vbNullString

Remember to change the str values to your own. (By the way, anyone knows an easier way to do this, let me know! I know the vbscript needs to be cleaned up).

This post showed you how to automate farm-level backups using the free Windows tools and commands available to you. The files are sent to a fire share. That file share can be backed up to tape or disk for archiving if you needed.
Next up, I’ll show you some other things you should backup, such as the 12 hive, and how you can schedule that as well.

Series Navigation
0 comments… add one

Leave a Reply