Wednesday, February 28, 2007

Backup Script for SharePoint 2007

Thanks (Muchos Gracias) to a posting on MSD2D by Herman Vargas and my colleague, Mario Barajas for translating all the comments that were in Spanish. I've managed to modify the script for a SharePoint 2007 backup. Not the best out there, but it's something.

I have not tested the script fully and assume that it would work. The script keeps the 5 latest backup copies. You can modify the following to suit what you need:

C_BackupPath : The path where the backup resides
C_NamePrefix : Prefix of the filename of the "backup prefix". Example: SharePoint_20070228
C_SiteURL : The URL of the SharePoint Site to be backed up

C_SharePointBin: Path to the Bin directory of Sharepoint installation
C_MaxBackupPerFolder: Number of XML Manifest per C_BackupPath folder.


Below is the .vbs script:

' Description:
' Tool for planning and automating files/entries
' Microsoft Office SharePoint Server 2007
'
' Will generate file entry names with the following style: MOSS_YYYYMMDD
' E.g.: SharePoint_20070228
' If there are more than 5 entries in the directory, then it will choose the one with the oldest date and will delete it

Option Explicit

Const C_BackupPath = "C:\Backup"
Const C_SiteURL = http://sharepointserver/site
Const C_NamePrefix = "SharePoint_"
Const C_SharePointBin = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin"
Const C_MaxBackupPerFolder = 5

Dim fso, folder, filedate, f, file
Dim sBackupPrefix
Dim CntXml
Dim DeletedBackup

Set fso = CreateObject("Scripting.FileSystemObject")

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

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

' Counts the number of XML manifests that are in the directory
CntXml=0
for each file in folder.files
if lCase(right(file.name,4)) = ".xml" then
CntXml=CntXml+1
end if
next

'WScript.Echo "CntXml... " & CntXml

DeletedBackup=""
' If it is greater than the maximum
if CntXml > C_MaxBackupPerFolder then

' Looks for the older entry/file
for each file in folder.files
if lCase(right(file.name,4)) = ".xml" then
if file.DateLastModified < deletedbackup =" lcase(Mid(file.name,1,Instr(1,file.name," filedate =" file.DateLastModified">"" then
for each file in folder.files
if lcase(mid(file.name, 1, len(DeletedBackup)))=DeletedBackup then
Set f = file
f.delete
' WScript.Echo "Deleting..." & file.name
Set f = Nothing
end if
next
end if

end if


Set folder=nothing
Set fso=nothing


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

Dim objShell
Dim strcmd

Set objShell = CreateObject("WScript.Shell")

strcmd = C_SharePointBin & "\stsadm.exe -o backup -url " & C_SiteURL & " -filename " & C_BackupPath & "\" & sBackupPrefix & ".bak -overwrite"

objShell.Exec(strCmd)

WScript.Echo ""& C_SharePointBin & "\stsadm.exe -o backup -url " & C_SiteURL & " -filename " & C_BackupPath & "\" & sBackupPrefix & ".bak -overwrite"

WScript.Echo "Backup of site collection successful"

Set objshell = nothing

Thursday, February 15, 2007

The 'Wow' Starts Now!

I think this ad by Microsoft on the the new Vista is quite inspiring.


Video: Windows Vista "Wow" ad

Wednesday, February 14, 2007

Prescan has encountered sites or lists that were not updated...

I've been in the midst of trying to upgrade my Project Server 2003 instance to 2007. I encountered an error as below when trying to upgrade WSS2.0 (where all the Project Workspace is kept) to WSS3.0:

Prescan has encountered sites or lists that were not updated because they cannot be accessed using the SharePoint Products and Technologies object model. The most likely reasons for Prescan to skip a list are covered in the Knowledge Base article at: http://go.microsoft.com/fwlink/?linkid=69958&clcid=0x409.

I searched high and low, tried everything as suggested in the Knowledge Base article above. Which I then referred to another Knowledge Base article 923904. I did method 1, it returned no orphaned items and I made sure that root has explicit inclusion on the WSS 2.0 site.

So what do you need to do to get prescan.exe to finish SUCCESSFULLY?

  1. Get in touch with your local Microsoft Support and obtain fix KB918743. This is not downloadable, Microsoft will send you an email pointing you to a link that last 7 days.
  2. Run database repair for WSS:

    stsadm.exe -o databaserepair -url http://server/BadSite -databasename ContentDBname -deletecorruption

  3. Detach the Content DB.
  4. Run iisreset.
  5. Reattach the Content DB.
  6. If PreScan still fails than drop and renew a config database. How to recreate the configuration database in Sharepoint 2003.

The reason for all this as explained to me by Ada Pan (Microsoft Online Partner Support) that this problem also may be caused by inconsistence of SharePoint databases (Config- and Content-Database). Prescan is checking Sites, which are listed in the config database This process runs without issues. Later Prescan checks the sites which are defined in the content database(s). Prescan is trying to access these sites via SharePoint Object Model. This step fails, because the site is not in the config database.