Click here to Skip to main content
Click here to Skip to main content

SharePoint Backup

, 25 Jul 2007
Rate this:
Please Sign up or sign in to vote.
A SharePoint backup utility.

Introduction

Typically, SharePoint backup is performed using the stsadm utility. Unfortunately, after setting up STSADM.exe to backup a SharePoint site, the backup directory will keep growing daily. The SPBackup utility eliminates the manual weekly task of removing old backups. It eliminating old backups from the file system and removes the backup references from the history log file (spbrtoc.xml).

Using the code

The utility performs a backup by calling the stsadm utility.

rFilename = rbinFolder + @"\stsadm.exe";
rArguments = "-o backup -directory " + rDirectory + " -backupmethod full";
Process proc = Process.Start(rFilename, rArguments);
proc.WaitForExit();

After the backup is complete, the utility parses the spbrotoc.xml file to determine the number of backups present in the backup folder. If the number exceeds a defined maximum limit (which is passed as a command line argument), the old backups are removed from the file system and the history log (spbrtoc.xml) is updated.

string rHistoryFile = rDirectory + @"\" + "spbrtoc.xml";
XmlDocument doc = new XmlDocument();
doc.Load(rHistoryFile);XmlNodeList nodelist = 
    doc.SelectNodes("/SPBackupRestoreHistory/SPHistoryObject");

if (nodelist.Count > nMaxBackups)
{
    XmlNode node = doc.SelectSingleNode("/SPBackupRestoreHistory");
    while (node.ChildNodes.Count != nMaxBackups)
    {
        XmlNode Directorynode = node.LastChild.SelectSingleNode("SPDirectoryName");
        // Delete folder 
        Directory.Delete(rDirectory + @"\" + Directorynode.InnerXml, true);
        node.RemoveChild(node.LastChild);
    }
}
doc.Save(rHistoryFile);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Simon Bonello
Architect
Malta Malta
No Biography provided

Comments and Discussions

 
GeneralWorks great! Pinmemberbvermilion9-Jan-09 5:34 
General[Message Removed] Pinmemberstonber5-Oct-08 7:10 
GeneralThanks. Great help! I added it to www.sharepoint-tools.de Pinmemberdknyoli17-Jun-08 2:34 
http://www.sharepoint-tools.de/42/Sharepoint_Backup_Tool.html[^]
Big Grin | :-D
Generalgetting error.... PinmemberAdityaBhanu29-Aug-07 0:54 
GeneralRe: getting error.... PinmemberSimon Bonello29-Aug-07 1:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 25 Jul 2007
Article Copyright 2007 by Simon Bonello
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid