public static void Backup(string name, string description, string volumeid, string volumename, string instancename, string expires)
{
Console.WriteLine(" Creating snapshot of " + volumeid + " / " + volumename + " / " + instancename);
AmazonEC2Client ec2 = Ec2Helper.CreateClient();
CreateSnapshotRequest rq = new CreateSnapshotRequest();
rq.VolumeId = volumeid;
rq.Description = description;
CreateSnapshotResponse rs = ec2.CreateSnapshot(rq);
string snapshotid = rs.Snapshot.SnapshotId;
// build tags for snapshot
CreateTagsRequest rqq = new CreateTagsRequest();
rqq.Resources.Add(snapshotid);
rqq.Tags.Add(new Tag { Key = "Name", Value = name });
rqq.Tags.Add(new Tag { Key = "source", Value = "scheduler" });
rqq.Tags.Add(new Tag { Key = "instance", Value = instancename });
rqq.Tags.Add(new Tag { Key = "volume", Value = volumename });
rqq.Tags.Add(new Tag { Key = "expires", Value = expires.ToString() });
// get tags from volume to be applied to snapshot
DescribeTagsRequest trq = new DescribeTagsRequest();
trq.Filters.Add(new Filter() { Name = "resource-id", Values = new List<string>() { volumeid } });
DescribeTagsResponse trs = ec2.DescribeTags(trq);
foreach (TagDescription t in trs.Tags)
{
if(t.Key!="nextSnapshot" && t.Key!="lastSnapshot" && t.Key!="Name")
rqq.Tags.Add(new Tag { Key = t.Key, Value = t.Value});
}
// apply tags to snapshopt
var createTagResponse = ec2.CreateTags(rqq);
}