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



September 14, 2007 at 7:20 am
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!”
September 14, 2007 at 7:21 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.
September 14, 2007 at 8:37 am
Thanks for the feedback Tim!
October 7, 2007 at 9:50 am
Thank so much for this small but efficient script.
December 18, 2007 at 3:07 pm
how would you back up only sites that have been modified since last backup?
December 18, 2007 at 7:45 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.
April 10, 2008 at 9:01 am
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
April 10, 2008 at 9:44 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….
June 10, 2008 at 9:30 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…
June 10, 2008 at 7:40 pm
Hey Robert, are you sure you have enough disk space?
June 18, 2008 at 10:01 am
Mine run, but seems like never finish, the DOS prompt still blinking.
please help…thanks
June 23, 2008 at 9:39 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.
July 30, 2008 at 12:17 pm
Hey Henry, Were did u leave space i seem t have the same issue. Window pops up creates te folder but no data.
July 30, 2008 at 12:18 pm
oops i mean Chris :S
July 30, 2008 at 12:21 pm
actually i have same issue Robert had… and i do have space. 89gig to be exact.
July 30, 2008 at 12:38 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.
August 1, 2008 at 5:05 am
No im not having space issue. I just dont see any data after i run the script. Plz help
March 24, 2009 at 8:25 pm
Wow thanks for the great script. Just a quick edit in notepad to replace all the quotes and I was on my way!
July 23, 2009 at 9:29 pm
If you’re backing up on to a network drive, you need to make sure the SP service account has read/write access to that location.
January 19, 2010 at 5:23 am
Hi
Looks good but fails at line 8 Character 14
I make that the end of the line?
“undetermined string constant”
Anybody figure that?
Cheers
Bob
January 31, 2010 at 7:08 pm
Love the blog…people are missing out not using Twitter more
March 31, 2010 at 12:54 am
Hi guys
I am the lucky guy who have been handed the project of writing an app to backup a sharepoint site in .net(C#) and I have no idea where to start.
Basically you need to be able to choose which site to backup and then which sub sites. Then also the master page and other custom web parts etc.
Any help?