Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

STSADM backup script

238 views
Skip to first unread message

Courntey Miles

unread,
Jan 27, 2004, 10:45:11 PM1/27/04
to
I was about to sit down and write a batch file to backup all top level
sites using stsadm and thought I would check if anyone else might have one
already, since I'm not fluent in writing batch files or scripts and it
would take me many hours. Even if you don't have a script to share I'm
interested to hear suggestions. I can't think of how I would extract the
url's from the output of enumsites.

Cheers

Ryan Miller

unread,
Feb 2, 2004, 10:43:45 AM2/2/04
to
That would be cool, but how often will the list of top level sites be
changing? Often enough that it warrants going beyond hard coding them into
the batch script individually?

I don't know that you can actually extract the names using standard batch
commands. You may need a .NET program to either just do the backups or
output the batch script to file. At least the latter option should be
pretty simple to write.

Good Luck,
-Ryan


"Courntey Miles" <c.m...@cqu.edu.au> wrote in message
news:opr2gvdl...@msnews.microsoft.com...

David McKenzie

unread,
Mar 24, 2004, 4:32:24 PM3/24/04
to
Actually the list of top level sites will change hundreds of times a year
here s we create a new team site programaticly which requires (as far as I
could tell) a wildcard inclusion managed path.

So,
Courtney, if you or anyone else has developed such a script I know there are
a handful of interested parties.

David
(who is looking at this along with 5 other coding problems he is really not
qualified to do)

"Ryan Miller" <ry...@nospam.com> wrote in message
news:OasJQOa6...@TK2MSFTNGP11.phx.gbl...

Iyaz

unread,
Mar 25, 2004, 1:07:39 PM3/25/04
to
There will be one which I believe might be out with the resource kit. Dont
have a time frame when the resource kit would be out. If people are
interested I can try and see if I am able to post this site collection
backup tool here or on maybe Mike's FAQ website.
-Iyaz
"David McKenzie" <DavidM...@bonbon.net> wrote in message
news:#o496deE...@TK2MSFTNGP11.phx.gbl...

Mike Walsh [MVP]

unread,
Mar 26, 2004, 1:13:39 AM3/26/04
to
I have no problems with that providing its not so big as to make the site
provider pause for thought.

[But I'd prefer a link to somewhere else if possible as that would fit in
better with the site's 'strategy'.]

Mike Walsh, Helsinki, Finland
WSS FAQ at wss.collutions.com
Please post questions to the newsgroup only.


"Iyaz" <iy...@invalid.msn.com> wrote in message
news:%23AmfWQp...@tk2msftngp13.phx.gbl...

David McKenzie

unread,
Mar 26, 2004, 10:03:22 AM3/26/04
to
PEOPLE ARE INTERESTED
(at least I AM)
There's always MSD2D or gotdotnet as alternative hosting scenareos


"Iyaz" <iy...@invalid.msn.com> wrote in message
news:%23AmfWQp...@tk2msftngp13.phx.gbl...

Iyaz

unread,
Mar 26, 2004, 11:45:49 AM3/26/04
to
I am trying to see if it can be posted somewhere. Will keep you updated once
it is done. Thanks.

-Iyaz
"David McKenzie" <DavidM...@bonbon.net> wrote in message
news:#lg9zN0E...@tk2msftngp13.phx.gbl...

Mike Walsh [MVP]

unread,
Mar 27, 2004, 8:58:17 AM3/27/04
to
In that case preferably gotdotnet so that it's available to all without them
having to register to the site.

(Which is my main objection to MSD2D.)

Mike Walsh, Helsinki, Finland

"David McKenzie" <DavidM...@bonbon.net> wrote in message

news:#lg9zN0E...@tk2msftngp13.phx.gbl...

David McKenzie

unread,
Apr 22, 2004, 11:33:45 AM4/22/04
to
I have not seen anything yet
I *was* looking at a programatic approach, but as far as I could determine I
could only iterate subwebs, and my need it to iterate and backup all sites.

"kvet" <anon...@discussions.microsoft.com> wrote in message
news:777D7730-23C4-41CF...@microsoft.com...
> I am very interested, have any of you created a script?


Iyaz

unread,
Apr 22, 2004, 12:04:23 PM4/22/04
to
I was hoping to get this script on one of the download sites but hitting a
few hurdles. So I guess you have to wait for the resoruce kit to come out
with this script.

-Iyaz
"David McKenzie" <DavidM...@bonbon.net> wrote in message
news:uW7HJ8HK...@TK2MSFTNGP10.phx.gbl...

David McKenzie

unread,
Apr 22, 2004, 2:47:55 PM4/22/04
to
OK
Thanks for your efforts anyways, Iyaz.
Is there a ETA for the Resource Kit?

"David McKenzie" <DavidM...@bonbon.net> wrote in message

news:uW7HJ8HK...@TK2MSFTNGP10.phx.gbl...

Mike Walsh

unread,
Apr 23, 2004, 1:15:04 AM4/23/04
to
> Is there a ETA for the Resource Kit?

It seems to be drifting ...

(Iyaz posted yesterday elsewhere here that he had no date for it)

Mike Walsh, Helsinki, Finland


"David McKenzie" <DavidM...@bonbon.net> wrote in message

news:e3dbpoJK...@TK2MSFTNGP09.phx.gbl...

Jay

unread,
Apr 29, 2004, 8:29:01 AM4/29/04
to
Here is an example that backs up all the top level sites in a farm.
It is a command line utility that generates the backup script (batch
file), executes it and waits for it to finish and logs the results.
It also removes previous copies of backup files.

using System;
using System.IO;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Administration;
using System.Diagnostics;
using System.Threading;

namespace WSSBackupUtility
{
/// <summary>
/// Summary description for WSSBackupUtil.
/// </summary>
class WSSBackupUtil
{
public static bool debugging = false;
private static StreamWriter backupWriter;

public WSSBackupUtil()
{

}

public void generateBatchFile()
{
Console.WriteLine("Generating backup file....");

//Enumerate all the top level sites and back em up!
SPGlobalAdmin globAdmin = new SPGlobalAdmin();
SPVirtualServerCollection vServers = globAdmin.VirtualServers;

foreach (SPVirtualServer vServer in vServers)
{
SPSiteCollection sites = vServer.Sites;
foreach (SPSite site in sites)
{
Console.WriteLine("Adding site: " + site.Url + " to backup
script...");
String backupFileName = site.ServerRelativeUrl;

//remove any leading forward slash
if (backupFileName.StartsWith("/"))
backupFileName = backupFileName.Remove(0, 1);

//make sure that the filename is at least 1 char long --
otherwise it is the root site
if (backupFileName.Length < 1)
backupFileName = "root";

//replace any remaining forward slash's with underscores
backupFileName = backupFileName.Replace("/", "_");

//replace any space's with underscores
backupFileName = backupFileName.Replace(" ", "_");

//replace any & with underscores
backupFileName = backupFileName.Replace("&", "_");

//append the current day to the filename
//backupFileName = backupFileName + "_" + DateTime.Now.DayOfWeek;

//append the .dat suffix to the filename
backupFileName = backupFileName + ".dat";

//make backup in the current directory
backupFileName = "./" + backupFileName;

//write out the line to the backup file
backupWriter.WriteLine("stsadm.exe -o backup -url \""+ site.Url
+"\" -filename "+ backupFileName +" -overwrite");
}
}

Console.WriteLine("Generating backup file complete!");
}

public void redirectConsoleToFile()
{
//set the console out to a text file
FileStream outFileStream =
File.Create("./WSSBackupUtilityLog.txt");
StreamWriter outWriter = new StreamWriter(outFileStream);
Console.SetOut(outWriter);
}

public void flushAndCloseConsoleWriter()
{
//flush and close the log file writer the console is using
Console.Out.Flush();
Console.Out.Close();
}

public void initializeBatchFile()
{
//create the backup.bat file based on the current top level sites
FileStream backupFileStream = File.Create("./custom_backup.bat");
backupWriter = new StreamWriter(backupFileStream);
backupWriter.WriteLine("echo off");
backupWriter.WriteLine("rem This file was automatically generated
at " + DateTime.Now);
backupWriter.WriteLine("rem For questions contact
jc...@adelphia.net");
backupWriter.WriteLine("echo on");
backupWriter.WriteLine("SET PATH=C:\\Program files\\common
files\\microsoft shared\\web server extensions\\60\\bin");
}

public void flushAndCloseBatchFile()
{
//flush and close the backup file writer
backupWriter.Flush();
backupWriter.Close();
}

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
WSSBackupUtil backupUtil = new WSSBackupUtil();

//if not debugging redirect console to file
if (!debugging)
backupUtil.redirectConsoleToFile();

//init the batch file
backupUtil.initializeBatchFile();

backupUtil.generateBatchFile();

//flush and close the batch file
backupUtil.flushAndCloseBatchFile();

//delete all the .dat files that currently exist
string[] filenames = Directory.GetFiles("./", "*.dat");
foreach (string filename in filenames)
{
Console.WriteLine("Removing previous backup file: " +
filename);
new FileInfo(filename).Delete();
}

//execute the batch file
Console.WriteLine("Executing backup script...");
Process backupProcess = Process.Start("./custom_backup.bat");

//wait until the batch file completes
while (!backupProcess.HasExited)
{
Console.WriteLine("Waiting for backup script to complete...");
Thread.Sleep(10000);
}

Console.WriteLine("Backup script execution complete -- cleaning up
and shutting down...");

//if not debugging clean up redirecting console to file
if (!debugging)
backupUtil.flushAndCloseConsoleWriter();

//if we are debugging give the user a chance to read what is in the
command window...
if (debugging)
{
Console.WriteLine("Press carriage return to continue...");
Console.ReadLine();
}

}
}
}


"Mike Walsh" <englant...@hotmail.com> wrote in message news:<OYQhzHP...@TK2MSFTNGP11.phx.gbl>...

Mike Walsh

unread,
Apr 30, 2004, 12:55:11 AM4/30/04
to
Stupid question I know, but if I copied this text into a file to be used on
the command line, what file name (after the . !) would I give it ?

Mike Walsh, Helsinki, Finland

"Jay" <jc...@adelphia.net> wrote in message
news:7f41faac.04042...@posting.google.com...

Jay

unread,
Apr 30, 2004, 1:06:47 PM4/30/04
to
Hi Mike,

I didn't even think to mention that... sorry. It is a C# class --
you would need to create a new C# command line application project in
Visual Studio and compile the code into an executable. Then the
executable can be set up to run as a scheduled task (or run directly
from the command line or by double clicking on the executable) and it
automates the whole backup process. This just gives you the code you
need, but you still need to create the project and compile it to get
something you can execute.

--Jay


"Mike Walsh" <englant...@hotmail.com> wrote in message news:<em0sV9m...@tk2msftngp13.phx.gbl>...

Mike Walsh

unread,
Apr 30, 2004, 2:05:31 PM4/30/04
to
Thanks, Jay. I really must get round to actually doing more with Visual
Studio than just installing it.

Mike Walsh, Helsinki, Finland


"Jay" <jc...@adelphia.net> wrote in message

news:7f41faac.04043...@posting.google.com...

David McKenzie

unread,
May 5, 2004, 4:18:37 PM5/5/04
to
Jay

you rock!

very minor tweaking makes this EXACTLY what I wanted
then just drop it in the scheduled tasks and kick a tape backup a little
later

all hail Jay!


"Jay" <jc...@adelphia.net> wrote in message
news:7f41faac.04042...@posting.google.com...

partha

unread,
May 18, 2004, 5:46:27 PM5/18/04
to
Hi

The Script looks very good but when iam trying to debug the console
app in the vs.net iam getting message "An unhandled exception of type
'Microsoft.SharePoint.SPException' occurred in
microsoft.sharepoint.dll"
please help me.
Thanks to Jay all the great people in this group.

Thanks and Regards

Parth


"David McKenzie" <DavidM...@bonbon.net> wrote in message news:<OZMAn4tM...@TK2MSFTNGP11.phx.gbl>...

Chamiak@discussions.microsoft.com Jason Chamiak

unread,
Jul 23, 2004, 11:50:01 AM7/23/04
to
Here is a vbscript I created. It works great for me.

'###############################################################################################
'# This script runs the stsadm enumsites operation and captures the output in a temp file. The #
'# URL is the only data left after the string manipulation which is then writen to a newly #
'# created text file. This script was created by Jason Chamiak. #
'###############################################################################################

Option Explicit

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Dim objFSO
Dim objShell
Dim objName
Dim objTempFile
Dim objTextFile
Dim strText
Dim intTextLines
Dim objFile
Dim objFile1
Dim strTextFileLocation
Dim intTextLength
Dim intWriteLineLength
Dim strWriteLineTextStart
Dim strWriteLineTextFinal
Dim intChrPosition

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("Wscript.Shell")

objName = objFSO.GetTempName
objTempFile = objName
intTextLines = 0
strTextFileLocation = "C:\Documents and Settings\Administrator\Desktop\Enumsites.txt"

objShell.Run "cmd /c STSADM.exe -o enumsites -url http://mppsps >" & objTempFile, 0, True

Set objTextFile = objFSO.OpenTextFile(objTempFile, 1)
Set objFile = objFSO.CreateTextFile(strTextFileLocation)
objFile.Close

Do While objTextFile.AtEndOfStream <> True
strText = objTextFile.ReadLine
If InStr(strText, "http") Then
intTextLength = Len(Mid(Trim(strText),12,99))
intWriteLineLength = intTextLength - 4
strWriteLineTextStart = Mid(Trim(strText),12,99)
intChrPosition = InStr(1,strWriteLineTextStart,Chr(34)) - 1
strWriteLineTextFinal = Mid(Trim(strText),12,intChrPosition)
End If
Set objFile = objFSO.OpenTextFile(strTextFileLocation, ForAppending)
If InStr(strText, "http") Then
objFile.WriteLine(strWriteLineTextFinal)
End If
objFile.Close
Loop

objTextFile.Close
objFSO.DeleteFile(objTempFile)

'############################################################################################
'# This portion of the script reads the Site URLs from the text file created from the above #
'# code and inputs each URL into an array. The last portion of the URL string in each array #
'# index is extracted to a variable. The full URL variable and the extracted portion of the #
'# URL are used to populate the stsadm -url and -filename options. The stsadm command is #
'# run for each site stated in the text file and a backup file name containing the last #
'# portion of the URL is created. #
'############################################################################################

Dim arrSiteCollection()
Dim strLineText
Dim intSize
Dim strCmdRun
Dim strBackupLocation

Set objFile = objFSO.OpenTextFile(strTextFileLocation, ForReading)
intSize = 0
strBackupLocation = "E:\Backup\"

Do While objFile.AtEndOfStream <> True
strText = objFile.ReadLine

ReDim Preserve arrSiteCollection(intSize)
arrSiteCollection(intSize) = strText

intTextLength = Len(strText)
intChrPosition = InStrRev(strText,Chr(47)) + 1
strWriteLineTextFinal = Mid(strText,intChrPosition,99)

strCmdRun = "stsadm.exe -o backup -url " & arrSiteCollection(intSize) & " -filename " & _
strBackupLocation & strWriteLineTextFinal
objShell.Run "cmd /c" & strCmdRun

intSize = intSize + 1
Loop

0 new messages