/// <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 restoreRequest = new Model.RecoverTaskRequest(name: TaskName)
            {
                Type            = Model.RecoverTaskRequest.TypeEnum.KMountVolumes,
                ContinueOnError = true
            };

            var mountParams = new Model.MountVolumesParameters();

            if (BringDisksOnline.IsPresent)
            {
                mountParams.BringDisksOnline = BringDisksOnline;
            }

            if (VolumeNames != null)
            {
                mountParams.VolumeNames = new List <string>(VolumeNames);
            }

            mountParams.TargetSourceId = TargetHostId.HasValue ? TargetHostId : SourceId;

            if (TargetHostCredential != null)
            {
                mountParams.Username = TargetHostCredential.UserName;
                mountParams.Password = TargetHostCredential.GetNetworkCredential().Password;
            }

            restoreRequest.MountParameters = mountParams;

            var restoreObject = new Model.RestoreObjectDetails
            {
                JobId = JobId,
                ProtectionSourceId = SourceId
            };

            if (JobRunId.HasValue)
            {
                restoreObject.JobRunId = JobRunId;
            }

            if (NewParentId.HasValue)
            {
                restoreRequest.NewParentId = NewParentId;
            }

            if (StartTime.HasValue)
            {
                restoreObject.StartedTimeUsecs = StartTime;
            }

            var objects = new List <Model.RestoreObjectDetails>();

            objects.Add(restoreObject);

            restoreRequest.Objects = objects;

            // POST /public/restore/recover
            var preparedUrl = $"/public/restore/recover";
            var result      = Session.ApiClient.Post <Model.RestoreTask>(preparedUrl, restoreRequest);

            WriteObject(result);
        }
Beispiel #3
0
        /// <summary>
        /// Process
        /// </summary>
        protected override void ProcessRecord()
        {
            var restoreRequest = new Model.RestoreFilesTaskRequest(name: TaskName)
            {
                Filenames          = new List <string>(FileNames),
                ContinueOnError    = ContinueOnError.IsPresent,
                PreserveAttributes = !(DoNotPreserveAttributes.IsPresent),
                Overwrite          = !(DoNotOverwrite.IsPresent)
            };

            if (FileRecoveryMethod.HasValue)
            {
                restoreRequest.FileRecoveryMethod = FileRecoveryMethod;
            }

            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 Model.RestoreObjectDetails
            {
                JobId = JobId,
                ProtectionSourceId = SourceId,
                JobUid             = new Model.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 <Model.RestoreTask>(preparedUrl, restoreRequest);

            WriteObject(result);
        }