How to find latest or most recent AWS RDS snapshot?
How to find latest or most recent AWS RDS snapshot?
I can call aws rds describe-db-snapshots --db-instance-identifier {my_db_instance}
and sort all automated snapshots to find the most recently created one but I was hoping someone has a better idea out there.
aws rds describe-db-snapshots --db-instance-identifier {my_db_instance}
4 Answers
4
I know this is old, but I was needing to know the same information and was able to construct the following which will then just give me the snapshot name. It doesn't totally answer your question about emphatically finding the latest snapshot but in this example might give you some better direction.
aws rds describe-db-snapshots --db-instance-identifier prd --snapshot-type automated --query "DBSnapshots[?SnapshotCreateTime>='2017-06-05'].DBSnapshotIdentifier"
To break it down with the options
--db-instance-identifier
(put in your instance name your are looking for)
--db-instance-identifier
--snapshot-type
(I put in automated to find the automated backups)
--snapshot-type
--query "DBSnapshots[?SnapshotCreateTime>='2017-06-05'].DBSnapshotIdentifier"
--query "DBSnapshots[?SnapshotCreateTime>='2017-06-05'].DBSnapshotIdentifier"
(This is what I used to refine my search as we do daily backups, I just look for the snapshot create time to be greater than today and by giving the .DBSnapshotIdentifier gives me back just the name.
Hopefully this will help somebody else out.
For me, this one works:
aws rds describe-db-snapshots
--query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]"
The query parameter sorts them automatically and returns only the most recent one.
If only the Arn is needed, this one might help:
aws rds describe-db-snapshots
--query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]|DBSnapshotArn"
--output text
And all that for a specific database instance:
aws rds describe-db-snapshots
--db-instance-identifier={instance identifier}
--query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]|DBSnapshotArn"
--output text
As at 31th October 2014, it looks like you can use the --t
flag to list only automated backups.
--t
http://docs.aws.amazon.com/AmazonRDS/latest/CommandLineReference/CLIReference-cmd-DescribeDBSnapshots.html
From there, you should be able to parse the output to determine your latest snapshots.
rds-describe-db-snapshots --t automated
DBSNAPSHOT rds:<NAME>-2016-08-09-17-12
There is no any other more simple way around for this.
My way:
> aws rds describe-db-snapshots --db-instance-identifier ${yourDbIdentifier} --query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]|DBSnapshotIdentifier"
> "rds:dbName-2018-06-20-00-07"
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Works like a charm. Learn something new about AWS query every day. I believe this should be the accepted answer. Thanks!
– Brent
Jun 29 at 15:56