• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

sbs 2008 script problem

Hi all,
I am trying to write a vbscript to automatically backup my Sharepoint. I am testing it by opening a command prompt as administrator and then running the script. The script correctly creates the backup sub-directory however, it doesn't appear to launch stsadm as it doesn't create any backup files and it doesn't show as running in Taks manager - All Users.

How can I test this script and ensure it works? I have attached the script incase i made an error in it.
Thank you.
' Description:
' Tool for planning and automating files/entries
' Microsoft Office SharePoint Server 2007
'
' Will generate file entry names with the following style: YYYYMMDD
' E.g.: 20070228

Option Explicit

Const BackupPath = "D:\SharePoint_Backup\"
Const C_SiteURL = "http://companyweb"
Const C_NamePrefix = "SharePoint_"
Const C_SharePointBin = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin"

Dim fso, folder, filedate, f, file, filesys
Dim sBackupPrefix

set filesys=CreateObject("Scripting.FileSystemObject") 
Set fso = CreateObject("Scripting.FileSystemObject")

if Not fso.FolderExists(BackupPath) then
WScript.Echo "The folder " & BackupPath & " does not exist!"
WScript.Quit
end if

Set folder = fso.GetFolder(BackupPath)
filedate = now
Set f = Nothing

' Assigns a name of the new file
sBackupPrefix = BackupPath & year(now) & right("00" & Month(now),2) & right("00" & day(now),2)

Set folder = filesys.CreateFolder(sBackupPrefix)

Dim objShell
Dim strcmd

Set objShell = CreateObject("WScript.Shell")
'msgbox ("C_SiteURL = " & C_SiteURL & ", filename = " & sBackupPrefix )
'WScript.Quit

strcmd = C_SharePointBin & "\stsadm.exe -o backup -url " & C_SiteURL & " -filename " & sBackupPrefix & "\companyweb.bak -backupmethod full -includeusersecurity"
wscript.echo strcmd 
objShell.Exec(strCmd)

WScript.Echo "Backup of site collection successful"
Set objshell = nothing

Open in new window

0
LostInWindows
Asked:
LostInWindows
  • 7
  • 5
1 Solution
 
RobSampsonCommented:
Hi there, I think you only need to enclose the stsadm.exe part in quotes, by changing this:
strcmd = C_SharePointBin & "\stsadm.exe -o backup -url " & C_SiteURL & " -filename " & sBackupPrefix & "\companyweb.bak -backupmethod full -includeusersecurity"

to this

strcmd = """" & C_SharePointBin & "\stsadm.exe"" -o backup -url " & C_SiteURL & " -filename " & sBackupPrefix & "\companyweb.bak -backupmethod full -includeusersecurity"


Regards,

Rob.
0
 
LostInWindowsAuthor Commented:
I tried your suggestion and stsadm still doesn't show in Task Manager and the destination directory is still empty
0
 
RobSampsonCommented:
OK, maybe it's command line only...try this
strcmd = "cmd /c """ & C_SharePointBin & "\stsadm.exe"" -o backup -url " & C_SiteURL & " -filename " & sBackupPrefix & "\companyweb.bak -backupmethod full -includeusersecurity"

If that doesn't work, then after that line put this
strcmd = InputBox("Prompt", "Title", strcmd)

and copy and paste that to a command line and see what it does.

Regards,

Rob.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LostInWindowsAuthor Commented:
The Input box returns an error see below

1.jpg
0
 
RobSampsonCommented:
You should have both of these lines

strcmd = "cmd /c """ & C_SharePointBin & "\stsadm.exe"" -o backup -url " & C_SiteURL & " -filename " & sBackupPrefix & "\companyweb.bak -backupmethod full -includeusersecurity"
strcmd = InputBox("Prompt", "Title", strcmd)

so that you build the comand, then the InputBox should display the command, so that you can copy and paste it into a DOS box.

Does the inputbox display at all?

Regards,

Rob.
0
 
LostInWindowsAuthor Commented:
I received the following output:
D:\SharePoint_Backup>cmd /c "C:\Program Files\Common Files\Microsoft Shared\Web
Server Extensions\12\Bin\stsadm.exe" -o backup -url http://companyweb -filename
D:\SharePoint_Backup\20091230\companyweb.bak -backupmethod full -includeusersecu
rity

Command line error. Invalid parameter.


For site collection backup:
    stsadm.exe -o backup
        -url <url>
        -filename <filename>
        [-overwrite]
        [-nositelock]

For catastrophic backup:
    stsadm.exe -o backup
        -directory <UNC path>
        -backupmethod <full | differential>
        [-item <created path from tree>]
        [-percentage <integer between 1 and 100>]
        [-backupthreads <integer between 1 and 10>]
        [-showtree]
        [-quiet]
        [-force]

I then removed the option -includeusersecurity and the process worked.

I don't know about this user security item. I tried it before with Microsoft and it works if you type it into the command line but it will not work in a script and it will not work with copy/paste.
0
 
RobSampsonCommented:
OK, so if we omit that by changing this
strcmd = "cmd /c """ & C_SharePointBin & "\stsadm.exe"" -o backup -url " & C_SiteURL & " -filename " & sBackupPrefix & "\companyweb.bak -backupmethod full -includeusersecurity"

to this
strcmd = "cmd /c """ & C_SharePointBin & "\stsadm.exe"" -o backup -url " & C_SiteURL & " -filename " & sBackupPrefix & "\companyweb.bak -backupmethod full"

Does it work?

Rob.
0
 
LostInWindowsAuthor Commented:
Here is the output with the -includeusersecurity removed:

D:\SharePoint_Backup>cmd /c "C:\Program Files\Common Files\Microsoft Shared\Web
Server Extensions\12\Bin\stsadm.exe" -o backup -url http://companyweb -filename
D:\SharePoint_Backup\20091230\companyweb.bak -backupmethod full

Setting the site collection to be read-only for the duration of the backup. If t
he operation is interrupted, make sure to check the site lock for this site coll
ection. For more information see stsadm.exe -help getsitelock and stsadm.exe -he
lp setsitelock.

Operation completed successfully.
0
 
LostInWindowsAuthor Commented:
Thank you very much for your help. if you have any suggestions about the user security please let me know.
0
 
LostInWindowsAuthor Commented:
Thanks for a timely and efficient solution
0
 
RobSampsonCommented:
Thanks for the grade.

It appears that the -includeusersecurity parameter might only be valid for the Import or Export operations, not the Backup operation.

http://blogs.msdn.com/joelo/archive/2006/10/16/what-happened-to-smigrate-exe-what-if-i-only-want-to-upgrade-one-site-what-can-i-do-now-with-stsadm-exe.aspx
http://blog.techgalaxy.net/archives/993

So if you wanted to preserve the security info, try using the Export method instead.

Regards,

Rob.
0
 
LostInWindowsAuthor Commented:
Thanks, I had totally missed that. I will check it out in the morning.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now