The Art of SharePoint Evolution

Stories from a SharePoint Engineer that isn’t afraid of Visual Studio.

Automated Backup Script for WSSv3/MOSS 2007

with 17 comments

I got this 2003 script from SPSFAQ.com awhile back and have since customized it for the 2007 products. Here’s a script to run nightly backups for Sharepoint as a Windows Scheduled Task:

———————————————-

””””””’
‘Begin Script
””””””’
Dim fso, f, fspec
dim yr, mo, dt, hr, min, sec

yr = Year(Now)

mo = Month(Now)
if mo < 10 Then
mo = “0″ & mo
end if

dt = Day(Now)
if dt < 10 Then
dt = “0″ & dt
end if

hr = Hour(Now)
if hr < 10 Then
hr = “0″ & hr
end if

min = Minute(Now)
if min < 10 Then
min = “0″ & min
end if

sec = Second(Now)
if sec < 10 Then
sec = “0″ & sec
end if

destFolder = “SPSPortal-” & yr & “-” & mo & “-” & dt & “-” & hr & “-” & min & “-” & sec

Set fso = CreateObject(”Scripting.FileSystemObject”)
Set f = fso.CreateFolder(”D:\SPS2007Backups\SPSPortal-” & yr & “-” & mo & “-” & dt & “-” & hr & “-” & min & “-” & sec) <<<<<<<<< Customize this

bkFolder = f.Path
bkFolder = Replace(bkFolder, “”, “\”)
bkFolder = bkFolder

””””””””””””’
‘Run the spsbackup script
””””””””””””’
Set objShell = CreateObject(”WScript.Shell”)
objShell.CurrentDirectory = “c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\”

objShell.Exec (”STSADM.exe -o backup -directory ” & bkFolder & ” -backupmethod full”) <<<<<<<<<<<<< You can customize this
 WScript.Echo “Backup Started!”

———————————————————————————–

 Save that as a .vbs file and to run it as a scheduled task go to Control Panel > Scheduled Tasks > Add Scheduled Task > And Follow the Prompts. Happy back-ups!

Written by Henry

February 13, 2007 at 10:12 am

Posted in SharePoint

17 Responses to 'Automated Backup Script for WSSv3/MOSS 2007'

Subscribe to comments with RSS or TrackBack to 'Automated Backup Script for WSSv3/MOSS 2007'.

  1. Thanks for this it really helped out for automating my backups to a remote server and then backing them up to tape. It just seems to work better than using Veritas to back it up because the trestores just don’t work 100% of the time.

    One thing to note are the changes I had to make to your script due to website formatting:

    The quotes ” ” are all incorrect and the <<< “text” need to be removed.

    Here is an example of your script modified to work on my system:

    Dim fso, f, fspec
    dim yr, mo, dt, hr, min, sec

    yr = Year(Now)

    mo = Month(Now)
    if mo < 10 Then
    mo = “0″ & mo
    end if

    dt = Day(Now)
    if dt < 10 Then
    dt = “0″ & dt
    end if

    hr = Hour(Now)
    if hr < 10 Then
    hr = “0″ & hr
    end if

    min = Minute(Now)
    if min < 10 Then
    min = “0″ & min
    end if

    sec = Second(Now)
    if sec < 10 Then
    sec = “0″ & sec
    end if

    destFolder = “SPSPortal-” & yr & “-” & mo & “-” & dt & “-” & hr & “-” & min & “-” & sec

    Set fso = CreateObject(”Scripting.FileSystemObject”)
    Set f = fso.CreateFolder(”\\toamail2\spbackups\SPSPortal-” & yr & “-” & mo & “-” & dt & “-” & hr & “-” & min & “-” & sec)

    bkFolder = f.Path
    bkFolder = Replace(bkFolder, “”, “\”)
    bkFolder = bkFolder

    Set objShell = CreateObject(”WScript.Shell”)
    objShell.CurrentDirectory = “c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\”

    objShell.Exec (”STSADM.exe -o backup -directory ” & bkFolder & ” -backupmethod full”)
    WScript.Echo “Backup Started!”

    TimH

    14 Sep 07 at 7:20 am

  2. Okay people its the website that is messing up the scripts. Just use notepad’s find/replace feature to replace all of the quotes with standard ones.

    TimH

    14 Sep 07 at 7:21 am

  3. Thanks for the feedback Tim!

    Henry

    14 Sep 07 at 8:37 am

  4. Thank so much for this small but efficient script.

    Anty

    7 Oct 07 at 9:50 am

  5. how would you back up only sites that have been modified since last backup?

    David Kearns

    18 Dec 07 at 3:07 pm

  6. Hey David, for that you’ll want to run the full backup once and then use i think the -backupmethod incremental parameter instead of full.

    Henry

    18 Dec 07 at 7:45 pm

  7. First…I apologize for being a newbie to script writing. I seem to have the script written correctly according to what is posted above, but it doesn’t seem to work. I get the command prompt window to pop up and the “Backup Started” echo comes up, even the folder for the backups is created, but no files are created. Please help….thank you

    Christopher Losh

    10 Apr 08 at 9:01 am

  8. Nevermind….so sorry….I had one of our analysts look at it and I was missing a space….of all things!!….thanks for the great little piece of code….

    Christopher Losh

    10 Apr 08 at 9:44 am

  9. I am getting the same issue that Christopher Losh had, where was he missing a space. It says back started and creates the backup directory, but nothing is there…

    Please Help…

    Robert Corradini

    10 Jun 08 at 9:30 am

  10. Hey Robert, are you sure you have enough disk space?

    Henry

    10 Jun 08 at 7:40 pm

  11. Mine run, but seems like never finish, the DOS prompt still blinking.
    please help…thanks

    JD

    18 Jun 08 at 10:01 am

  12. Hey JD, you can check in Central Admin to see if your backup had completed anyways. If it is then you can set the scheduled task to automatically stop after a certain amount of time.

    Henry

    23 Jun 08 at 9:39 am

  13. Hey Henry, Were did u leave space i seem t have the same issue. Window pops up creates te folder but no data.

    Albert

    30 Jul 08 at 12:17 pm

  14. oops i mean Chris :S

    Albert

    30 Jul 08 at 12:18 pm

  15. actually i have same issue Robert had… and i do have space. 89gig to be exact. :(

    Albert

    30 Jul 08 at 12:21 pm

  16. Hey Albert, you can check in Central Admin to see how much space you’ll need for the back up @ http://centralAdmin/_admin/StartBackup.aspx?backupselect=Farm

    If you still have the same problem then I suspect there may be a typo somewhere in the directory path or stsadm command or position of the quotes.

    Henry

    30 Jul 08 at 12:38 pm

  17. No im not having space issue. I just dont see any data after i run the script. Plz help

    Albert

    1 Aug 08 at 5:05 am

Leave a Reply