Every Techie needs to read something.

Tuesday, June 19, 2007

Script to backup SharePoint Team Services 2

Over at my very popular "Strange SharePoint Restore Issue" post, Rafael was having a problem with restoring a SharePoint backup. Unfortunately it isn't anything I have ran into, all of my experience has been with SharePoint Team Services 2. But Rafael asked me to post my SharePoint backup script anyway.

So here it is, but first, a little advice:

If you use this script to backup your SharePoint database:

  • As with any backup plan or device, Test out the restore procedure.
  • Backups are Version Dependent. There are various subversions. Here is a Penny Coventry (MVP) has a nice table that lays out the versions.
  • Make sure that the name remains the same. If you rename the backup file before you try to restore it, you will get a strange error.
  • Use this script at your own peril. I don't guarantee anything. This works for me, and I have tested it in my environment. You should do the same before you rely on it.
  • The script makes files named "YYYY-M-D-SharepointBackup.dat". You should only run it once a day, or it will error out the next runs.
  • I run this script on the sharpoint server. You may have to modify the strURL variable.
  • The path to STSADM varies by locale.

    '** Begin Copy here
    '******************* SPSBK.VBS ****************************************
    '** Save this file with a .vbs extension
    '**
    '** Share Point Services Backup
    '** This script is meant to be run periodically to create a backup of
    '** a sharepoint site to a local folder.
    '**
    '** This script runs stsadm with the parameters needed
    '** to create a full backup named after the date.
    '**********************************************************************


    'Create the Variables
    dim strCmdPath ' Used to store the path where stsadm is located
    dim strBKPath ' Used to store the path where backup files will be stored
    dim strFileDate ' Used to store the date which is appended to the file name.
    dim strCmd ' Used to hold the entire command sent to the shell.
    dim strURL ' Used to store the URL for the Sharepoint Backup


    '************************************************************************
    ' Here is where the location is set. Change these depending on Machine **
    '************************************************************************
    ' This is the path where stsadm is
    strCmdPath = "c:\Program Files\Common Files\Microsoft Shared\" & _

    "web server extensions\60\bin\"

    ' This is the path where backup files will be stored
    strBKPath = "d:\SharepointBackups\"

    strURL = "http://localhost/sites"

    '************************************************************************
    ' Assemble the date string for the filename
    strFileDate = year(now) & "-" & month(now) & "-" & day(now)

    ' Build the command line.
    strCmd = chr(34)& strCmdPath & "stsadm.exe " & chr(34) & "-o backup -url " & _
    strURL & " -filename " & strBKPath & strFileDate & "-SharepointBackup.dat"

    ' Execute the command.
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCmd)
    '*** End Copy Here


    A Good SharePoint Blog:

    Penny on SharePoint - Penny Coventry MVP's SharePoint blog.


No comments: