skip to Main Content

I have a working command to fetch manual snapshots info. How can I use the query option to filter out only snapshots older than 30 days?

aws rds describe-db-cluster-snapshots
–query "DBClusterSnapshots[*].[DBClusterSnapshotIdentifier, DBClusterIdentifier, SnapshotCreateTime, Status, Engine]"
–output table

Thanks very much

2

Answers


  1. Chosen as BEST ANSWER

    Your commands did not work on both Cloudshell and EC2 Linux. Here are outputs

    #Cloudshell

    [cloudshell-user@ip-10-130-70-166 ~]$ aws rds describe-db-cluster-snapshots --query "DBClusterSnapshots[?SnapshotCreateTime<='$(date -v -30d '+%Y-%m-%d')'].[DBClusterSnapshotIdentifier, DBClusterIdentifier, SnapshotCreateTime, Status, Engine]"

    date: invalid option -- 'v'

    Try 'date --help' for more information.

    []

    [cloudshell-user@ip-10-130-70-166 ~]$ aws rds describe-db-cluster-snapshots --query "DBClusterSnapshots[?SnapshotCreateTime<='$(date -30d '+%Y-%m-%d')'].[DBClusterSnapshotIdentifier, DBClusterIdentifier, SnapshotCreateTime, Status, Engine]"

    date: invalid option -- '3'

    Try 'date --help' for more information.

    #EC2 Linux

    [ec2-user@ip-172-31-26-154 ~]$ aws rds describe-db-cluster-snapshots --query "DBClusterSnapshots[?SnapshotCreateTime<='$(date -v -30d '+%Y-%m-%d')'].[DBClusterSnapshotIdentifier, DBClusterIdentifier, SnapshotCreateTime, Status, Engine]"

    date: invalid option -- 'v'

    Try 'date --help' for more information.

    []

    [ec2-user@ip-172-31-26-154 ~]$ aws rds describe-db-cluster-snapshots --query "DBClusterSnapshots[?SnapshotCreateTime<='$(date -30d '+%Y-%m-%d')'].[DBClusterSnapshotIdentifier, DBClusterIdentifier, SnapshotCreateTime, Status, Engine]"

    date: invalid option -- '3'

    Try 'date --help' for more information.

    []

    It does not like -v option. Is there any other option I should try?

    Thanks much


  2. You can try something like this:

    aws rds describe-db-cluster-snapshots --query "DBClusterSnapshots[?SnapshotCreateTime<='$(date -v -30d '+%Y-%m-%d')'].[DBClusterSnapshotIdentifier, DBClusterIdentifier, SnapshotCreateTime, Status, Engine]"
    

    Depending on your operating system, it might need to be: date --date='-30 days' '+%Y-%m-%d')

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search