SharePoint Backup
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.
Hide Copy Code
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.
Hide Copy Code
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);
No comments:
Post a Comment