Free SharePoint Backups (3 of 4)

SharePoint
This entry is part 3 of 4 in the series Free SharePoint Backups

This is the 3rd article of the Free SharePoint Backups series. If you haven’t already, check out:

In the 3rd article, we’ll talk about some of the other things that need to be backed up on a SharePoint server. I have scripts for these too!

There are two primary components besides the sites that need to be backed up. You may never use these but they take up little space and would come in handy in some disaster recovery scenarios. The two components are:

  • The IIS metabase: The metabase is a repository for most Internet Information Services (IIS) configuration values.
  • Note: This applies to IIS6 only. IIS 7.0 uses XML to store configuration data, more on that later.

  • The 12 hive: The 12 hive is a folder location that contains templates, themes, features, etc for SharePoint. Its especially important to back this up if you’ve made cuztomizations.

I’ll show you the batch file and then explain it. Here it is

@ECHO OFF
ECHO ================================================
ECHO Backup Script For Office SharePoint Server 2007
ECHO        Written By: Wahid Saleemi
ECHO ================================================
cscript C:\Windows\System32\iisback.vbs /backup /b sharepoint /overwrite
COPY /Y C:\Windows\System32\inetsrv\Metaback\sharepoint.* G:\Backups\IIS
robocopy "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12" G:\Backups\12\ /MIR /ZB /SEC /V /LOG:D:\BackupBatch\12hive.log
cscript D:\BackupBatch\reportlog.vbs

This batch file calls iisback.vbs, which should be installed already. It will name the backup “sharepoint.” For details on how it works, see this TechNet article: Backing Up IIS Configurations using iisback.vbs

Next, we use a simple COPY command to copy the backup files to an alternate location. In my example its the G:\Backups\IIS folder. I use another backup utility to archive this to a remote disk library.

Then, we’ll use robocopy to copy the 12 hive. Robocopy is a very useful app! It comes with Windows Server 2008 but if you’re still on 2003 you can download it from Microsoft. The example above assumes SharePoint is installed in its default location.

Finally, we run a vbscript similar to the last post that will send us the report to our email so we can review it. Here’s the vbscript.

'--------------------
' 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 = "http://schemas.microsoft.com/cdo/configuration/sendusing"
	Const cdoSendUsingPort = 2
	Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"

	' This is the sender of the report
	strVirt = "http://sharepoint.domain.com"
	strSMTPServer = "mailserver1"
	strReportTo = "portaladmin@domain.com"
	strFrom = "report@domain.com"
	strLogFile = "D:\BackupBatch\12hive.log"	

	' This is the subject
	strSubject = "SharePoint IIS/12 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
		.Update
	End With

	With objMessage
		Set .Configuration = objConfig
			.To = strReportTo
			.From = strFrom
			.Subject = strSubject
			.AddAttachment strLogFile
			.HTMLBody = "Attached is your IIS and 12 Hive backup for " & strVirt
	End With

	objMessage.Send

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

Regarding IIS 7.0 (Windows Server 2008) and the metabase: IIS 7.0 doesn’t use a metabase. It uses the applicationHost.config file. You can read Robert McCurray’s Blog for more details. So, for Windows Server 2008, instead of using the script above, use the one below. It’s Robert McCurray’s script plus some additions:

@echo offcls
DEL /Y %WinDir%\System32\Inetsrv\Backups\*
pushd "%WinDir%\System32\inetsrv"

echo.| date | find /i "current">datetime1.tmp
echo.| time | find /i "current">datetime2.tmp

for /f "tokens=1,2,3,4,5,6" %%i in (datetime1.tmp) do (
  echo %%n>datetime1.tmp
)
for /f "tokens=1,2,3,4,5,6" %%i in (datetime2.tmp) do (
  echo %%m>datetime2.tmp
)
for /f "delims=/ tokens=1,2,3" %%i in (datetime1.tmp) do (
  set TMPDATETIME=%%k%%i%%j
)
for /f "delims=:. tokens=1,2,3,4" %%i in (datetime2.tmp) do (
  set TMPDATETIME=D%TMPDATETIME%T%%i%%j%%k%%l
)

appcmd add backups %TMPDATETIME%

del datetime1.tmp
del datetime2.tmp

set TMPDATETIME=

popd
echo.
COPY /Y %WinDir%\System32\Inetsrv\Backups\* G:\Backups\IIS
robocopy "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12" G:\Backups\12\ /MIR /ZB /SEC /V /LOG:D:\BackupBatch\12hive.log
cscript D:\BackupBatch\reportlog.vbs

As you can see, even with built-in tools and at no cost, you can still design a backup solution that is somewhat robust. This is a good starting point. However, for a larger production environment, you should really look at a 3rd party backup solution. We’ll look at some of these in the last post of this series.

Series NavigationFree SharePoint Backups (2 of 4)Free SharePoint Backups (4 of 4)
0 comments… add one

Leave a Reply