public override void Run() { using (VssClient client = new VssClient(Host)) { if (HasOption(OptAll)) { Host.WriteWarning("This will delete all shadow copies on the system."); if (!Host.ShouldContinue()) return; } client.Initialize(VssSnapshotContext.All); if (SnapshotID.HasValue) { Host.WriteLine("Delete the snapshot with id {0:B}", SnapshotID.Value); client.DeleteSnapshot(SnapshotID.Value); } else if (SnapshotSetID.HasValue) { Host.WriteLine("Delete the snapshot set with id {0:B}", SnapshotSetID.Value); client.DeleteSnapshotSet(SnapshotSetID.Value); } else if (HasOption(OptAll)) { client.DeleteAllSnapshots(); } else { string volume = GetOptionValue<string>(OptOldest); Host.WriteLine("Delete the oldest snapshot for volume {0}", volume); client.DeleteOldestSnapshot(volume); } } }
public override void Run() { using (VssClient client = new VssClient(Host)) { client.Initialize(VssSnapshotContext.All); client.RevertToSnapshot(GetOptionValue<Guid>(OptSnapshotID)); } }
public override void Run() { UpdateFinalContext(); using (VssClient client = new VssClient(Host)) { client.Initialize(Context); client.GatherWriterMetadata(); client.GatherWriterStatus(); client.ListWriterStatus(); } }
public override void Run() { using (VssClient client = new VssClient(Host)) { client.Initialize(VssSnapshotContext.All); if (HasValue(OptMountPoint)) client.ExposeShapshotLocally(SnapshotId, GetOptionValue<string>(OptMountPoint)); else client.ExposeSnapshotRemotely(SnapshotId, GetOptionValue<string>(OptShare), HasOption(OptDir) ? GetOptionValue<string>(OptDir) : null); } }
public override void Run() { using (VssClient client = new VssClient(Host)) { client.Initialize(VssSnapshotContext.All, null, false); if (SnapshotID.HasValue) client.GetSnapshotProperties(SnapshotID.Value); else client.QuerySnapshotSet(SnapdhotSetID.HasValue ? SnapdhotSetID.Value : Guid.Empty); } }
public override void Run() { using (VssClient client = new VssClient(Host)) { client.Initialize(VssSnapshotContext.All); if (HasValue(OptMountPoint)) { client.ExposeShapshotLocally(SnapshotId, GetOptionValue <string>(OptMountPoint)); } else { client.ExposeSnapshotRemotely(SnapshotId, GetOptionValue <string>(OptShare), HasOption(OptDir) ? GetOptionValue <string>(OptDir) : null); } } }
public override void Run() { UpdateFinalContext(); using (VssClient client = new VssClient(Host)) { client.Initialize(Context); if (HasOption(OptXml)) { client.GatherWriterMetadataToScreen(); } else { client.GatherWriterMetadata(); client.ListWriterMetadata(HasOption(OptDetailed)); } } }
public static async Task <int> Main(string[] args) { // Redirect ILogger to Console ILogger logger = Program.RedirectLoggerToConsole(); // Parse command line CommandOptions parsedOptions = Program.ParseArguments(args); if (parsedOptions == null) { return(-1); } // Get Personal Access Token from command line or environment variable string personalAccessToken = parsedOptions.PersonalAccessToken; if (string.IsNullOrEmpty(personalAccessToken)) { personalAccessToken = Environment.GetEnvironmentVariable("VssPersonalAccessToken"); } // Get Sql Server connection string from command line or environment variable string sqlServerConnectionString = string.IsNullOrEmpty(parsedOptions.SqlServerConnectionString) ? Environment.GetEnvironmentVariable("VssSqlServerConnectionString") : parsedOptions.SqlServerConnectionString; // Create Azure DevOps HttpClient VssClient vssClient; if (string.IsNullOrEmpty(personalAccessToken)) { // Connect using current signed in domain user string bearerToken = await VssClientHelper.GetAzureDevOpsBearerTokenForCurrentUserAsync(); vssClient = new VssClient(parsedOptions.Organization, bearerToken, VssTokenType.Bearer, logger); } else { // Connect using personal access token vssClient = new VssClient(parsedOptions.Organization, personalAccessToken, VssTokenType.Basic, logger); } // Run collector await Program.RunCollectorAsync(parsedOptions, vssClient, sqlServerConnectionString, logger); // Returns zero on success return(0); }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public override async Task RunAsync() #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { using (VssClient client = new VssClient(Host)) { client.Initialize(VssSnapshotContext.All, null, false); if (SnapshotID.HasValue) { client.GetSnapshotProperties(SnapshotID.Value); } else { client.QuerySnapshotSet(SnapdhotSetID.HasValue ? SnapdhotSetID.Value : Guid.Empty); } } }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public override async Task RunAsync() #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { using (VssClient client = new VssClient(Host)) { client.Initialize(VssSnapshotContext.All); if (HasValue(OptMountPoint)) { client.ExposeShapshotLocally(SnapshotId, GetOptionValue <string>(OptMountPoint)); } else { client.ExposeSnapshotRemotely(SnapshotId, GetOptionValue <string>(OptShare), HasOption(OptDir) ? GetOptionValue <string>(OptDir) : null); } } }
public void DoPruning(VssClient vss) { lock (_lockProcessing) { CleanupGhostInstances(vss); IEnumerable <SnapshotInstance> pruneList = GetPruningList(); foreach (SnapshotInstance instance in pruneList) { vss.DeleteSnapshot(instance.SnapshotId); } CleanupInstances(pruneList.Select(i => i.SnapshotId)); Save(); } }
public override async Task RunAsync() { UpdateFinalContext(); using (VssClient client = new VssClient(Host)) { client.Initialize(Context); if (HasOption(OptXml)) { await client.GatherWriterMetadataToScreenAsync().ConfigureAwait(false); } else { await client.GatherWriterMetadataAsync().ConfigureAwait(false); client.ListWriterMetadata(HasOption(OptDetailed)); } } }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public override async Task RunAsync() #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { using (VssClient client = new VssClient(Host)) { if (HasOption(OptAll)) { Host.WriteWarning("This will delete all shadow copies on the system."); if (!Host.ShouldContinue()) { return; } } client.Initialize(VssSnapshotContext.All); if (SnapshotID.HasValue) { Host.WriteLine("Delete the snapshot with id {0:B}", SnapshotID.Value); client.DeleteSnapshot(SnapshotID.Value); } else if (SnapshotSetID.HasValue) { Host.WriteLine("Delete the snapshot set with id {0:B}", SnapshotSetID.Value); client.DeleteSnapshotSet(SnapshotSetID.Value); } else if (HasOption(OptAll)) { client.DeleteAllSnapshots(); } else { string volume = GetOptionValue <string>(OptOldest); Host.WriteLine("Delete the oldest snapshot for volume {0}", volume); client.DeleteOldestSnapshot(volume); } } }
public override void Run() { Host.WriteLine("Importing shadow copy set from file '{0}'", XmlDocFile); string xmlDoc = File.ReadAllText(XmlDocFile); Host.WriteVerbose("XML document:\n{0}", xmlDoc); using (VssClient client = new VssClient(Host)) { client.Initialize(VssSnapshotContext.All, xmlDoc); client.ImportSnapshotSet(); if (HasValue(OptExecCommand)) { string arguments = String.Empty; if (HasOption(CommonOptions.OptExecCommandArgs)) { arguments = GetOptionValue <string>(CommonOptions.OptExecCommandArgs); } Host.ExecCommand(GetOptionValue <string>(OptExecCommand), arguments); } } }
public override void Run() { Host.WriteLine("Importing shadow copy set from file '{0}'", XmlDocFile); string xmlDoc = File.ReadAllText(XmlDocFile); Host.WriteVerbose("XML document:\n{0}", xmlDoc); using (VssClient client = new VssClient(Host)) { client.Initialize(VssSnapshotContext.All, xmlDoc); client.ImportSnapshotSet(); if (HasValue(OptExecCommand)) { string arguments = String.Empty; if (HasOption(CommonOptions.OptExecCommandArgs)) { arguments = GetOptionValue<string>(CommonOptions.OptExecCommandArgs); } Host.ExecCommand(GetOptionValue<string>(OptExecCommand), arguments); } } }
public override void Run() { using (VssClient client = new VssClient(Host)) { if (HasOption(OptAll)) { Host.WriteWarning("This will delete all shadow copies on the system."); if (!Host.ShouldContinue()) { return; } } client.Initialize(VssSnapshotContext.All); if (SnapshotID.HasValue) { Host.WriteLine("Delete the snapshot with id {0:B}", SnapshotID.Value); client.DeleteSnapshot(SnapshotID.Value); } else if (SnapshotSetID.HasValue) { Host.WriteLine("Delete the snapshot set with id {0:B}", SnapshotSetID.Value); client.DeleteSnapshotSet(SnapshotSetID.Value); } else if (HasOption(OptAll)) { client.DeleteAllSnapshots(); } else { string volume = GetOptionValue <string>(OptOldest); Host.WriteLine("Delete the oldest snapshot for volume {0}", volume); client.DeleteOldestSnapshot(volume); } } }
public override void Run() { Host.WriteLine("Performing a{0} restore", Simulate ? " simulated" : ""); string xmlDoc = File.ReadAllText(FileName); Host.WriteVerbose("XML Document:\n{0}", xmlDoc); using (VssClient client = new VssClient(Host)) { // Initialize the VSS client client.Initialize(VssSnapshotContext.All, xmlDoc, true); // Gather writer metadata client.GatherWriterMetadata(); // Gather writer status client.GatherWriterStatus(); // List writer status client.ListWriterStatus(); // Initialize the list of writers and components for restore client.InitializeWriterComponentsForRestore(); // Select required components for restore client.SelectComponentsForRestore(ExcludedWriters.ToList(), IncludedWriters.ToList()); if (Simulate) { Host.WriteLine("Restore simulation done."); return; } // Issue a PreRestore event to the writers client.PreRestore(); // Execute the optional custom command between PreRestore and PostRestore try { if (HasOption(OptExecCommand)) { string arguments = String.Empty; if (HasOption(CommonOptions.OptExecCommandArgs)) { arguments = GetOptionValue<string>(CommonOptions.OptExecCommandArgs); } Host.ExecCommand(GetOptionValue<string>(OptExecCommand), arguments); } } catch (Exception) { // Notify writers about a failed restore client.SetFileRestoreStatus(false); // Issue a PostRestore event to the writers client.PostRestore(); throw; } // Notify writers about a succesful restore client.SetFileRestoreStatus(true); // Issue a PostRestore event to the writers client.PostRestore(); // Check selected writer status client.CheckSelectedWriterStatus(); Host.WriteLine("Restore done."); } }
public Task Execute(IJobExecutionContext context) { // Quartz.NET seem to fire each Trigger once after scheduling them, regardless of their real fire time. // This is an attempt to fix that issue. if (context.PreviousFireTimeUtc == null) { return(TaskConst.Completed); } VssClient vss = null; int maxRetryCount = -1; try { SnapshotRule rule = RuleMgr.Instance.GetRule(RuleId); if (rule == null) { Log.Error("Failed to retrieve SnapshotRule {RuleId}", RuleId); throw new InvalidOperationException(String.Format("Failed to retrieve SnapshotRule {0}", RuleId)); } Log.Debug("Executing SnapshotJob for {rule.Name}", rule.Name); if (rule.Enabled == false) // Shouldn't happen expect in rare cases { return(TaskConst.Completed); } vss = new VssClient(new VssHost()); vss.Initialize((VssSnapshotContext)rule.VssContext, (VssBackupType)rule.VssBackupType); var snapshotIds = vss.CreateSnapshot(rule.Volumes, null, rule.VssExcludeWriters, rule.VssIncludeWriters); PruningMgr.Instance.CreateNewInstances(rule.Id, snapshotIds); // TODO: Implement backups if (false && rule.BackupEnabled && rule.BackupRules != null && rule.BackupRules.Count > 0) { ScheduleBackup(context.Scheduler); } Log.Debug("Completed SnapshotJob for {RuleId}", RuleId); } catch (Exception ex) { Log.Error(ex, "Failed SnapshotJob for {RuleId}", RuleId); Retry(ex, context.Scheduler, context.JobDetail, maxRetryCount); return(TaskConst.Canceled); } finally { if (vss != null) { vss.Dispose(); vss = null; } } return(TaskConst.Completed); }
public override void Run() { Host.WriteLine("Performing a{0} restore", Simulate ? " simulated" : ""); string xmlDoc = File.ReadAllText(FileName); Host.WriteVerbose("XML Document:\n{0}", xmlDoc); using (VssClient client = new VssClient(Host)) { // Initialize the VSS client client.Initialize(VssSnapshotContext.All, xmlDoc, true); // Gather writer metadata client.GatherWriterMetadata(); // Gather writer status client.GatherWriterStatus(); // List writer status client.ListWriterStatus(); // Initialize the list of writers and components for restore client.InitializeWriterComponentsForRestore(); // Select required components for restore client.SelectComponentsForRestore(ExcludedWriters.ToList(), IncludedWriters.ToList()); if (Simulate) { Host.WriteLine("Restore simulation done."); return; } // Issue a PreRestore event to the writers client.PreRestore(); // Execute the optional custom command between PreRestore and PostRestore try { if (HasOption(OptExecCommand)) { string arguments = String.Empty; if (HasOption(CommonOptions.OptExecCommandArgs)) { arguments = GetOptionValue <string>(CommonOptions.OptExecCommandArgs); } Host.ExecCommand(GetOptionValue <string>(OptExecCommand), arguments); } } catch (Exception) { // Notify writers about a failed restore client.SetFileRestoreStatus(false); // Issue a PostRestore event to the writers client.PostRestore(); throw; } // Notify writers about a succesful restore client.SetFileRestoreStatus(true); // Issue a PostRestore event to the writers client.PostRestore(); // Check selected writer status client.CheckSelectedWriterStatus(); Host.WriteLine("Restore done."); } }
public override void Run() { Host.WriteVerbose("- Attempting to create a shadow copy set for the volumes: {0}", String.Join(",", VolumeList.ToArray())); UpdateFinalContext(); using (VssClient client = new VssClient(Host)) { client.Initialize(Context); // Create the shadow copy set client.CreateSnapshot(VolumeList, BackupComponentsDoc, ExcludedWriters, IncludedWriters); // Execute BackupComplete, except in fast snapshot creation if ((Context & VssVolumeSnapshotAttributes.DelayedPostSnapshot) == 0) { try { if (HasOption(CommonOptions.OptSetVarScript)) { client.GenerateSetvarScript(GetOptionValue<string>(CommonOptions.OptSetVarScript)); } if (HasOption(OptExecCommand)) { string arguments = String.Empty; if (HasOption(CommonOptions.OptExecCommandArgs)) { arguments = GetOptionValue<string>(CommonOptions.OptExecCommandArgs); } Host.ExecCommand(GetOptionValue<string>(OptExecCommand), arguments); } } catch (Exception) { // Mark backup failure and exit if ((Context & VssVolumeSnapshotAttributes.NoWriters) == 0) client.BackupComplete(false); throw; } // Complete the backup // Note that this will notify writers that the backup is succesful! // (which means eventually log truncation) if ((Context & VssVolumeSnapshotAttributes.NoWriters) == 0) client.BackupComplete(true); } Host.WriteLine("Snapshot creation done."); } }
public ProjectIngestor(VssClient vssClient, string sqlConnectionString, ILogger logger) { this.vssClient = vssClient; this.sqlConnectionString = sqlConnectionString; this.logger = logger; }