Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Windows batch script for creating daily EC2 snapshots for a volume and deleting old ones.
set AWS_VOLUME=vol-12345678
:: Create snapshot for this volume
CMD /C ec2-create-snapshot %AWS_VOLUME% -d "Daily Snapshot"
:: Find old snapshots for this volume, sort them by date desc
ec2-describe-snapshots -F "volume-id=%AWS_VOLUME%" -F "status=completed"|find /I "Daily Snapshot"|sort /R /+49>%AWS_HOME%\snapshots.txt
:: Loop over old snapshots, skip the first 10, delete the rest
for /f "tokens=2 skip=%AWS_SNAPSHOT_KEEP%" %%s in (%AWS_HOME%\snapshots.txt) do ec2-delete-snapshot %%s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.