public void BackupFarm(SPFarm farm, bool prepare) { if (prepare) PrepareSystem(); if (_includeIis) { // Export the IIS settings. string iisBakPath = Path.Combine(_path, "iis_full.bak"); if (_overwrite && File.Exists(iisBakPath)) File.Delete(iisBakPath); if (!_overwrite && File.Exists(iisBakPath)) throw new SPException( string.Format("The IIS backup file '{0}' already exists - specify '-overwrite' to replace the file.", iisBakPath)); //Utilities.RunCommand("cscript", string.Format("{0}\\iiscnfg.vbs /export /f \"{1}\" /inherited /children /sp /lm", Environment.SystemDirectory, iisBakPath), false); using (DirectoryEntry de = new DirectoryEntry("IIS://localhost")) { Logger.Write("Exporting full IIS settings...."); string decryptionPwd = string.Empty; de.Invoke("Export", new object[] { decryptionPwd, iisBakPath, "/lm", FLAG_EXPORT_INHERITED_SETTINGS }); } } SPEnumerator enumerator = new SPEnumerator(farm); InitiateEnumerator(enumerator); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; Logger.Verbose = true; string scope = Params["scope"].Value.ToLowerInvariant(); SPFarm farm = SPFarm.Local; SPWebService webService = farm.Services.GetValue<SPWebService>(""); m_quotaColl = webService.QuotaTemplates; m_setQuota = Params["setquota"].UserTypedIn; if (Params["quota"].UserTypedIn) { m_quota = m_quotaColl[Params["quota"].Value]; if (m_quota == null) throw new ArgumentException("The specified quota template name could not be found."); } SPEnumerator enumerator; if (scope == "farm") { enumerator = new SPEnumerator(SPFarm.Local); } else if (scope == "webapplication") { enumerator = new SPEnumerator(SPWebApplication.Lookup(new Uri(Params["url"].Value.TrimEnd('/')))); } else { // scope == "site" using (SPSite site = new SPSite(Params["url"].Value.TrimEnd('/'))) { Sync(site); } return (int)ErrorCodes.NoError; } enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated; enumerator.Enumerate(); return (int)ErrorCodes.NoError; }
/// <summary> /// Handles the SPWebApplicationEnumerated event of the enumerator control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Lapointe.SharePoint.STSADM.Commands.OperationHelpers.SPEnumerator.SPWebApplicationEventArgs"/> instance containing the event data.</param> private void OnSPWebApplicationEnumerated(object sender, SPEnumerator.SPWebApplicationEventArgs e) { if (!_includeIis) return; foreach (SPIisSettings iis in e.WebApplication.IisSettings.Values) { string iisBakPath = Path.Combine(_path, string.Format("iis_w3svc_{0}.bak", iis.PreferredInstanceId)); if (_overwrite && File.Exists(iisBakPath)) File.Delete(iisBakPath); if (!_overwrite && File.Exists(iisBakPath)) throw new SPException(string.Format("The IIS backup file '{0}' already exists - specify '-overwrite' to replace the file.", iisBakPath)); //Utilities.RunCommand( // "cscript", // string.Format("{0}\\iiscnfg.vbs /export /f \"{1}\" /inherited /children /sp /lm/w3svc/{2}", // Environment.SystemDirectory, // iisBakPath, // iis.PreferredInstanceId), // false); using (DirectoryEntry de = new DirectoryEntry("IIS://localhost")) { Logger.Write("Exporting IIS settings for web application '{0}'....", iis.ServerComment); string decryptionPwd = string.Empty; string path = string.Format("/lm/w3svc/{0}", iis.PreferredInstanceId); de.Invoke("Export", new object[] { decryptionPwd, iisBakPath, path, FLAG_EXPORT_INHERITED_SETTINGS }); } } }
/// <summary> /// Handles the SPSiteEnumerated event of the enumerator control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Lapointe.SharePoint.STSADM.Commands.OperationHelpers.SPEnumerator.SPSiteEventArgs"/> instance containing the event data.</param> private void OnSPSiteEnumerated(object sender, SPEnumerator.SPSiteEventArgs e) { BackupSiteCore(e.Site); }
private void InitiateEnumerator(SPEnumerator enumerator) { if (enumerator != null) { // Listen for web application events so that we can export the settings for the specified application. enumerator.SPWebApplicationEnumerated += new SPEnumerator.SPWebApplicationEnumeratedEventHandler(OnSPWebApplicationEnumerated); enumerator.SPSiteEnumerated += new SPEnumerator.SPSiteEnumeratedEventHandler(OnSPSiteEnumerated); enumerator.Enumerate(); } }
public void BackupWebApplication(List<SPWebApplication> webApps, bool prepare) { if (prepare) PrepareSystem(); foreach (SPWebApplication webApp in webApps) { SPEnumerator enumerator = new SPEnumerator(webApp); InitiateEnumerator(enumerator); } }
public void BackupWebApplication(SPWebApplication webApp, bool prepare) { if (prepare) PrepareSystem(); SPEnumerator enumerator = new SPEnumerator(webApp); InitiateEnumerator(enumerator); }
/// <summary> /// Handles the SPWebEnumerated event of the enumerator control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Lapointe.SharePoint.STSADM.Commands.OperationHelpers.SPEnumerator.SPWebEventArgs"/> instance containing the event data.</param> private void enumerator_SPWebEnumerated(object sender, SPEnumerator.SPWebEventArgs e) { ActivateDeactivateFeatureAtWeb(e.Site, e.Web, m_Activate, m_FeatureId, m_Force, m_IgnoreNonActive); }
/// <summary> /// Handles the SPWebApplicationEnumerated event of the enumerator control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Lapointe.SharePoint.STSADM.Commands.OperationHelpers.SPEnumerator.SPWebApplicationEventArgs"/> instance containing the event data.</param> private void enumerator_SPWebApplicationEnumerated(object sender, SPEnumerator.SPWebApplicationEventArgs e) { ActivateDeactivateFeatureAtWebApplication(e.WebApplication, m_FeatureId, m_Activate, m_Force, m_IgnoreNonActive); }
internal void ActivateDeactivateFeatureAtScope(SPFeatureDefinition feature, ActivationScope scope, bool activate, string url, bool force, bool ignoreNonActive) { m_IgnoreNonActive = ignoreNonActive; m_Activate = activate; m_Force = force; m_Url = url; m_FeatureId = feature.Id; if (feature.Scope == SPFeatureScope.Farm) { if (scope != ActivationScope.Farm) throw new SPSyntaxException("The Feature specified is scoped to the Farm. The -scope parameter must be \"Farm\"."); ActivateDeactivateFeatureAtFarm(activate, m_FeatureId, m_Force, m_IgnoreNonActive); } else if (feature.Scope == SPFeatureScope.WebApplication) { if (scope != ActivationScope.Farm && scope != ActivationScope.WebApplication) throw new SPSyntaxException("The Feature specified is scoped to the Web Application. The -scope parameter must be either \"Farm\" or \"WebApplication\"."); if (scope == ActivationScope.Farm) { SPEnumerator enumerator = new SPEnumerator(SPFarm.Local); enumerator.SPWebApplicationEnumerated += enumerator_SPWebApplicationEnumerated; enumerator.Enumerate(); } else { if (string.IsNullOrEmpty(m_Url)) throw new SPSyntaxException("The -url parameter is required if the scope is \"WebApplication\"."); SPWebApplication webApp = SPWebApplication.Lookup(new Uri(m_Url)); ActivateDeactivateFeatureAtWebApplication(webApp, m_FeatureId, activate, m_Force, m_IgnoreNonActive); } } else if (feature.Scope == SPFeatureScope.Site) { if (scope == ActivationScope.Web) throw new SPSyntaxException("The Feature specified is scoped to Site. The -scope parameter cannot be \"Web\"."); SPSite site = null; SPEnumerator enumerator = null; try { if (scope == ActivationScope.Farm) enumerator = new SPEnumerator(SPFarm.Local); else if (scope == ActivationScope.WebApplication) { SPWebApplication webApp = SPWebApplication.Lookup(new Uri(m_Url)); enumerator = new SPEnumerator(webApp); } else if (scope == ActivationScope.Site) { site = new SPSite(m_Url); ActivateDeactivateFeatureAtSite(site, activate, m_FeatureId, m_Force, m_IgnoreNonActive); } if (enumerator != null) { enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated; enumerator.Enumerate(); } } finally { if (site != null) site.Dispose(); } } else if (feature.Scope == SPFeatureScope.Web) { SPSite site = null; SPWeb web = null; SPEnumerator enumerator = null; try { if (scope == ActivationScope.Farm) enumerator = new SPEnumerator(SPFarm.Local); else if (scope == ActivationScope.WebApplication) { SPWebApplication webApp = SPWebApplication.Lookup(new Uri(m_Url)); enumerator = new SPEnumerator(webApp); } else if (scope == ActivationScope.Site) { site = new SPSite(m_Url); enumerator = new SPEnumerator(site); } else if (scope == ActivationScope.Web) { site = new SPSite(m_Url); web = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(m_Url)]; enumerator = new SPEnumerator(web); } if (enumerator != null) { enumerator.SPWebEnumerated += enumerator_SPWebEnumerated; enumerator.Enumerate(); } } finally { if (web != null) web.Dispose(); if (site != null) site.Dispose(); } } }
/// <summary> /// Handles the SPSiteEnumerated event of the enumerator control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Lapointe.SharePoint.STSADM.Commands.OperationHelpers.SPEnumerator.SPSiteEventArgs"/> instance containing the event data.</param> private void enumerator_SPSiteEnumerated(object sender, SPEnumerator.SPSiteEventArgs e) { Sync(e.Site); }