Windows batch script for creating daily EC2 snapshots for a volume and deleting old ones.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
|:: 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|