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

SharePoint Backup

By , 25 Jul 2007
 

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
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralWorks great!memberbvermilion9 Jan '09 - 5:34 
General[Message Removed]memberstonber5 Oct '08 - 7:10 
GeneralThanks. Great help! I added it to www.sharepoint-tools.dememberdknyoli17 Jun '08 - 2:34 
Generalgetting error....memberAdityaBhanu29 Aug '07 - 0:54 
GeneralRe: getting error....memberSimon Bonello29 Aug '07 - 1:42 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 25 Jul 2007
Article Copyright 2007 by Simon Bonello
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid