Automated Backup Script for WSSv3/MOSS 2007

February 13th, 2007 § 23 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!

Advertisement

§ 23 Responses to Automated Backup Script for WSSv3/MOSS 2007

  • TimH says:

    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 says:

    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.

  • Henry says:

    Thanks for the feedback Tim!

  • Anty says:

    Thank so much for this small but efficient script.

  • David Kearns says:

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

  • Henry says:

    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.

  • Christopher Losh says:

    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 says:

    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….

  • Robert Corradini says:

    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…

  • Henry says:

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

  • JD says:

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

  • Henry says:

    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.

  • Albert says:

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

  • Albert says:

    oops i mean Chris :S

  • Albert says:

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

  • Henry says:

    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.

  • Albert says:

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

  • Dan Colyer says:

    Wow thanks for the great script. Just a quick edit in notepad to replace all the quotes and I was on my way!

  • Sino16 says:

    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.

  • Bob Spearing says:

    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

  • Marcel Tackitt says:

    Love the blog…people are missing out not using Twitter more

  • Jurie says:

    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?

  • berrahomeberra says:

    ‘ “

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Automated Backup Script for WSSv3/MOSS 2007 at The SharePoint Swiss Army Knife.

meta

Follow

Get every new post delivered to your Inbox.

Join 584 other followers