Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --delete-delay DELAY_IN_SECONDS option. #12

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions ec2-expire-snapshots
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ my $keep_all_since = undef;
my $expiration_tag_name = undef;
my $expiration_tag_optional = undef;

my $delete_delay = undef;

Getopt::Long::config('no_ignore_case');
Getopt::Long::config('no_auto_abbrev');
GetOptions(
'help|?' => \$Help,
'debug' => \$Debug,
'quiet' => \$Quiet,
'noaction' => \$Noaction,
'h|help|?' => \$Help,
'd|debug' => \$Debug,
'q|quiet' => \$Quiet,
'n|noaction' => \$Noaction,

'aws-access-key-id=s' => \$aws_access_key_id,
'aws-secret-access-key=s' => \$aws_secret_access_key,
Expand All @@ -68,6 +71,8 @@ GetOptions(
'keep-all-since=s' => \$keep_all_since,
'expiration-tag-name=s' => \$expiration_tag_name,
'expiration-tag-optional' => \$expiration_tag_optional,

'delete-delay=i' => \$delete_delay
) or pod2usage(2);

my $filesystem_frozen = 0;
Expand Down Expand Up @@ -250,7 +255,13 @@ sub expire_snapshots_for_volume {
" Deleting $count_to_delete snapshot",
($count_to_delete == 1 ? "" : "s"),"\n";

my $index = 0;
for my $snapshot ( @$snapshots_to_delete ) {
if ( $index > 0 && $delete_delay ) {
$Quiet or warn "$Prog: Sleeping $delete_delay second/s between deletes\n";
sleep $delete_delay;
}

my $snapshot_id = $snapshot->{snapshot_id};
$Quiet or warn "$Prog: $volume_id: Deleting snapshot: $snapshot_id (",
$snapshot->start_time, ")\n";
Expand All @@ -264,6 +275,8 @@ sub expire_snapshots_for_volume {
ec2_error_message($@);
}
}

$index++;
}
}

Expand Down Expand Up @@ -607,6 +620,12 @@ use is for when snapshots are copied across regions. This is so
a consistent expiration schedule can be kept, without regards to
the new volume-id generated each time a copy is made.

=item C<--delete-delay DELAY_IN_SECONDS>

Specifies the number of seconds to wait between deleting
snapshots. Allows ec2-expire-snapshots to run without hitting
the AWS rate limiter.

=item C<--keep-most-recent COUNT>

=item C<--keep-all-since DATETIME> [NOT YET IMPLEMENTED]
Expand Down