RDSの最新の自動取得 snapshot を取得する
$ aws rds describe-db-snapshots --snapshot-type automated | jq '.DBSnapshots | sort_by(.SnapshotCreateTime) | reverse | .[0]'
{
"Engine": "mysql",
"SnapshotCreateTime": "2016-09-25T18:46:55.366Z",
"AvailabilityZone": "ap-northeast-1a",
"PercentProgress": 100,
"MasterUsername": "root",
"Encrypted": false,
"LicenseModel": "general-public-license",
"StorageType": "gp2",
"Status": "available",
"VpcId": "vpc-xxxxxxxx",
"DBSnapshotIdentifier": "rds:test-db-2016-09-25-18-46",
"InstanceCreateTime": "2014-12-09T07:15:17.894Z",
"OptionGroupName": "default:mysql-5-6",
"AllocatedStorage": 1000,
"EngineVersion": "5.6.19a",
"SnapshotType": "automated",
"Port": 3306,
"DBInstanceIdentifier": "test-db"
}
# 該当する snapshot がない場合は null
$ aws rds describe-db-snapshots --snapshot-type automated | jq '.DBSnapshots | sort_by(.SnapshotCreateTime) | reverse | .[0]'
null
$ echo $?
0
Aurora の場合(snapshot-type manual)
$ aws rds describe-db-cluster-snapshots --snapshot-type manual | jq '.DBClusterSnapshots | sort_by(.SnapshotCreateTime) | reverse | .[0]'
{
"Engine": "aurora",
"SnapshotCreateTime": "2016-06-27T07:52:46.842Z",
"VpcId": "vpc-xxxxxxxx",
"DBClusterIdentifier": "test-db",
"MasterUsername": "root",
"LicenseModel": "aurora",
"Status": "available",
"PercentProgress": 100,
"DBClusterSnapshotIdentifier": "test-db-snapshot",
"ClusterCreateTime": "2016-06-20T08:59:26.788Z",
"AllocatedStorage": 1,
"SnapshotType": "manual",
"AvailabilityZones": [
"ap-northeast-1a",
"ap-northeast-1c"
],
"Port": 0
}
# 該当する snapshot がない場合は null
$ aws rds describe-db-cluster-snapshots --snapshot-type manual | jq '.DBClusterSnapshots | sort_by(.SnapshotCreateTime) | reverse | .[0]'
null
$ echo $?
0