适用于SQL Server的AWS RDS云形成模板

时间:2016-07-13 17:48:30

标签: amazon-web-services aws-rds

我很擅长使用AWS的东西。我想拍摄当前SQL Server实例的快照,并使用AWS Cloud Formation创建具有相同快照的另一个实例(以便迁移所有现有数据库和数据)和更多存储容量。

我在亚马逊上看到过像https://s3-us-west-2.amazonaws.com/cloudformation-templates-us-west-2/RDS_MySQL_With_Read_Replica.template

这样的内容

但无法根据我的需要量身定制。我不想要所有的EC2实例和额外的东西。只是我现有的快照ID和将使用快照ID克隆的新SQL Server RDS实例详细信息

1 个答案:

答案 0 :(得分:1)

使用CLI或PowerShell手动拍摄现有数据库的快照,并记下DBSnapshotIdentifier。

使用PowerShell看起来像这样:

New-RDSDBSnapshot -DBSnapshotIdentifier "NameOfYourNewSnapshot" -DBInstanceIdentifier "YourExistingDbIdentifier"

好的,现在您有快照,您需要更改CloudFormation模板以使用DBSnapshotIdentifier。

更改现有模板以创建SqlServer数据库并指定新属性DBSnapshotIdentifier

"MyDB" : {
 "Type" : "AWS::RDS::DBInstance",
 "Properties" : {
     "DBSecurityGroups" : [
        {"Ref" : "MyDbSecurityByEC2SecurityGroup"}, {"Ref" : "MyDbSecurityByCIDRIPGroup"} ],
     "AllocatedStorage" : "20",
     "DBInstanceClass" : "db.t2.micro",
     "Engine" : "sqlserver-ex",
     "MasterUsername" : "MyName",
     "MasterUserPassword" : "MyPassword",
     "DBSnapshotIdentifier" : "NameOfYourNewSnapshot"
 }
}

应该是这样,当您运行堆栈时,它将从快照中删除并重新创建数据库,因此请确保满足停机时间。

文档:

http://docs.aws.amazon.com/powershell/latest/reference/Index.html
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#cfn-rds-dbinstance-dbsnapshotidentifier