Tuesday, November 16, 2010

Manually backup Windows SharePoint Services 3.0 and purge old backups from command line (script)

SharePoint Services 3.0 creates its own SQL instance which needs to be backed up. Here are a couple of steps you can take to do a manual back up and purge older backups.


Step 1: Create a batch file and setup a task on the server that you are attempting to backup.


Here is a batch file I've used from http://technet.microsoft.com/en-us/library/cc288541(office.12).aspx
backupsharepoint.bat

cd %COMMONPROGRAMFILES%\Microsoft Shared\web server extensions\12\BIN 
stsadm.exe -o backup -directory "d:\Backup Sharepoint" -backupmethod full 
echo completed
It simply changes the directory to "%COMMONPROGRAMFILES%\Microsoft Shared\web server extensions\12\BIN" and runs stsadmn.exe. Note: The directory this is saving the backup to is "d:\Backup Sharepoint". Follow the instruction from here if you run into any snags.


Step 2: Once you've tested your backup task you can add a script to delete folders older than 10 days using VBS. Here is an example from here: http://windowsxp.mvps.org/wshdelfolder.htm


Create a vbs file called deloldfolders.vbs and save it in the same directory as your backupsharepoint.bat. Here is the code for it.
'DelFolder.vbs - December 1, 2005
'Ramesh Srinivasan


Dim i, fso, f, f1, sf, BasePath, CalcResult, fNameArray()
BasePath = "d:\Backup Sharepoint"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(BasePath)
Set sf = f.SubFolders
For Each f1 in sf
     CalcResult = DateDiff("d",f1.DateCreated,Now)
          if CalcResult > 10 then
                ReDim preserve fNameArray(i)
                fNameArray(i) = f1.Name
                i = i + 1
        end if
Next
For Each fName in fNameArray
    FSO.DeleteFolder(BasePath & "\" & fName)
Next
Then add this line to the end of your backupsharepoint.bat.
cscript.exe c:\deloldfolders.vbs 
So now you should have a task that run backupsharepoint.bat which will backup the databases and purge older backups.

No comments:

Disclaimer

All data and information provided on this site is for informational purposes only. adminbromo.blogspot.com makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis.