Class: CopySnapshot
- Defined in:
- lib/scripts/ec2/copy_snapshot.rb
Overview
Copy a given snapshot to another region
-
start up instance in source-region, create volume from snapshot, attach volume, and mount it
-
start up instance in destination-region, create empty volume of same size, attache volume, and mount it
-
copy the destination key to the source instance
-
perform an rsynch sync -PHAXaz –rsh “ssh -i /home/$src_user/.ssh/id_$dst_keypair” –rsync-path “sudo rsync” $src_dir/ $dst_user@$dst_public_fqdn:$dst_dir/
-
create a snapshot of the volume
-
clean-up everything
Defined Under Namespace
Classes: CopySnapshotState, DataCopiedState, InitialState, KeyInPlaceState, SnapshotCreatedState, SourceCleanedUpState, SourceInstanceLaunchedState, SourceVolumeReadyState, TargetInstanceLaunchedState, TargetVolumeReadyState
Instance Method Summary collapse
- #check_input_parameters ⇒ Object
-
#initialize(input_params) ⇒ CopySnapshot
constructor
context information needed * the EC2 credentials (see #Ec2Script) * snapshot_id => The ID of the snapshot to be downloaded * target_ec2_handler => The EC2 handler connected to the region where the snapshot is being copied to * source_ssh_username => user name to connect to the source instance (default = root) * source_key_name => Key name of the instance that manages the snaphot-volume in the source region * source_ssh_key_data => Key information for the security group that starts the AMI [if not set, use ssh_key_files] * source_ssh_key_file => Key information for the security group that starts the AMI * target_ssh_username => user name to connect to the target instance (default = root) * target_key_name => Key name of the instance that manages the snaphot-volume in the target region * target_ssh_key_data => Key information for the security group that starts the AMI [if not set, use ssh_key_files] * target_ssh_key_file => Key information for the security group that starts the AMI * source_ami_id => ID of the AMI to start in the source region * target_ami_id => ID of the AMI to start in the target region.
-
#load_initial_state ⇒ Object
Load the initial state for the script.
Methods inherited from Ec2Script
#get_execution_result, #post_message, #register_progress_message_listener, #register_state_change_listener, #start_script
Constructor Details
#initialize(input_params) ⇒ CopySnapshot
context information needed
-
the EC2 credentials (see #Ec2Script)
-
snapshot_id => The ID of the snapshot to be downloaded
-
target_ec2_handler => The EC2 handler connected to the region where the snapshot is being copied to
-
source_ssh_username => user name to connect to the source instance (default = root)
-
source_key_name => Key name of the instance that manages the snaphot-volume in the source region
-
source_ssh_key_data => Key information for the security group that starts the AMI [if not set, use ssh_key_files]
-
source_ssh_key_file => Key information for the security group that starts the AMI
-
target_ssh_username => user name to connect to the target instance (default = root)
-
target_key_name => Key name of the instance that manages the snaphot-volume in the target region
-
target_ssh_key_data => Key information for the security group that starts the AMI [if not set, use ssh_key_files]
-
target_ssh_key_file => Key information for the security group that starts the AMI
-
source_ami_id => ID of the AMI to start in the source region
-
target_ami_id => ID of the AMI to start in the target region
33 34 35 |
# File 'lib/scripts/ec2/copy_snapshot.rb', line 33 def initialize(input_params) super(input_params) end |
Instance Method Details
#check_input_parameters ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/scripts/ec2/copy_snapshot.rb', line 37 def check_input_parameters() local_ec2_helper = Ec2Helper.new(@input_params[:ec2_api_handler]) if !local_ec2_helper.check_open_port('default', 22) raise Exception.new("Port 22 must be opened for security group 'default' to connect via SSH in source-region") end remote_ec2_helper = Ec2Helper.new(@input_params[:target_ec2_handler]) if !remote_ec2_helper.check_open_port('default', 22) raise Exception.new("Port 22 must be opened for security group 'default' to connect via SSH in target-region") end if @input_params[:source_ssh_username] == nil @input_params[:source_ssh_username] = "root" end if @input_params[:target_ssh_username] == nil @input_params[:target_ssh_username] = "root" end end |
#load_initial_state ⇒ Object
Load the initial state for the script. Abstract method to be implemented by extending classes.
56 57 58 |
# File 'lib/scripts/ec2/copy_snapshot.rb', line 56 def load_initial_state() CopySnapshotState.load_state(@input_params) end |