Automated Backup Script for WSSv3/MOSS 2007
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!



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
September 14, 2007 at 7:20 am
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
September 14, 2007 at 7:21 am
Thanks for the feedback Tim!
Henry
September 14, 2007 at 8:37 am
Thank so much for this small but efficient script.
Anty
October 7, 2007 at 9:50 am
how would you back up only sites that have been modified since last backup?
David Kearns
December 18, 2007 at 3:07 pm
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
December 18, 2007 at 7:45 pm
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
April 10, 2008 at 9:01 am
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
April 10, 2008 at 9:44 am
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
June 10, 2008 at 9:30 am
Hey Robert, are you sure you have enough disk space?
Henry
June 10, 2008 at 7:40 pm
Mine run, but seems like never finish, the DOS prompt still blinking.
please help…thanks
JD
June 18, 2008 at 10:01 am
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
June 23, 2008 at 9:39 am
Hey Henry, Were did u leave space i seem t have the same issue. Window pops up creates te folder but no data.
Albert
July 30, 2008 at 12:17 pm
oops i mean Chris :S
Albert
July 30, 2008 at 12:18 pm
actually i have same issue Robert had… and i do have space. 89gig to be exact.
Albert
July 30, 2008 at 12:21 pm
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
July 30, 2008 at 12:38 pm
No im not having space issue. I just dont see any data after i run the script. Plz help
Albert
August 1, 2008 at 5:05 am
Wow thanks for the great script. Just a quick edit in notepad to replace all the quotes and I was on my way!
Dan Colyer
March 24, 2009 at 8:25 pm