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.
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.mi...@cqu.edu.au> wrote in message
> 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.
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)
> 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.mi...@cqu.edu.au> wrote in message > news:opr2gvdlwiv7738b@msnews.microsoft.com... > > 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.
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" <DavidMcKen...@bonbon.net> wrote in message
> 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" <r...@nospam.com> wrote in message > news:OasJQOa6DHA.3548@TK2MSFTNGP11.phx.gbl... > > 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.mi...@cqu.edu.au> wrote in message > > news:opr2gvdlwiv7738b@msnews.microsoft.com... > > > 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.
> 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" <DavidMcKen...@bonbon.net> wrote in message > news:#o496deEEHA.576@TK2MSFTNGP11.phx.gbl... > > 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" <r...@nospam.com> wrote in message > > news:OasJQOa6DHA.3548@TK2MSFTNGP11.phx.gbl... > > > 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.mi...@cqu.edu.au> wrote in message > > > news:opr2gvdlwiv7738b@msnews.microsoft.com... > > > > 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.
> 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" <DavidMcKen...@bonbon.net> wrote in message > news:#o496deEEHA.576@TK2MSFTNGP11.phx.gbl... > > 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" <r...@nospam.com> wrote in message > > news:OasJQOa6DHA.3548@TK2MSFTNGP11.phx.gbl... > > > 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.mi...@cqu.edu.au> wrote in message > > > news:opr2gvdlwiv7738b@msnews.microsoft.com... > > > > 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.
> PEOPLE ARE INTERESTED > (at least I AM) > There's always MSD2D or gotdotnet as alternative hosting scenareos
> "Iyaz" <i...@invalid.msn.com> wrote in message > news:%23AmfWQpEEHA.3576@tk2msftngp13.phx.gbl... > > 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" <DavidMcKen...@bonbon.net> wrote in message > > news:#o496deEEHA.576@TK2MSFTNGP11.phx.gbl... > > > 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" <r...@nospam.com> wrote in message > > > news:OasJQOa6DHA.3548@TK2MSFTNGP11.phx.gbl... > > > > 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.mi...@cqu.edu.au> wrote in message > > > > news:opr2gvdlwiv7738b@msnews.microsoft.com... > > > > > 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.
> PEOPLE ARE INTERESTED > (at least I AM) > There's always MSD2D or gotdotnet as alternative hosting scenareos
> "Iyaz" <i...@invalid.msn.com> wrote in message > news:%23AmfWQpEEHA.3576@tk2msftngp13.phx.gbl... > > 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" <DavidMcKen...@bonbon.net> wrote in message > > news:#o496deEEHA.576@TK2MSFTNGP11.phx.gbl... > > > 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" <r...@nospam.com> wrote in message > > > news:OasJQOa6DHA.3548@TK2MSFTNGP11.phx.gbl... > > > > 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.mi...@cqu.edu.au> wrote in message > > > > news:opr2gvdlwiv7738b@msnews.microsoft.com... > > > > > 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.
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" <anonym...@discussions.microsoft.com> wrote in message
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" <DavidMcKen...@bonbon.net> wrote in message
> 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.
> 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.
> OK > Thanks for your efforts anyways, Iyaz. > Is there a ETA for the Resource Kit?
> "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > news:uW7HJ8HKEHA.3304@TK2MSFTNGP10.phx.gbl... > > 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.
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"); } }
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(); }
> (Iyaz posted yesterday elsewhere here that he had no date for it)
> Mike Walsh, Helsinki, Finland
> "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > news:e3dbpoJKEHA.1156@TK2MSFTNGP09.phx.gbl... > > OK > > Thanks for your efforts anyways, Iyaz. > > Is there a ETA for the Resource Kit?
> > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > news:uW7HJ8HKEHA.3304@TK2MSFTNGP10.phx.gbl... > > > 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.
> 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;
> 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"); > } > }
> 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" <englantilai...@hotmail.com> wrote in message
> > (Iyaz posted yesterday elsewhere here that he had no date for it)
> > Mike Walsh, Helsinki, Finland
> > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > news:e3dbpoJKEHA.1156@TK2MSFTNGP09.phx.gbl... > > > OK > > > Thanks for your efforts anyways, Iyaz. > > > Is there a ETA for the Resource Kit?
> > > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > > news:uW7HJ8HKEHA.3304@TK2MSFTNGP10.phx.gbl... > > > > 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.
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.
"Mike Walsh" <englantilai...@hotmail.com> wrote in message <news:em0sV9mLEHA.808@tk2msftngp13.phx.gbl>... > 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.0404290429.3cda6e64@posting.google.com... > > 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;
> > //Enumerate all the top level sites and back em up! > > SPGlobalAdmin globAdmin = new SPGlobalAdmin(); > > SPVirtualServerCollection vServers = globAdmin.VirtualServers;
> > //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"); > > } > > }
> > 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(); > > }
> > > (Iyaz posted yesterday elsewhere here that he had no date for it)
> > > Mike Walsh, Helsinki, Finland
> > > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > > news:e3dbpoJKEHA.1156@TK2MSFTNGP09.phx.gbl... > > > > OK > > > > Thanks for your efforts anyways, Iyaz. > > > > Is there a ETA for the Resource Kit?
> > > > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > > > news:uW7HJ8HKEHA.3304@TK2MSFTNGP10.phx.gbl... > > > > > 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.
> 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" <englantilai...@hotmail.com> wrote in message
> > 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.0404290429.3cda6e64@posting.google.com... > > > 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;
> > > //Enumerate all the top level sites and back em up! > > > SPGlobalAdmin globAdmin = new SPGlobalAdmin(); > > > SPVirtualServerCollection vServers = globAdmin.VirtualServers;
> > > //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"); > > > } > > > }
> > > //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(); > > > }
> > > > (Iyaz posted yesterday elsewhere here that he had no date for it)
> > > > Mike Walsh, Helsinki, Finland
> > > > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > > > news:e3dbpoJKEHA.1156@TK2MSFTNGP09.phx.gbl... > > > > > OK > > > > > Thanks for your efforts anyways, Iyaz. > > > > > Is there a ETA for the Resource Kit?
> > > > > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > > > > news:uW7HJ8HKEHA.3304@TK2MSFTNGP10.phx.gbl... > > > > > > 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.
> 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;
> 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"); > } > }
> 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" <englantilai...@hotmail.com> wrote in message
> > (Iyaz posted yesterday elsewhere here that he had no date for it)
> > Mike Walsh, Helsinki, Finland
> > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > news:e3dbpoJKEHA.1156@TK2MSFTNGP09.phx.gbl... > > > OK > > > Thanks for your efforts anyways, Iyaz. > > > Is there a ETA for the Resource Kit?
> > > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > > news:uW7HJ8HKEHA.3304@TK2MSFTNGP10.phx.gbl... > > > > 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.
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.
> 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.0404290429.3cda6e64@posting.google.com... > > 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;
> > //Enumerate all the top level sites and back em up! > > SPGlobalAdmin globAdmin = new SPGlobalAdmin(); > > SPVirtualServerCollection vServers = globAdmin.VirtualServers;
> > //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"); > > } > > }
> > 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(); > > }
> > > (Iyaz posted yesterday elsewhere here that he had no date for it)
> > > Mike Walsh, Helsinki, Finland
> > > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > > news:e3dbpoJKEHA.1156@TK2MSFTNGP09.phx.gbl... > > > > OK > > > > Thanks for your efforts anyways, Iyaz. > > > > Is there a ETA for the Resource Kit?
> > > > "David McKenzie" <DavidMcKen...@bonbon.net> wrote in message > > > > news:uW7HJ8HKEHA.3304@TK2MSFTNGP10.phx.gbl... > > > > > 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.
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. # '########################################################################## #####################
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")
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
"Courntey Miles" wrote: > 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.