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!”
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.
Thanks for the feedback Tim!
Thank so much for this small but efficient script.
how would you back up only sites that have been modified since last backup?
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.
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
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….
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…
Hey Robert, are you sure you have enough disk space?
Mine run, but seems like never finish, the DOS prompt still blinking.
please help…thanks
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.
Hey Henry, Were did u leave space i seem t have the same issue. Window pops up creates te folder but no data.
oops i mean Chris :S
actually i have same issue Robert had… and i do have space. 89gig to be exact. 😦
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.
No im not having space issue. I just dont see any data after i run the script. Plz help
Wow thanks for the great script. Just a quick edit in notepad to replace all the quotes and I was on my way!
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.
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
Love the blog…people are missing out not using Twitter more
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?
‘ “
how to perform differential backup ? i changed to differential instead of full in backup method , but it did not work .