-
-
Save juno/1096451 to your computer and use it in GitHub Desktop.
Revisions
-
juno revised this gist
Jul 21, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -33,5 +33,5 @@ ## 指定世代分を残して古いスナップショットを削除します snapshots_to_remain = snapshots.sort_by { |snap| snap.start_time }.reverse[0, history] snapshots_to_delete = snapshots.to_a - snapshots_to_remain.to_a snapshots_to_delete.each { |snap| snap.delete } -
juno revised this gist
Jul 21, 2011 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -32,5 +32,6 @@ snapshots = ec2.snapshots.filter('volume-id', vol_id) ## 指定世代分を残して古いスナップショットを削除します snapshots_to_remain = snapshots.sort_by { |snap| snap.start_time }.reverse[0, history] snapshots_to_delete = snapshots - snapshots_to_remain snapshots_to_delete.each { |snap| snap.delete } -
juno revised this gist
Jul 21, 2011 . 1 changed file with 6 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- require 'rubygems' require 'aws-sdk' @@ -7,8 +8,8 @@ ## 引数チェック unless ARGV.size == 4 puts 'How to Use: create_ebs_snapshots.rb <aws_region_url> <num> <volume_id> <snapshot_description>' exit 0 end ## 引数からスナップショット保存設定を行います @@ -18,8 +19,7 @@ snapshot_memo = ARGV[3] ## スナップショットのdescriptionを作成します snapshot_description = "#{snapshot_memo} #{Time.now.strftime('%Y/%m/%d %H:%M')}" ## EC2インスターフェースを作成するために認証を行います AWS.config(:access_key_id => ACCESS_KEY, :secret_access_key => SECRET_KEY, :ec2_endpoint => aws_region) @@ -29,16 +29,8 @@ ec2.snapshots.create(:volume => ec2.volumes[vol_id], :description => snapshot_description) ## 現在保存されている対象ボリュームから作成されたスナップショットをリスト化する snapshots = ec2.snapshots.filter('volume-id', vol_id) ## 指定世代分を残して古いスナップショットを削除します snapshots_to_delete = snapshots.sort_by { |snap| snap.start_time }.reverse[0,history] snapshots_to_delete.each { |snap| snap.delete } -
okochang revised this gist
Jul 21, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ ## 引数チェック unless ARGV.size == 4 puts 'How to Use: awssdk_create_snapshot.rb <aws_region_url> <num> <volume_id> <snapshot_description>' exit 0 end -
okochang revised this gist
Jul 21, 2011 . No changes.There are no files selected for viewing
-
okochang created this gist
Jul 21, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ require 'rubygems' require 'aws-sdk' ## アクセスIDとシークレットアクセスキーを指定します ACCESS_KEY = 'SET UP YOUR ACCESS KEY' SECRET_KEY = 'SET UP YOUR SECRET KEY' ## 引数チェック unless ARGV.size == 4 puts 'How to Use: create_ebs_snapshots.rb <aws_region_url> <num> <volume_id> <snapshot_description>' exit 0 end ## 引数からスナップショット保存設定を行います aws_region = ARGV[0] history = ARGV[1].to_i vol_id = ARGV[2] snapshot_memo = ARGV[3] ## スナップショットのdescriptionを作成します t = Time.now snapshot_description = "#{snapshot_memo} #{t.strftime('%Y/%m/%d %H:%M')}" ## EC2インスターフェースを作成するために認証を行います AWS.config(:access_key_id => ACCESS_KEY, :secret_access_key => SECRET_KEY, :ec2_endpoint => aws_region) ec2 = AWS::EC2.new ## 対象ボリュームからスナップショットを作成します ec2.snapshots.create(:volume => ec2.volumes[vol_id], :description => snapshot_description) ## 現在保存されている対象ボリュームから作成されたスナップショットをリスト化する snapshot_list = [] snapshots = ec2.snapshots.filter('volume-id', vol_id) snapshots.each { |snap| snapshot_list << snap.id } ## 指定世代分を残して古いスナップショットを削除します delete_list = [] snapshot_list.each { |snap| delete_list << ec2.snapshots[snap] } delete_list = delete_list.sort_by { |snap| snap.start_time }.reverse delete_list.each_with_index { |snap, i| unless i < history snap.delete end }