简体   繁体   English

如何使用 AWS CLI 获取 RDS 数据库实例的最新快照的名称?

[英]How can I get the name of the most recent snapshot for an RDS DB instance using the AWS CLI?

Using the AWS CLI, how can I get the most recent snapshot for a particular DB instance?使用 AWS CLI,如何获取特定数据库实例的最新快照?

I can get them through the GUI easily but I'd like to automate it.我可以轻松地通过 GUI 获取它们,但我想将其自动化。

You can use the aws rds describe-db-snapshots CLI command to get a list of DB snapshots, and then run a local query using --query to get the latest DB snapshot using the SnapshotCreateTime field.您可以使用aws rds describe-db-snapshots CLI 命令获取数据库快照列表,然后使用--query运行本地查询以使用SnapshotCreateTime字段获取最新的数据库快照。

SnapshotCreateTime -> (timestamp) SnapshotCreateTime ->(时间戳)

Specifies when the snapshot was taken in Coordinated Universal Time (UTC).指定以协调世界时 (UTC) 拍摄快照的时间。 Changes for the copy when the snapshot is copied.复制快照时副本的更改。

Something like this:像这样的东西:

aws rds describe-db-snapshots \
    --db-instance-identifier your-id \
    --query "sort_by(DBSnapshots, &SnapshotCreateTime)[-1].{id:DBSnapshotIdentifier,time:SnapshotCreateTime}"

Note that this query sorts snapshots by their ascending SnapshotCreateTime and then simply takes the last one in the list (as dictated by [-1]), which will be the one that was last created.请注意,此查询按 SnapshotCreateTime 的升序对快照进行排序,然后简单地获取列表中的最后一个(如 [-1] 所指示),这将是最后创建的那个。

[Added] if you're looking for snapshots of Aurora DB clusters then you'd have to use describe-db-cluster-snapshots in place of describe-db-snapshots , but otherwise the process is similar: use DBClusterSnapshots and DBClusterSnapshotIdentifier (in place of DBSnapshots and DBSnapshotIdentifier ). [已添加] 如果您要查找 Aurora 数据库集群的快照,则必须使用describe-db-cluster-snapshots代替describe-db-snapshots ,否则过程类似:使用DBClusterSnapshotsDBClusterSnapshotIdentifier (在DBSnapshotsDBSnapshotIdentifier )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取使用 AWS CLI 手动创建的 RDS 数据库实例的所有快照的名称? - How can I get the name of the all snapshot of RDS DB instance created manually using the AWS CLI? 如何通过 id 获取最新的共享 AWS RDS 快照? - How to get the most recent shared AWS RDS snapshot by id? 如何从最新快照或从头开始创建RDS实例 - How to create an RDS instance from the most recent snapshot or from scratch 如何查找最新或最新的 AWS RDS 快照? - How to find latest or most recent AWS RDS snapshot? 如何指向我最近的 RDS 数据库快照的标识符? - How do I point to the the identifier of my most recent RDS DB snapshot? 如何使用AWS CLI列出数据库引擎oracle-ee的所有Amazon RDS数据库实例类 - How do I list all Amazon RDS DB Instance Classes for DB engine oracle-ee using AWS CLI Ansible - 从最近的现有快照创建 RDS 实例 - Ansible - Create RDS Instance from most recent existing snapshot AWS-CLI:将 RDS Aurora 数据库实例创建到从快照创建的现有集群中 - AWS-CLI : Create RDS Aurora DB instance into existing cluster created from snapshot 如何在 Terraform 中获取 AWS RDS 编写器实例 - How I can get the AWS RDS writer instance in Terraform 如何使用 AWS CLI 启动 RDS 数据库实例? - How to start RDS database instance using AWS CLI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM