Hi All,
Posting this as it may prove useful for someone.
Recently I had to sort out backups for a sharepoint server using no 3rd party backup tools.
i trawled the web and found this link which I ended up utilising:
-- Also referenced here:
--
The important bit, is the script at the end by Jason Chamiak. It is Jason's script that i have updated/ammended/hacked and pasted below.
NB: The orig script enumerates 'localhost' and creates a text file which it then reads to get sitenames. This did not work after removing 'default' host header so i have a text file which I keep manually updated with site names (currently sitting on the admin desktop. You can see which lines to uncomment if you want to re-enable this.
Full credit to Jason.
I'm not really a VB scriptie type person so my changes are pretty hacky but seems to be working fine. Perhaps i'll clean it up one day..
Cheers.
Posting this as it may prove useful for someone.
Recently I had to sort out backups for a sharepoint server using no 3rd party backup tools.
i trawled the web and found this link which I ended up utilising:
-- Also referenced here:
--
The important bit, is the script at the end by Jason Chamiak. It is Jason's script that i have updated/ammended/hacked and pasted below.
NB: The orig script enumerates 'localhost' and creates a text file which it then reads to get sitenames. This did not work after removing 'default' host header so i have a text file which I keep manually updated with site names (currently sitting on the admin desktop. You can see which lines to uncomment if you want to re-enable this.
Full credit to Jason.
I'm not really a VB scriptie type person so my changes are pretty hacky but seems to be working fine. Perhaps i'll clean it up one day..
Cheers.
Code:
'###############################################################################################
'# This script runs the stsadm enumsites operation and captures the output in a temp file. The #
'# URL is the only data left after the string manipulation which is then writen to a newly #
'# created text file. This script was created by Jason Chamiak. #
'###############################################################################################
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim objFSO
Dim objShell
Dim objName
Dim objTempFile
Dim objTextFile
Dim strText
Dim intTextLines
Dim objFile
Dim objFile1
Dim strTextFileLocation
Dim intTextLength
Dim intWriteLineLength
Dim strWriteLineTextStart
Dim strWriteLineTextFinal
Dim intChrPosition
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("Wscript.Shell")
objName = objFSO.GetTempName
objTempFile = objName
intTextLines = 0
strTextFileLocation = "C:\Documents and Settings\Administrator\Desktop\STATIC_SITE_LIST.txt"
'objShell.Run "cmd /c STSADM.exe -o enumsites -url [URL unfurl="true"]http://localhost[/URL] >" & objTempFile, 0, True
'Set objTextFile = objFSO.OpenTextFile(objTempFile, 1)
'Set objFile = objFSO.CreateTextFile(strTextFileLocation)
'objFile.Close
'Do While objTextFile.AtEndOfStream <> True
' strText = objTextFile.ReadLine
' If InStr(strText, "http") Then
' intTextLength = Len(Mid(Trim(strText),12,99))
' intWriteLineLength = intTextLength - 4
' strWriteLineTextStart = Mid(Trim(strText),12,99)
' intChrPosition = InStr(1,strWriteLineTextStart,Chr(34)) - 1
' strWriteLineTextFinal = Mid(Trim(strText),12,intChrPosition)
' End If
' Set objFile = objFSO.OpenTextFile(strTextFileLocation, ForAppending)
' If InStr(strText, "http") Then
' objFile.WriteLine(strWriteLineTextFinal)
' End If
' objFile.Close
'Loop
'objTextFile.Close
'objFSO.DeleteFile(objTempFile)
'############################################################################################
'# This portion of the script creates a new folder with the form yyyymmdd using the internal#
'# 'date' function to read current system date and time and create a folder in the yyyymmdd #
'# format. #
'# parentFolder is the 'root' folder for the backups. #
'# strBackupLocation is the full path created which is used in the following section to #
'# write backups to the newly created directory. #
'############################################################################################
'Declare Variables
'-----------------
Dim folderDateName 'String to store new folder name
Dim parentFolder 'String to store 'root' folder
Dim currDate 'Current Date
Dim strBackupLocation 'Full path for backups
Dim objFolder
'Set parentFolder
parentFolder = "Z:\Sharepoint_Backups\"
'Get current date
currDate = Date
folderDateName = (Year(currDate)*100 + Month(currDate))*100 + Day(currDate)
'Concatenate parentFolder and folderDateName to give full path for new backup
strBackupLocation = parentFolder & folderDateName & "\"
'Debug Option
'wscript.echo "Folder FULL Name: " & strBackupLocation
' Use shell object to create a new folder for backups
'-----------------------------------------------------
set objShell = CreateObject("Shell.Application")
set objFolder = objShell.NameSpace(ParentFolder)
objFolder.NewFolder folderDateName
'############################################################################################
'# This portion of the script reads the Site URLs from the text file created from the above #
'# code and inputs each URL into an array. The last portion of the URL string in each array #
'# index is extracted to a variable. The full URL variable and the extracted portion of the #
'# URL are used to populate the stsadm -url and -filename options. The stsadm command is #
'# run for each site stated in the text file and a backup file name containing the last #
'# portion of the URL is created. #
'############################################################################################
Dim arrSiteCollection()
Dim strLineText
Dim intSize
Dim strCmdRun
'Dim strBackupLocation
Set objShell = WScript.CreateObject("Wscript.Shell")
Set objFile = objFSO.OpenTextFile(strTextFileLocation, ForReading)
intSize = 0
'Debug Option
'wscript.echo "Folder FULL Name: " & strBackupLocation
Do While objFile.AtEndOfStream <> True
strText = objFile.ReadLine
ReDim Preserve arrSiteCollection(intSize)
arrSiteCollection(intSize) = strText
intTextLength = Len(strText)
intChrPosition = InStrRev(strText,Chr(47)) + 1
strWriteLineTextFinal = Mid(strText,intChrPosition,99)
strCmdRun = "stsadm.exe -o backup -url " & arrSiteCollection(intSize) & " -filename " & _
strBackupLocation & strWriteLineTextFinal
objShell.Run "cmd /c" & strCmdRun
intSize = intSize + 1
Loop