[英]How to find latest or most recent AWS RDS snapshot?
我可以調用aws rds describe-db-snapshots --db-instance-identifier {my_db_instance}
並對所有自動快照進行排序以找到最近創建的快照,但我希望有人有更好的想法。
對我來說,這有效:
aws rds describe-db-snapshots \
--query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]"
query參數自動對它們進行排序,並僅返回最新的參數。
如果只需要Arn,這可能會有所幫助:
aws rds describe-db-snapshots \
--query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]|DBSnapshotArn" \
--output text
以及特定數據庫實例的所有內容:
aws rds describe-db-snapshots \
--db-instance-identifier={instance identifier} \
--query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]|DBSnapshotArn" \
--output text
我知道這很舊,但是我需要知道相同的信息,並且能夠構造以下內容,然后將其命名為快照名稱。 它並不能完全回答您有關如何着重查找最新快照的問題,但是在本示例中,它可能會為您提供更好的指導。
aws rds describe-db-snapshots --db-instance-identifier prd --snapshot-type automated --query "DBSnapshots[?SnapshotCreateTime>='2017-06-05'].DBSnapshotIdentifier"
用選項分解
--db-instance-identifier
(輸入您要查找的實例名稱)
--snapshot-type
(我放入了自動查找自動備份的位置)
--query "DBSnapshots[?SnapshotCreateTime>='2017-06-05'].DBSnapshotIdentifier"
(這是我每天進行備份時用來完善搜索的內容,我只是在尋找快照創建時間要比今天更長,並且通過提供.DBSnapshotIdentifier來給我重新命名。
希望這可以幫助其他人。
我的方式:
> aws rds describe-db-snapshots --db-instance-identifier ${yourDbIdentifier} --query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]|DBSnapshotIdentifier"
> "rds:dbName-2018-06-20-00-07"
截至2014年10月31日,您似乎可以使用--t
標志僅列出自動備份。
從那里,您應該能夠解析輸出以確定最新的快照。
rds-describe-db-snapshots --t automated
DBSNAPSHOT rds:<NAME>-2016-08-09-17-12
為此,沒有其他更簡單的方法了。
從快照恢復數據庫時出現此錯誤,該ID是通過上述方法的命令獲取的ID:
An error occurred (InvalidParameterValue) when calling the RestoreDBInstanceFromDBSnapshot operation: Invalid snapshot identifier: "rds:dev-mysql-rds1-2018-10-06-01-09"
因此,我修改了上面的查詢以使其對我有用,這是一個對我有用的查詢,用於獲取與restore-db-instance-from-db-snapshot
一起使用的最新restore-db-instance-from-db-snapshot
aws rds describe-db-snapshots --query "DBSnapshots[?DBInstanceIdentifier=='MASTER_INSTANCE_IDENTIFIER']" | jq -r 'max_by(.SnapshotCreateTime).DBSnapshotIdentifier'
如果有人在尋找cluster
命令:
aws rds describe-db-cluster-snapshots --db-cluster-identifier prod --snapshot-type automated --query "DBClusterSnapshots[?SnapshotCreateTime>='2017-06-05'].DBClusterSnapshotIdentifier"
aws rds describe-db-cluster-snapshots --snapshot-type=automated --query="max_by(DBClusterSnapshots,&SnapshotCreateTime)"
這適用於 2022.08
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.