0

We are running this script below and this doesnt delete anything older than one day what are we missing ?

We got the script from github.com/colinbjohnson/aws-missing-tools/tree/master/ec2-automate-backup

ec2-automate-backup -r "us-west-2" -s tag -t "Backup,Values=true" -k 1 -p -h > /data/scripts/ec2-automate-backup.log

Snapshots taken by ec2-automate-backup will be eligible for purging after the following date (the purge after date given in seconds from epoch): 1458239434. Tagging Snapshot snap-b9fffbe6 with the following Tags: Key=CreatedBy,Value=ec2-automate-backup Key=InitiatingHost,Value='ip-10-220-5-100' Key=PurgeAfterFE,Value=1458239434 Key=PurgeAllow,Value=true Tagging Snapshot snap-8c457dc9 with the following Tags: Key=CreatedBy,Value=ec2-automate-backup Key=InitiatingHost,Value='ip-10-220-5-100' Key=PurgeAfterFE,Value=1458239434 Key=PurgeAllow,Value=true

Tim Penner
  • 3,551
  • 21
  • 36
modasir
  • 1
  • 2
  • This is resolved. just have to run the command this way. ec2-automate-backup.sh -r "us-west-2" -s tag -t "Backup,Values=true" -k 5 -p -h > /data/scripts/ec2-automate-backup.log – modasir Mar 30 '16 at 23:24

1 Answers1

0

The below cron job entry is working great for me. First take snapshots, then create tags and finally purge the old ones, here you go (every day at 0:00 am):

0 0 * * * /path/to/script/ec2-automate-backup.sh -r "<your-region>" -s tag -t "Backup,Values=true" -k 15 -p -h >> /path/to/log/ec2-automate-backup.log 2>&1

here:

-r - the region that contains the EBS volumes for which you wish to have a snapshot created.

-s - the selection method by which EBS volumes will be selected. Currently supported selection methods are "volumeid" and "tag." The selection method "volumeid" identifies EBS volumes for which a snapshot should be taken whereas the selection method "tag" identifies EBS volumes for which a snapshot should be taken by a filter that utilizes a Key and Value pair.

-t - the "tag" parameter is required if the "method" of selecting EBS volumes for snapshot is by tag (-s tag). The format for tag is key,Values=$desired_values (example: Backup,Values=true) and the correct method for running ec2-automate-backup in this manner is ec2-automate-backup -s tag -t Backup,Values=true". (You have to tag "Backup=true" all the volumes that you want them to backup)

-k - the period after which a snapshot can be purged. For example, running "ec2-automate-backup.sh -v "vol-6d6a0527 vol-636a0112" -k 31" would allow snapshots to be removed after 31 days. purge_after_days creates two tags for each volume that was backed up - a PurgeAllow tag which is set to PurgeAllow=true and a PurgeAfter tag which is set to the present day (in UTC) + the value provided by -k.

-p - the -p flag will purge (meaning delete) all snapshots that were created more than "purge after days" ago. ec2-automate-backup looks at two tags to determine which snapshots should be deleted - the PurgeAllow and PurgeAfter tags. The tags must be set as follows: PurgeAllow=true and PurgeAfter=YYYY-MM-DD where YYYY-MM-DD must be before the present date.

-h - tag snapshots "InitiatingHost" tag to specify which host ran the script

The example tags after the snapshot is created: enter image description here

Bahadir Tasdemir
  • 10,325
  • 4
  • 49
  • 61