예제 #1
0
        /// <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");
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Process
        /// </summary>
        protected override void ProcessRecord()
        {
            if (JobObject != null)
            {
                JobName  = JobObject.JobName;
                JobRunId = (long)JobObject.BackupRun.JobRunId;
            }


            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 <Model.RunJobSnapshotTarget>();
                            var target         = new Model.RunJobSnapshotTarget
                            {
                                Type       = Model.RunJobSnapshotTarget.TypeEnum.KLocal,
                                DaysToKeep = 0
                            };

                            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);

                            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");
            }
        }