cloudbud
cloudbud

Reputation: 3288

How to delete ec2-snapshot that are 1 days older using a batch script?

I want to delete snapshots of volumes using a batch script, snapshots which are created on previous day.

for /f "tokens=2 skip=%AWS_SNAPSHOT_KEEP%" %%s in (%EC2_HOME%\snapshots.txt) do call ec2-delete-snapshot %%s

This is deleting all the snapshot and keeping only one snapshot because AWS_SNAPSHOT_KEEP=1.

Please help me out.

Any suggestion is appreciated.

Upvotes: 0

Views: 406

Answers (1)

Endoro
Endoro

Reputation: 37589

you can use robocopy's /minage and /maxage parameters to select the files. Code example:

for /f "delims=" %%a in ('robocopy "%cd%" "%temp%" * /minage:1 /maxage:2 /l /np /fp /njh /njs /ndl /ns^|findstr /riv /c:"^$" /c:"\*EXTRA File"') do echo %%~a

Upvotes: 2

Related Questions