/// <summary> /// Process /// </summary> protected override void ProcessRecord() { if (!string.IsNullOrWhiteSpace(Name)) { var job = RestApiCommon.GetProtectionJobByName(Session.ApiClient, Name); Id = (long)job.Id; } // POST /public/protectionJobState/{id} if (ShouldProcess($"Job Id: {Id}")) { bool deleteSnapshots = true; if (KeepSnapshots.IsPresent) { deleteSnapshots = false; } var content = new { DeleteSnapshots = deleteSnapshots }; var preparedUrl = $"/public/protectionJobs/{Id.ToString()}"; Session.ApiClient.Delete(preparedUrl, content); WriteObject($"Protection job with Id {Id} was deleted successfully."); } else { WriteObject($"Protection job with Id {Id} was not deleted."); } }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { if (!string.IsNullOrWhiteSpace(Name)) { var job = RestApiCommon.GetProtectionJobByName(Session.ApiClient, Name); Id = (long)job.Id; } var copyRunTargets = CopyRunTargets != null?CopyRunTargets.ToList() : null; var sourceIDs = SourceIds != null?SourceIds.ToList() : null; var content = new RunProtectionJobParam { CopyRunTargets = copyRunTargets, RunType = RunType, SourceIds = sourceIDs }; // POST public/protectionJobs/run/{id} var preparedUrl = $"/public/protectionJobs/run/{Id.ToString()}"; Session.ApiClient.Post(preparedUrl, content); WriteObject("Protection job was started successfully."); }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { if (ShouldProcess($"Job Run Id: {JobRunId} for Protection Job: {JobName}")) { var job = RestApiCommon.GetProtectionJobByName(Session.ApiClient, JobName); var jobRuns = RestApiCommon.GetProtectionJobRunsByJobId(Session.ApiClient, (long)job.Id); foreach (var jobRun in jobRuns) { bool snapshotDeleted = (bool)jobRun.BackupRun.SnapshotsDeleted; if (!snapshotDeleted) { if (JobRunId == jobRun.BackupRun.JobRunId) { var copyRunTargets = new List <Models.RunJobSnapshotTarget>(); var target = new Models.RunJobSnapshotTarget { Type = Models.RunJobSnapshotTarget.TypeEnum.KLocal, DaysToKeep = 0 }; copyRunTargets.Add(target); var run = new Models.UpdateProtectionJobRun { CopyRunTargets = copyRunTargets, JobUid = new Models.UniqueGlobalId10 { ClusterId = jobRun.JobUid.ClusterId, ClusterIncarnationId = jobRun.JobUid.ClusterIncarnationId, Id = jobRun.JobUid.Id }, RunStartTimeUsecs = (long)jobRun.CopyRun[0].RunStartTimeUsecs }; if (SourceIds != null && SourceIds.Length >= 1) { run.SourceIds = new List <long?>(SourceIds); } var runs = new List <Models.UpdateProtectionJobRun>(); runs.Add(run); var request = new Models.UpdateProtectionJobRunsParam { JobRuns = runs }; var preparedUrl = $"/public/protectionRuns"; var result = Session.ApiClient.Put(preparedUrl, request); WriteObject($"Expired the snapshot with Job Run Id: {JobRunId} for Protection Job: {JobName} successfully"); } } } } else { WriteObject($"The snapshot with Job Run Id: {JobRunId} for Protection Job: {JobName} was not expired"); } }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { var view = RestApiCommon.GetViewByName(Session.ApiClient, SourceViewName); var cloneRequest = new Model.CloneTaskRequest(name: TaskName) { Type = Model.CloneTaskRequest.TypeEnum.KCloneView, ContinueOnError = true, }; var cloneViewParams = new Model.CloneViewRequest { SourceViewName = SourceViewName, CloneViewName = TargetViewName, Description = TargetViewDescription, Qos = new Model.QoS { PrincipalName = QoSPolicy } }; cloneRequest.CloneViewParameters = cloneViewParams; var cloneObject = new Model.RestoreObjectDetails { JobId = JobId, ProtectionSourceId = view.ViewProtection.MagnetoEntityId }; if (JobRunId.HasValue) { cloneObject.JobRunId = JobRunId; } if (StartTime.HasValue) { cloneObject.StartedTimeUsecs = StartTime; } var objects = new List <Model.RestoreObjectDetails>(); objects.Add(cloneObject); cloneRequest.Objects = objects; // POST /public/restore/clone var preparedUrl = $"/public/restore/clone"; var result = Session.ApiClient.Post <Model.RestoreTask>(preparedUrl, cloneRequest); WriteObject(result); }
private bool IsValidTime(long?time) { bool valid = true; try { RestApiCommon.ConvertUsecsToDateTime((long)time); } catch { valid = false; } return(valid); }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { if (!string.IsNullOrWhiteSpace(Name)) { var job = RestApiCommon.GetProtectionJobByName(Session.ApiClient, Name); Id = (long)job.Id; } var protectionJobState = new { Pause = true }; // POST /public/protectionJobState/{id} var preparedUrl = $"/public/protectionJobState/{Id.ToString()}"; Session.ApiClient.Post(preparedUrl, protectionJobState); WriteObject("Protection job was paused successfully."); }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { if (!string.IsNullOrWhiteSpace(Name)) { var job = RestApiCommon.GetProtectionJobByName(Session.ApiClient, Name); Id = (long)job.Id; } var requestData = JsonConvert.SerializeObject(new { powerOff = PowerOffVms.IsPresent }); // POST /deactivateBackupJob/{id} var preparedUrl = $"/deactivateBackupJob/{Id.ToString()}"; Session.ApiClient.Post(preparedUrl, requestData); WriteObject($"Protection job with id {Id} was deactivated successfully."); }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { if (ProtectionJob.Environment == Model.ProtectionJob.EnvironmentEnum.KPhysicalFiles) { var job = RestApiCommon.GetProtectionJobById(Session.ApiClient, ProtectionJob.Id.Value); if (null != job) { if (null != job.SourceSpecialParameters) { // assuming that there will be at least one source exists in the job and the job has ran at least once PhysicalProtectionSource.HostTypeEnum hostType = (PhysicalProtectionSource.HostTypeEnum) job.LastRun.BackupRun.SourceBackupStatus[0].Source.PhysicalProtectionSource.HostType; List <SourceSpecialParameter> resp = ConstructSourceSpecialParameters(hostType, ProtectionJob.SourceIds, job.SourceIds); ProtectionJob.SourceSpecialParameters.AddRange(resp); } } } // PUT public/protectionJobs/{id} var preparedUrl = $"/public/protectionJobs/{ProtectionJob.Id.ToString()}"; var result = Session.ApiClient.Put <Model.ProtectionJob>(preparedUrl, ProtectionJob); WriteObject(result); }
private bool IsValidPointInTime(long?restoreTimeSecs, long?startTime, long sourceId, Model.ProtectionJob job) { // identifying range from preceeding day System.DateTime startDate = RestApiCommon.ConvertUsecsToDateTime((long)startTime); startDate = startDate.AddDays(-1); long startTimeInUsec = RestApiCommon.ConvertDateTimeToUsecs(startDate); var pointsInTimeRange = new Model.RestorePointsForTimeRangeParam { EndTimeUsecs = RestApiCommon.ConvertDateTimeToUsecs(System.DateTime.Now), Environment = Model.RestorePointsForTimeRangeParam.EnvironmentEnum.KSQL, JobUids = new List <Model.UniversalId>(), ProtectionSourceId = sourceId, StartTimeUsecs = startTimeInUsec }; pointsInTimeRange.JobUids.Add(job.Uid); var pointsForTimeRangeUrl = $"/public/restore/pointsForTimeRange"; var timeRangeResult = Session.ApiClient.Post <Model.RestorePointsForTimeRange>(pointsForTimeRangeUrl, pointsInTimeRange); bool foundPointInTime = false; if (null != timeRangeResult.TimeRanges) { foreach (var item in timeRangeResult.TimeRanges) { var restoreTimeUsecs = restoreTimeSecs * 1000 * 1000; if (item.StartTimeUsecs < restoreTimeUsecs && restoreTimeUsecs < item.EndTimeUsecs) { foundPointInTime = true; break; } } } return(foundPointInTime); }
/// <summary> /// Process Record /// </summary> protected override void ProcessRecord() { if (!string.IsNullOrWhiteSpace(Name)) { var job = RestApiCommon.GetProtectionJobByName(Session.ApiClient, Name); Id = (long)job.Id; } if (JobRunId == null) { var job = RestApiCommon.GetProtectionJobById(Session.ApiClient, Id); JobRunId = (long)job.LastRun.BackupRun.JobRunId; } var body = new CancelProtectionJobRunParam { //CopyTaskUid, JobRunId = JobRunId }; var url = $"/public/protectionRuns/cancel/{Id.ToString()}"; Session.ApiClient.Post(url, body); WriteObject("Protection Job Run cancelled."); }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { var domain = RestApiCommon.GetStorageDomainByName(Session.ApiClient, StorageDomainName); long storageDomainId = (long)domain.Id; var request = new Model.CreateViewRequest(name: Name, viewBoxId: storageDomainId) { Description = Description, ProtocolAccess = (Model.CreateViewRequest.ProtocolAccessEnum)AccessProtocol, Qos = new Model.QoS(principalName: QosPolicy), CaseInsensitiveNamesEnabled = CaseInsensitiveNames.IsPresent, EnableSmbViewDiscovery = BrowsableShares.IsPresent, EnableSmbAccessBasedEnumeration = SmbAccessBasedEnumeration.IsPresent, StoragePolicyOverride = new Model.StoragePolicyOverride(DisableInlineDedupAndCompression.IsPresent) }; if (LogicalQuotaInBytes != null || AlertQuotaInBytes != null) { request.LogicalQuota = new Model.QuotaPolicy(); if (LogicalQuotaInBytes != null) { request.LogicalQuota.HardLimitBytes = LogicalQuotaInBytes; } if (AlertQuotaInBytes != null) { request.LogicalQuota.AlertLimitBytes = AlertQuotaInBytes; } } var preparedUrl = $"/public/views"; var result = Session.ApiClient.Post <Model.View>(preparedUrl, request); WriteObject(result); }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { var requestData = new Dictionary <string, object>(); requestData["name"] = TaskName; requestData["action"] = "kCloneApp"; var restoreAppParams = new Dictionary <string, object>(); restoreAppParams["type"] = 3; if (TargetHostCredential != null) { var credentials = new Dictionary <string, object>(); credentials["username"] = TargetHostCredential.UserName; credentials["password"] = TargetHostCredential.GetNetworkCredential().Password; restoreAppParams["credentials"] = credentials; } var job = RestApiCommon.GetProtectionJobById(Session.ApiClient, JobId); var jobUid = new Dictionary <string, object>(); jobUid["clusterId"] = job.Uid.ClusterId; jobUid["clusterIncarnationId"] = job.Uid.ClusterIncarnationId; jobUid["objectId"] = job.Id; var ownerObject = new Dictionary <string, object>(); ownerObject["jobId"] = JobId; ownerObject["jobUid"] = jobUid; if (JobRunId.HasValue) { ownerObject["jobInstanceId"] = JobRunId; } if (StartTime.HasValue) { ownerObject["startTimeUsecs"] = StartTime; } var entity = new Dictionary <string, object>(); entity["id"] = HostSourceId; ownerObject["entity"] = entity; var ownerRestoreInfo = new Dictionary <string, object>(); ownerRestoreInfo["ownerObject"] = ownerObject; ownerRestoreInfo["performRestore"] = false; restoreAppParams["ownerRestoreInfo"] = ownerRestoreInfo; var sqlRestoreParams = new Dictionary <string, object>(); sqlRestoreParams["captureTailLogs"] = false; if (!string.IsNullOrWhiteSpace(NewDatabaseName)) { sqlRestoreParams["newDatabaseName"] = NewDatabaseName; } if (!string.IsNullOrWhiteSpace(InstanceName)) { sqlRestoreParams["instanceName"] = InstanceName; } var restoreParams = new Dictionary <string, object>(); restoreParams["sqlRestoreParams"] = sqlRestoreParams; if (TargetHostId != null) { var targetHost = new Dictionary <string, object>(); targetHost["id"] = TargetHostId; restoreParams["targetHost"] = targetHost; } if (TargetHostParentId != null) { var targetHostParentSource = new Dictionary <string, object>(); targetHostParentSource["id"] = TargetHostParentId; restoreParams["targetHostParentSource"] = targetHostParentSource; } var appEntity = new Dictionary <string, object>(); appEntity["type"] = 3; appEntity["id"] = SourceId; var restoreAppObjectVec = new Dictionary <string, object>(); restoreAppObjectVec["restoreParams"] = restoreParams; restoreAppObjectVec["appEntity"] = appEntity; restoreAppParams["restoreAppObjectVec"] = new[] { restoreAppObjectVec }; requestData["restoreAppParams"] = restoreAppParams; string cloneRequest = JsonConvert.SerializeObject(requestData, Formatting.Indented); // POST /cloneApplication var preparedUrl = $"/cloneApplication"; var result = Session.ApiClient.Post(preparedUrl, cloneRequest); JObject restoreTaskObject = JObject.Parse(result); string restoreTaskId = (string)restoreTaskObject["restoreTask"]["performRestoreTaskState"]["base"]["taskId"]; // GET /public/restore/tasks/{id} var getRestoreTaskUrl = $"/public/restore/tasks/{restoreTaskId}"; var response = Session.ApiClient.Get <Models.RestoreTask>(getRestoreTaskUrl); WriteObject(response); }
protected override void ProcessRecord() { DateTime result = RestApiCommon.ConvertUsecsToDateTime(Usecs); WriteObject(result); }
protected override void ProcessRecord() { long microseconds = RestApiCommon.ConvertDateTimeToUsecs(DateTime); WriteObject(microseconds); }
/// <summary> /// Process Record /// </summary> protected override void ProcessRecord() { Model.ProtectionJob currentProtectionjob = null; if (!string.IsNullOrWhiteSpace(Name)) { var job = RestApiCommon.GetProtectionJobByName(Session.ApiClient, Name); Id = (long)job.Id; currentProtectionjob = job; } if (JobRunId == null) { var job = RestApiCommon.GetProtectionJobById(Session.ApiClient, Id); JobRunId = (long)job.LastRun.BackupRun.JobRunId; currentProtectionjob = job; } UniversalId copyTaskUid = null; CopyRun copyRun = null; if (StopArchivalJob) { copyRun = currentProtectionjob.LastRun.CopyRun.Find(x => x.Target.Type == SnapshotTargetSettings.TypeEnum.KArchival); if (null == copyRun) { WriteObject("Could not find the archival task."); return; } } if (StopCloudSpinJob) { copyRun = currentProtectionjob.LastRun.CopyRun.Find(x => x.Target.Type == SnapshotTargetSettings.TypeEnum.KCloudDeploy); if (null == copyRun) { WriteObject("Could not find the cloud deploy task."); return; } } if (StopReplicationJob) { copyRun = currentProtectionjob.LastRun.CopyRun.Find(x => x.Target.Type == SnapshotTargetSettings.TypeEnum.KRemote); if (null == copyRun) { WriteObject("Could not find the replication task."); return; } } object body; if (null != copyRun) { copyTaskUid = copyRun.TaskUid; // When the non-local job is being stopped body = new CancelProtectionJobRunParam { // The copy task uid and job id would be used for Archival, Cloud spin and Remote targets CopyTaskUid = copyTaskUid, }; } else { // When the local job is being stopped body = new CancelProtectionJobRunParam { JobRunId = this.JobRunId }; } var url = $"/public/protectionRuns/cancel/{Id.ToString()}"; Session.ApiClient.Post(url, body); WriteObject("Protection Job Run cancelled."); }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { var restoreRequest = new Models.RestoreFilesTaskRequest(name: TaskName) { Filenames = new List <string>(FileNames), ContinueOnError = ContinueOnError.IsPresent, PreserveAttributes = !(DoNotPreserveAttributes.IsPresent), Overwrite = !(DoNotOverwrite.IsPresent) }; if (!string.IsNullOrWhiteSpace(NewBaseDirectory)) { restoreRequest.NewBaseDirectory = NewBaseDirectory; } if (TargetHostCredential != null) { restoreRequest.Username = TargetHostCredential.UserName; restoreRequest.Password = TargetHostCredential.GetNetworkCredential().Password; } if (TargetParentSourceId.HasValue) { restoreRequest.TargetParentSourceId = TargetParentSourceId; } if (TargetSourceId.HasValue) { restoreRequest.TargetSourceId = TargetSourceId; } if (TargetHostType.HasValue) { restoreRequest.TargetHostType = TargetHostType; } var job = RestApiCommon.GetProtectionJobById(Session.ApiClient, JobId); var restoreObject = new Models.RestoreObject_ { JobId = JobId, ProtectionSourceId = SourceId, JobUid = new Models.UniversalId_ { Id = job.Id, ClusterId = job.Uid.ClusterId, ClusterIncarnationId = job.Uid.ClusterIncarnationId } }; // If job run id is not specified, get the job run id of the last run if (JobRunId.HasValue) { restoreObject.JobRunId = JobRunId; } else { restoreObject.JobRunId = job.LastRun.BackupRun.JobRunId; } // If start time is not specified, get the start time of the last run if (StartTime.HasValue) { restoreObject.StartedTimeUsecs = StartTime; } else { restoreObject.StartedTimeUsecs = job.LastRun.BackupRun.Stats.StartTimeUsecs; } restoreRequest.SourceObjectInfo = restoreObject; // POST /public/restore/files var preparedUrl = $"/public/restore/files"; var result = Session.ApiClient.Post <Models.RestoreTask>(preparedUrl, restoreRequest); WriteObject(result); }
/// <summary> /// Process Record /// </summary> protected override void ProcessRecord() { var qb = new QuerystringBuilder(); if (!string.IsNullOrWhiteSpace(JobName)) { var job = RestApiCommon.GetProtectionJobByName(Session.ApiClient, JobName); JobId = job.Id; } if (JobId.HasValue && JobId != null) { qb.Add("jobId", JobId.Value); } if (StartedTime.HasValue && StartedTime != null) { qb.Add("startedTimeUsecs", StartedTime.Value); } if (EndTime.HasValue && EndTime != null) { qb.Add("endTimeUsecs", EndTime.Value); } if (NumRuns.HasValue && NumRuns != null) { qb.Add("numRuns", NumRuns.Value); } if (ExcludeTasks.IsPresent) { qb.Add("excludeTasks", true); } if (SourceId.HasValue && SourceId != null) { qb.Add("sourceId", SourceId.Value); } if (ExcludeErrorRuns.IsPresent) { qb.Add("excludeErrorRuns", true); } if (StartTime.HasValue && StartTime != null) { qb.Add("startTimeUsecs", StartTime.Value); } if (RunTypes != null && RunTypes.Any()) { qb.Add("runTypes", string.Join(",", RunTypes)); } if (ExcludeNonRestoreableRuns.IsPresent) { qb.Add("excludeNonRestoreableRuns", true); } var url = $"/public/protectionRuns{ qb.Build()}"; var results = Session.ApiClient.Get <IEnumerable <ProtectionRunInstance> >(url); // Hide deleted protection jobs unless explicitly asked for if (!IncludeDeleted.IsPresent) { results = results.Where(x => !(x.JobName.StartsWith("_DELETED"))).ToList(); } WriteObject(results, true); }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { if (ShouldProcess($"Source Id : {SourceId}")) { var applicationRestoreObject = new Model.ApplicationRestoreObject(applicationServerId: SourceId) { SqlRestoreParameters = new Model.SqlRestoreParameters { CaptureTailLogs = CaptureTailLogs.IsPresent, KeepOffline = KeepOffline.IsPresent, KeepCdc = KeepCDC.IsPresent } }; if (!string.IsNullOrWhiteSpace(NewDatabaseName)) { applicationRestoreObject.SqlRestoreParameters.NewDatabaseName = NewDatabaseName; } if (!string.IsNullOrWhiteSpace(NewInstanceName)) { applicationRestoreObject.SqlRestoreParameters.NewInstanceName = NewInstanceName; } if (!string.IsNullOrWhiteSpace(TargetDataFilesDirectory)) { applicationRestoreObject.SqlRestoreParameters.TargetDataFilesDirectory = TargetDataFilesDirectory; } if (!string.IsNullOrWhiteSpace(TargetLogFilesDirectory)) { applicationRestoreObject.SqlRestoreParameters.TargetLogFilesDirectory = TargetLogFilesDirectory; } if (null != TargetSecondaryDataFilesDirectoryList) { applicationRestoreObject.SqlRestoreParameters.TargetSecondaryDataFilesDirectoryList = TargetSecondaryDataFilesDirectoryList; } if (TargetHostId != null) { applicationRestoreObject.TargetHostId = TargetHostId; } if (TargetHostParentId != null) { applicationRestoreObject.TargetRootNodeId = TargetHostParentId; } var applicationRestoreObjects = new List <Model.ApplicationRestoreObject>(); applicationRestoreObjects.Add(applicationRestoreObject); var job = RestApiCommon.GetProtectionJobById(Session.ApiClient, JobId); var hostingProtectionSource = new Model.RestoreObjectDetails { JobId = JobId, ProtectionSourceId = HostSourceId, JobUid = new Model.UniversalId { Id = job.Id, ClusterId = job.Uid.ClusterId, ClusterIncarnationId = job.Uid.ClusterIncarnationId } }; if (this.ArchivalId.HasValue) { hostingProtectionSource.ArchivalTarget = new Model.ArchivalExternalTarget { VaultId = this.ArchivalId, VaultType = Model.ArchivalExternalTarget.VaultTypeEnum.KCloud }; } if (JobRunId.HasValue) { hostingProtectionSource.JobRunId = JobRunId; } if (StartTime.HasValue) { hostingProtectionSource.StartedTimeUsecs = StartTime; } var restoreRequest = new Model.ApplicationsRestoreTaskRequest(name: TaskName, applicationEnvironment: Model.ApplicationsRestoreTaskRequest.ApplicationEnvironmentEnum.KSQL, applicationRestoreObjects: applicationRestoreObjects, hostingProtectionSource: hostingProtectionSource) { }; if (TargetHostCredential != null) { restoreRequest.Username = TargetHostCredential.UserName; restoreRequest.Password = TargetHostCredential.GetNetworkCredential().Password; } if (null != this.RestoreTimeSecs) { if (null == this.StartTime) { WriteObject("Please add start time to validate point in time restore."); return; } if (false == IsValidPointInTime(this.RestoreTimeSecs, this.StartTime, this.SourceId, job)) { WriteObject("Invalid point in time " + this.RestoreTimeSecs); return; } applicationRestoreObject.SqlRestoreParameters.RestoreTimeSecs = this.RestoreTimeSecs; } // POST /public/restore/applicationsRecover var preparedUrl = $"/public/restore/applicationsRecover"; var result = Session.ApiClient.Post <Model.RestoreTask>(preparedUrl, restoreRequest); WriteObject(result); } }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { var job = RestApiCommon.GetProtectionJobByName(Session.ApiClient, JobName); var jobRuns = RestApiCommon.GetProtectionJobRunsByJobId(Session.ApiClient, (long)job.Id); foreach (var jobRun in jobRuns) { bool snapshotDeleted = (bool)jobRun.BackupRun.SnapshotsDeleted; if (!snapshotDeleted) { if (JobRunId == jobRun.BackupRun.JobRunId) { var copyRunTargets = new List <Model.RunJobSnapshotTarget>(); var target = new Model.RunJobSnapshotTarget { Type = Model.RunJobSnapshotTarget.TypeEnum.KLocal }; if (ExtendByDays.HasValue) { target.DaysToKeep = ExtendByDays; } else if (ReduceByDays.HasValue) { target.DaysToKeep = -ReduceByDays; } copyRunTargets.Add(target); var run = new Model.UpdateProtectionJobRun { CopyRunTargets = copyRunTargets, JobUid = new Model.UniversalId { ClusterId = jobRun.JobUid.ClusterId, ClusterIncarnationId = jobRun.JobUid.ClusterIncarnationId, Id = jobRun.JobUid.Id }, RunStartTimeUsecs = (long)jobRun.CopyRun[0].RunStartTimeUsecs }; if (SourceIds != null && SourceIds.Length >= 1) { run.SourceIds = new List <long>(SourceIds); } var runs = new List <Model.UpdateProtectionJobRun>(); runs.Add(run); var request = new Model.UpdateProtectionJobRunsParam { JobRuns = runs }; var preparedUrl = $"/public/protectionRuns"; var result = Session.ApiClient.Put(preparedUrl, request); if (ExtendByDays.HasValue) { WriteObject("Extended the snapshot retention successfully"); } else if (ReduceByDays.HasValue) { WriteObject("Reduced the snapshot retention successfully"); } } } } }
protected override void ProcessRecord() { if (string.IsNullOrWhiteSpace(Timezone)) { Timezone = TimeZoneInfoExtensions.GetOlsonTimeZone(); } if (!string.IsNullOrWhiteSpace(PolicyName)) { var policy = RestApiCommon.GetPolicyByName(Session.ApiClient, PolicyName); PolicyId = policy.Id; } if (!string.IsNullOrWhiteSpace(StorageDomainName)) { var domain = RestApiCommon.GetStorageDomainByName(Session.ApiClient, StorageDomainName); StorageDomainId = (long)domain.Id; } var newProtectionJob = new Model.ProtectionJob(name: Name, policyId: PolicyId, viewBoxId: StorageDomainId) { Timezone = Timezone, StartTime = new TimeOfDay(ScheduleStartTime.Hour, ScheduleStartTime.Minute) }; if (ParentSourceId.HasValue) { newProtectionJob.ParentSourceId = ParentSourceId; } if (SourceIds != null && SourceIds.Any()) { newProtectionJob.SourceIds = SourceIds.ToList(); } if (ExcludeSourceIds != null && ExcludeSourceIds.Any()) { newProtectionJob.ExcludeSourceIds = ExcludeSourceIds.ToList(); } if (VmTagIds != null && VmTagIds.Any()) { var vmTagIdsList = VmTagIds.ToList(); newProtectionJob.VmTagIds = new List <List <long> >(); foreach (var vmTagIds in vmTagIdsList) { newProtectionJob.VmTagIds.Add(new List <long> { vmTagIds }); } } if (ExcludeVmTagIds != null && ExcludeVmTagIds.Any()) { var excludeVmTagIdsList = ExcludeVmTagIds.ToList(); newProtectionJob.ExcludeVmTagIds = new List <List <long> >(); foreach (var excludeVmTagIds in excludeVmTagIdsList) { newProtectionJob.ExcludeVmTagIds.Add(new List <long> { excludeVmTagIds }); } } if (!string.IsNullOrWhiteSpace(ViewName)) { newProtectionJob.ViewName = ViewName; } newProtectionJob.Environment = Environment != null ? Environment : Model.ProtectionJob.EnvironmentEnum.KView; if (FullSLATimeInMinutes != null) { newProtectionJob.FullProtectionSlaTimeMins = FullSLATimeInMinutes; } if (IncrementalSLATimeInMinutes != null) { newProtectionJob.IncrementalProtectionSlaTimeMins = IncrementalSLATimeInMinutes; } if (SourceSpecialParameters != null && SourceSpecialParameters.Any()) { newProtectionJob.SourceSpecialParameters = SourceSpecialParameters.ToList(); } var preparedUrl = $"/public/protectionJobs"; var result = Session.ApiClient.Post <Model.ProtectionJob>(preparedUrl, newProtectionJob); WriteObject(result); }
/// <summary> /// Process /// </summary> protected override void ProcessRecord() { var applicationRestoreObject = new Models.ApplicationRestoreObject(applicationServerId: SourceId) { SqlRestoreParameters = new Models.SqlRestoreParameters { CaptureTailLogs = CaptureTailLogs.IsPresent, KeepOffline = KeepOffline.IsPresent } }; if (!string.IsNullOrWhiteSpace(NewDatabaseName)) { applicationRestoreObject.SqlRestoreParameters.NewDatabaseName = NewDatabaseName; } if (!string.IsNullOrWhiteSpace(NewInstanceName)) { applicationRestoreObject.SqlRestoreParameters.NewInstanceName = NewInstanceName; } if (!string.IsNullOrWhiteSpace(TargetDataFilesDirectory)) { applicationRestoreObject.SqlRestoreParameters.TargetDataFilesDirectory = TargetDataFilesDirectory; } if (!string.IsNullOrWhiteSpace(TargetLogFilesDirectory)) { applicationRestoreObject.SqlRestoreParameters.TargetLogFilesDirectory = TargetLogFilesDirectory; } if (TargetHostId != null) { applicationRestoreObject.TargetHostId = TargetHostId; } if (TargetHostParentId != null) { applicationRestoreObject.TargetRootNodeId = TargetHostParentId; } var applicationRestoreObjects = new List <Models.ApplicationRestoreObject>(); applicationRestoreObjects.Add(applicationRestoreObject); var job = RestApiCommon.GetProtectionJobById(Session.ApiClient, JobId); var hostingProtectionSource = new Models.RestoreObject { JobId = JobId, ProtectionSourceId = HostSourceId, JobUid = new Models.UniversalId_ { Id = job.Id, ClusterId = job.Uid.ClusterId, ClusterIncarnationId = job.Uid.ClusterIncarnationId } }; if (JobRunId.HasValue) { hostingProtectionSource.JobRunId = JobRunId; } if (StartTime.HasValue) { hostingProtectionSource.StartedTimeUsecs = StartTime; } var restoreRequest = new Models.ApplicationsRestoreTaskRequest(name: TaskName, applicationEnvironment: Models.ApplicationsRestoreTaskRequest.ApplicationEnvironmentEnum.KSQL, applicationRestoreObjects: applicationRestoreObjects, hostingProtectionSource: hostingProtectionSource) { }; if (TargetHostCredential != null) { restoreRequest.Username = TargetHostCredential.UserName; restoreRequest.Password = TargetHostCredential.GetNetworkCredential().Password; } // POST /public/restore/applicationsRecover var preparedUrl = $"/public/restore/applicationsRecover"; var result = Session.ApiClient.Post <Models.RestoreTask>(preparedUrl, restoreRequest); WriteObject(result); }