/**
         * Creates a point in time snapshot of a file system and waits for it to become available. Note that snapshot
         * names are immutable and must be unique amongst all non-DELETED snapshots for a file system.
         *
         * We recommend using a retry token on these requests so that if you receive a timeout or server error
         * and need to retry the request you won't run the risk of creating multiple resources.
         *
         * @param fsClient the service client used to communicate with the File Storage service
         * @param fileSystem the file system to create the snapshot of
         */
        private static async Task <Snapshot> CreateSnapshot(FileStorageClient fsClient, FileSystem fileSystem)
        {
            logger.Info("Creating Snapshot...");

            CreateSnapshotDetails createSnapshotDetails = new CreateSnapshotDetails
            {
                FileSystemId = fileSystem.Id,
                Name         = "example_snapshot"
            };
            CreateSnapshotRequest createRequest = new CreateSnapshotRequest
            {
                CreateSnapshotDetails = createSnapshotDetails
            };
            CreateSnapshotResponse createResponse = await fsClient.CreateSnapshot(createRequest);

            logger.Info($"Created snapshot: {createResponse.Snapshot.Name}");

            logger.Info($"Waiting for snapshot to become available");
            GetSnapshotRequest getRequest = new GetSnapshotRequest
            {
                SnapshotId = createResponse.Snapshot.Id
            };
            GetSnapshotResponse getResponse = fsClient.Waiters.ForSnapshot(getRequest, Snapshot.LifecycleStateEnum.Active).Execute();

            logger.Info($"Snapshot state: {getResponse.Snapshot.LifecycleState}");

            return(getResponse.Snapshot);
        }
        internal CreateSnapshotResponse CreateSnapshot(CreateSnapshotRequest request)
        {
            var marshaller   = new CreateSnapshotRequestMarshaller();
            var unmarshaller = CreateSnapshotResponseUnmarshaller.Instance;

            return(Invoke <CreateSnapshotRequest, CreateSnapshotResponse>(request, marshaller, unmarshaller));
        }
Example #3
0
        static Snapshot CreateSnapshot(string VolumeID, string name)
        {
            AmazonEC2 ec2     = GetEC2Client();
            var       request = new CreateSnapshotRequest()
                                .WithVolumeId(VolumeID)
                                .WithDescription(name);
            var response = ec2.CreateSnapshot(request);
            var snapshot = response.CreateSnapshotResult.Snapshot;

            ec2.CreateTags(new CreateTagsRequest()
                           .WithResourceId(snapshot.SnapshotId)
                           .WithTag(new Tag {
                Key = "Name", Value = name
            })
                           .WithTag(new Tag {
                Key = "BackupDate", Value = DateTime.Today.ToShortDateString()
            }));

            while (CheckSnapshotCompletion(snapshot.SnapshotId) == false)
            {
                System.Threading.Thread.Sleep(5000);
                Console.WriteLine("Checking Status");
            }

            return(snapshot);
        }
        /// <summary>
        /// Initiates the asynchronous execution of the CreateSnapshot operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the CreateSnapshot operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <CreateSnapshotResponse> CreateSnapshotAsync(CreateSnapshotRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new CreateSnapshotRequestMarshaller();
            var unmarshaller = CreateSnapshotResponseUnmarshaller.Instance;

            return(InvokeAsync <CreateSnapshotRequest, CreateSnapshotResponse>(request, marshaller,
                                                                               unmarshaller, cancellationToken));
        }
Example #5
0
        /// <summary>
        /// 创建云硬盘快照
        /// </summary>
        public CreateSnapshotResponse CreateSnapshot(CreateSnapshotRequest createSnapshotRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();
            string              urlPath          = HttpUtils.AddUrlPath("/v2/{project_id}/cloudsnapshots", urlParam);
            SdkRequest          request          = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", createSnapshotRequest);
            HttpResponseMessage response         = DoHttpRequestSync("POST", request);

            return(JsonUtils.DeSerialize <CreateSnapshotResponse>(response));
        }
Example #6
0
        public async Task Execute(Arguments arguments)
        {
            CreateSnapshotRequest request = CreateRequest();

            IDiskAnalysisProgress diskAnalysisProgress = await requestBus.PlaceRequest <CreateSnapshotRequest, IDiskAnalysisProgress>(request);

            diskAnalysisProgress.Progress += HandleAnalysisProgress;

            diskAnalysisProgress.WaitToEnd();
        }
Example #7
0
        /// <summary>
        /// Create a snapshot of a volume.
        /// </summary>
        /// <param name="volumeId"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public string CreateSnapShot(string volumeId, string description)
        {
            var request = new CreateSnapshotRequest {
                VolumeId = volumeId, Description = description
            };

            CreateSnapshotResponse response = Client.CreateSnapshot(request);

            return(response.CreateSnapshotResult.Snapshot.SnapshotId);
        }
Example #8
0
        static void CreateVolumeSnapshot(AmazonEC2Client client, Volume volume)
        {
            DescribeSnapshots(client, volume);

            var tag    = volume.Tags.FirstOrDefault(i => i.Key == "backup");
            var backup = (tag is null) ? "off" : tag.Value;

            if (backup == "on")
            {
                var req = new CreateSnapshotRequest(volume.VolumeId, "");
                client.CreateSnapshotAsync(req).Wait();
            }
        }
Example #9
0
 /// <summary>
 /// 本接口(CreateSnapshot)用于对指定云盘创建快照。
 /// 
 /// * 只有具有快照能力的云硬盘才能创建快照。云硬盘是否具有快照能力可由[DescribeDisks](/document/product/362/16315)接口查询,见SnapshotAbility字段。
 /// * 可创建快照数量限制见[产品使用限制](https://cloud.tencent.com/doc/product/362/5145)。
 /// </summary>
 /// <param name="req">参考<see cref="CreateSnapshotRequest"/></param>
 /// <returns>参考<see cref="CreateSnapshotResponse"/>实例</returns>
 public async Task<CreateSnapshotResponse> CreateSnapshot(CreateSnapshotRequest req)
 {
      JsonResponseModel<CreateSnapshotResponse> rsp = null;
      try
      {
          var strResp = await this.InternalRequest(req, "CreateSnapshot");
          rsp = JsonConvert.DeserializeObject<JsonResponseModel<CreateSnapshotResponse>>(strResp);
      }
      catch (JsonSerializationException e)
      {
          throw new TencentCloudSDKException(e.Message);
      }
      return rsp.Response;
 }
Example #10
0
 private void createSnapShot()
 {
     try
     {
         CreateSnapshotRequest request = new CreateSnapshotRequest();
         request.Name = "MyNewSnapShot" + DateTime.Now.Ticks;
         var response = mrsServer.CreateSnapshot(sessionId, request);
         snapshotId = response.SnapshotId;
         Console.WriteLine("Create SnapShot :" + snapshotId);
         snapShotCreated = true;
     }
     catch (Exception e)
     {
         throw new Exception("Create Snapshot Failed " + e.Message);
     }
 }
Example #11
0
        public void TestCreateSnapshot()
        {
            DiskClient            diskClient = GetDiskClient();
            CreateSnapshotRequest request    = new CreateSnapshotRequest();

            request.RegionId    = "cn-north-1";
            request.ClientToken = Guid.NewGuid().ToString().Replace("-", "");
            SnapshotSpec snapshotSpec = new SnapshotSpec();

            snapshotSpec.DiskId      = "vol-s7s7vakg2k";
            snapshotSpec.Description = "dotnet sdk test";
            snapshotSpec.Name        = "dotnet sdk test";
            request.SnapshotSpec     = snapshotSpec;
            var result = diskClient.CreateSnapshot(request);

            _output.WriteLine(JsonConvert.SerializeObject(result));
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            CreateSnapshotRequest request;

            try
            {
                request = new CreateSnapshotRequest
                {
                    CreateSnapshotDetails = CreateSnapshotDetails,
                    OpcRetryToken         = OpcRetryToken,
                    OpcRequestId          = OpcRequestId
                };

                response = client.CreateSnapshot(request).GetAwaiter().GetResult();
                WriteOutput(response, response.Snapshot);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
        private static void CreateSnapshot(EvsClient client)
        {
            CreateSnapshotRequest req = new CreateSnapshotRequest()
            {
                Body = new CreateSnapshotRequestBody()
                {
                    Snapshot = new CreateSnapshotOption()
                    {
                        VolumeId    = "1bebb541-5601-450f-a87a-55f9a3c8327b",
                        Description = "test",
                        Name        = "test",
                        Force       = false
                    }
                }
            };

            try
            {
                CreateSnapshotResponse resp = client.CreateSnapshot(req);
                Console.WriteLine(resp.Snapshot);
                Console.WriteLine(resp.HttpStatusCode);
            }
            catch (RequestTimeoutException requestTimeoutException)
            {
                Console.WriteLine(requestTimeoutException.ErrorMessage);
            }
            catch (ServiceResponseException clientRequestException)
            {
                Console.WriteLine(clientRequestException.HttpStatusCode);
                Console.WriteLine(clientRequestException.ErrorCode);
                Console.WriteLine(clientRequestException.ErrorMsg);
            }
            catch (ConnectionException connectionException)
            {
                Console.WriteLine(connectionException.ErrorMessage);
            }
        }
Example #14
0
 /// <summary>
 ///  -   为指定云硬盘创建快照,新生成的快照的状态为creating。
 /// -   同一地域下单用户快照的配额为15块。
 /// -   为保证数据完整性,请您在创建快照之前,停止对云硬盘进行写入操作,以保证快照数据的完整性。
 /// -   在执行创建快照前,建议您对云硬盘进行卸载操作,创建快照后再重新挂载到云主机上。
 /// -   手动快照的生命周期独立于云硬盘,请您及时删除不需要的快照。
 /// -   创建快照所需时间取决于云硬盘容量的大小,云硬盘容量越大耗时越长。
 ///
 /// </summary>
 /// <param name="request">请求参数信息</param>
 /// <returns>请求结果信息</returns>
 public async Task <CreateSnapshotResponse> CreateSnapshot(CreateSnapshotRequest request)
 {
     return(await new CreateSnapshotExecutor().Client(this).Execute <CreateSnapshotResponse, CreateSnapshotResult, CreateSnapshotRequest>(request).ConfigureAwait(false));
 }
Example #15
0
 /// <summary>
 ///  -   为指定云硬盘创建快照,新生成的快照的状态为creating。
 /// -   同一地域下单用户快照的配额为15块。
 /// -   为保证数据完整性,请您在创建快照之前,停止对云硬盘进行写入操作,以保证快照数据的完整性。
 /// -   在执行创建快照前,建议您对云硬盘进行卸载操作,创建快照后再重新挂载到云主机上。
 /// -   手动快照的生命周期独立于云硬盘,请您及时删除不需要的快照。
 /// -   创建快照所需时间取决于云硬盘容量的大小,云硬盘容量越大耗时越长。
 ///
 /// </summary>
 /// <param name="request">请求参数信息</param>
 /// <returns>请求结果信息</returns>
 public CreateSnapshotResponse CreateSnapshot(CreateSnapshotRequest request)
 {
     return(new CreateSnapshotExecutor().Client(this).Execute <CreateSnapshotResponse, CreateSnapshotResult, CreateSnapshotRequest>(request));
 }
Example #16
0
 /// <summary>
 /// Create Snapshot
 /// </summary>
 /// <param name="request">Create Snapshot  request</param>
 /// <returns>Create Snapshot  Response from the service</returns>
 /// <remarks>
 /// Create a snapshot of the volume identified by volume ID. A volume does not have to be detached
 /// at the time the snapshot is taken.
 /// Important Note:
 /// Snapshot creation requires that the system is in a consistent state.
 /// For instance, this means that if taking a snapshot of a database, the tables must
 /// be read-only locked to ensure that the snapshot will not contain a corrupted
 /// version of the database.  Therefore, be careful when using this API to ensure that
 /// the system remains in the consistent state until the create snapshot status
 /// has returned.
 ///
 /// </remarks>
 public CreateSnapshotResponse CreateSnapshot(CreateSnapshotRequest request)
 {
     return(Invoke <CreateSnapshotResponse>("CreateSnapshotResponse.xml"));
 }
 public CreateSnapshotResponse Create(CreateSnapshotRequest request)
 {
     request.BeforeRequest();
     return(DoRequest <CreateSnapshotRequest, CreateSnapshotResponse>(request));
 }
 public Task <CreateSnapshotResponse> CreateAsync(CreateSnapshotRequest request, CancellationToken cancellationToken = default)
 {
     request.BeforeRequest();
     return(DoRequestAsync <CreateSnapshotRequest, CreateSnapshotResponse>(request, cancellationToken));
 }
 public override Task <CreateSnapshotResponse> CreateSnapshot(CreateSnapshotRequest request, ServerCallContext context)
 {
     return(base.CreateSnapshot(request, context));
 }
        public void Execute(Arguments arguments)
        {
            CreateSnapshotRequest request = CreateRequest(arguments);

            mediator.Send(request).Wait();
        }
Example #21
0
        public static void Backup(string name, string description, string volumeid, string volumename, string instancename, string expires)
        {
            Console.WriteLine("Creating snapshot of " + volumeid + " / " + volumename + " / " + instancename);

            AmazonEC2 ec2 = Ec2Helper.CreateClient();

            CreateSnapshotRequest rq = new CreateSnapshotRequest();

            rq.VolumeId    = volumeid;
            rq.Description = description;

            CreateSnapshotResponse rs = ec2.CreateSnapshot(rq);

            string snapshotid = rs.CreateSnapshotResult.Snapshot.SnapshotId;


            // build tags for snapshot

            List <Tag> tags = new List <Tag>();

            tags.Add(new Tag {
                Key = "Name", Value = name
            });
            tags.Add(new Tag {
                Key = "source", Value = "scheduler"
            });
            tags.Add(new Tag {
                Key = "instance", Value = instancename
            });
            tags.Add(new Tag {
                Key = "volume", Value = volumename
            });
            tags.Add(new Tag {
                Key = "expires", Value = expires.ToString()
            });


            // get tags from volume to be applied to snapshot

            DescribeTagsRequest trq = new DescribeTagsRequest();

            trq.WithFilter(new Filter()
            {
                Name = "resource-id", Value = new List <string>()
                {
                    volumeid
                }
            });
            DescribeTagsResponse trs = ec2.DescribeTags(trq);

            foreach (ResourceTag t in trs.DescribeTagsResult.ResourceTag)
            {
                if (t.Key != "nextSnapshot" && t.Key != "lastSnapshot" && t.Key != "Name")
                {
                    tags.Add(new Tag {
                        Key = t.Key, Value = t.Value
                    });
                }
            }


            // apply tags to snapshopt

            CreateTagsRequest rqq = new CreateTagsRequest();

            rqq.WithResourceId(snapshotid);

            rqq.WithTag(tags.ToArray());


            var createTagResponse = ec2.CreateTags(rqq);
        }