/// <summary>
        /// <para> Creates a DBSnapshot. The source DBInstance must be in "available" state. </para>
        /// </summary>
        ///
        /// <param name="createDBSnapshotRequest">Container for the necessary parameters to execute the CreateDBSnapshot service method on
        ///           AmazonRDS.</param>
        ///
        /// <returns>The response from the CreateDBSnapshot service method, as returned by AmazonRDS.</returns>
        ///
        /// <exception cref="DBInstanceNotFoundException"/>
        /// <exception cref="InvalidDBInstanceStateException"/>
        /// <exception cref="SnapshotQuotaExceededException"/>
        /// <exception cref="DBSnapshotAlreadyExistsException"/>
        public CreateDBSnapshotResponse CreateDBSnapshot(CreateDBSnapshotRequest createDBSnapshotRequest)
        {
            IRequest <CreateDBSnapshotRequest> request  = new CreateDBSnapshotRequestMarshaller().Marshall(createDBSnapshotRequest);
            CreateDBSnapshotResponse           response = Invoke <CreateDBSnapshotRequest, CreateDBSnapshotResponse> (request, this.signer, CreateDBSnapshotResponseUnmarshaller.GetInstance());

            return(response);
        }
Пример #2
0
    public async Task SnapshotRDS(Instant snapshotTime)
    {
        using AmazonRDSClient rdsClient = new AmazonRDSClient();
        var    date       = snapshotTime.InZone(TimeExtensions.EasternTimeZone).LocalDateTime.Date;
        var    dateString = date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
        var    random     = Guid.NewGuid().ToString().Substring(0, 1);
        string snapName   = "AdminSnap-" + dateString + "-" + random;

        CreateDBSnapshotRequest request = new CreateDBSnapshotRequest(snapName, _instanceName);
        await rdsClient.CreateDBSnapshotAsync(request, CancellationToken.None);
    }
Пример #3
0
        public async Task SnapshotRDS(Instant snapshotTime)
        {
            using (AmazonRDSClient rdsClient = new AmazonRDSClient())
            {
                var    date       = snapshotTime.InZone(DateTimeZoneProviders.Tzdb.GetZoneOrNull("America/New_York")).LocalDateTime.Date;
                var    dateString = date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
                var    random     = Guid.NewGuid().ToString().Substring(0, 1);
                string snapName   = "AdminSnap-" + dateString + "-" + random;

                CreateDBSnapshotRequest request = new CreateDBSnapshotRequest(snapName, _instanceName);
                await rdsClient.CreateDBSnapshotAsync(request, CancellationToken.None);
            }
        }
Пример #4
0
        public async Task <string> TakeSnapshot()
        {
            var rdsInstance = await GetRDSInstance();

            var instanceId = rdsInstance.DBInstanceIdentifier;
            //don't wrap in using block or it will be disposed before you are done with it.
            var rdsClient = new AmazonRDSClient(
                CredentiaslManager.GetCredential(environment),
                AwsCommon.GetRetionEndpoint(region));
            var request = new CreateDBSnapshotRequest($"{environment}-{DateTime.Today.ToShortDateString()}", instanceId);
            //don't await this long running task
            var response = await rdsClient.CreateDBSnapshotAsync(request);

            return(response.DBSnapshot.DBInstanceIdentifier);
        }
Пример #5
0
        private static IDictionary <string, string> ConvertCreateDBSnapshot(CreateDBSnapshotRequest request)
        {
            IDictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary["Action"] = "CreateDBSnapshot";
            if (request.IsSetDBSnapshotIdentifier())
            {
                dictionary["DBSnapshotIdentifier"] = request.DBSnapshotIdentifier;
            }
            if (request.IsSetDBInstanceIdentifier())
            {
                dictionary["DBInstanceIdentifier"] = request.DBInstanceIdentifier;
            }
            return(dictionary);
        }
Пример #6
0
        public async Task <string> CreateSnapShotAsync()
        {
            try
            {
                if (IsDBExistis())
                {
                    CreateDBSnapshotRequest createDBSnapshotRequest = new CreateDBSnapshotRequest();
                    createDBSnapshotRequest.DBSnapshotIdentifier = "snapjaguar-rds";//"rds:jaguar-2019-05-11-11-17";
                    createDBSnapshotRequest.DBInstanceIdentifier = "jaguar";
                    //var response = amazonRDSClient.CreateDBSnapshot(createDBSnapshotRequest);

                    ModifyDBSnapshotAttributeRequest modifyDBSnapshotAttributeRequest = new ModifyDBSnapshotAttributeRequest();
                    modifyDBSnapshotAttributeRequest.DBSnapshotIdentifier = "rds-jaguar";
                    modifyDBSnapshotAttributeRequest.AttributeName        = "Restore";
                    List <string> awsAccounts = new List <string>();
                    awsAccounts.Add("739981354746");
                    modifyDBSnapshotAttributeRequest.ValuesToAdd = awsAccounts;

                    var shareResponse = await amazonRDSClient.ModifyDBSnapshotAttributeAsync(modifyDBSnapshotAttributeRequest);

                    CopyDBSnapshotRequest dBSnapshotRequest = new CopyDBSnapshotRequest();
                    dBSnapshotRequest.SourceDBSnapshotIdentifier = "rds:jaguar-2019-05-12-03-09";
                    dBSnapshotRequest.TargetDBSnapshotIdentifier = "rds-jaguar";

                    //var response2 =await amazonRDSClient.CopyDBSnapshotAsync(dBSnapshotRequest);

                    if (shareResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                    {
                        return("Success");
                    }
                    return("Failed");
                }

                return("");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #7
0
 public CreateDBSnapshotResponse CreateDBSnapshot(CreateDBSnapshotRequest request)
 {
     return(this.Invoke <CreateDBSnapshotResponse>(ConvertCreateDBSnapshot(request)));
 }