Class: AwsXRegionSync::RdsAutomatedSnapshotSync
- Defined in:
- lib/aws_xregion_sync/rds_automated_snapshot_sync.rb
Instance Attribute Summary
Attributes inherited from AwsSync
Instance Method Summary collapse
- #sync ⇒ Object
- #sync_required? ⇒ Boolean
- #sync_snapshot_to_region(source_region, destination_region, source_snapshot) ⇒ Object
- #validate_config ⇒ Object
Methods inherited from AwsSync
#aws_config, #create_sync_tag, #discover_aws_account_id, #initialize, #parse_config_filters, #parse_sync_tag_value, #sync_tag_indicator
Constructor Details
This class inherits a constructor from AwsXRegionSync::AwsSync
Instance Method Details
#sync ⇒ Object
11 12 13 14 |
# File 'lib/aws_xregion_sync/rds_automated_snapshot_sync.rb', line 11 def sync setup = pre_sync_setup sync_snapshot_to_region setup[:source_region], setup[:destination_region], setup[:snapshot] end |
#sync_required? ⇒ Boolean
16 17 18 19 20 |
# File 'lib/aws_xregion_sync/rds_automated_snapshot_sync.rb', line 16 def sync_required? setup = pre_sync_setup sync = needs_sync? setup[:destination_region], setup[:source_region], setup[:snapshot], discover_aws_account_id sync[:sync_required] end |
#sync_snapshot_to_region(source_region, destination_region, source_snapshot) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/aws_xregion_sync/rds_automated_snapshot_sync.rb', line 22 def sync_snapshot_to_region source_region, destination_region, source_snapshot # The way automated snapshot copying seems to work is as long as you're copying snapshot from the same db instance between regions # every snapshot you copy from the source region after the first one is simply just an incremental copy. Because of this we # should copy the latest snapshot # This first thing we should do is look for a sync tag in the destination snapshot (if present) and see we've already synced this # snapshot-id (or if the id is outdated) aws_account_id = discover_aws_account_id sync = needs_sync?(destination_region, source_region, source_snapshot, aws_account_id) if sync[:sync_required] sr = region(source_region) result = destination_region.client.copy_db_snapshot source_db_snapshot_identifier: arn(sr, aws_account_id, source_snapshot.id), target_db_snapshot_identifier: sanitize_snapshot_id(source_snapshot.id) if result[:db_snapshot_identifier] destination_snapshot_id = result[:db_snapshot_identifier] # Move the source snapshot's created timestamp and id to the destination snapshot's sync tag so that we know the last time # the snapshot was synced and what region it was synced from. Also, log the sync against the source too so we have tangible evidence # that it was synced just by looking at it as well. dr = region(destination_region) dest_sync_tag = create_sync_tag sr, source_snapshot.id, timestamp: source_snapshot.created_at, sync_subtype: "From" source_sync_tag = create_sync_tag dr, destination_snapshot_id, timestamp: source_snapshot.created_at destination_region.client. resource_name: arn(dr, aws_account_id, result[:db_snapshot_identifier]), tags: [dest_sync_tag] source_region.client. resource_name: arn(sr, aws_account_id, source_snapshot.id), tags: [source_sync_tag] # We'll now clean up older snapshots if necessary cleanup_old_snapshots sync[:snapshots], max_snapshots, destination_region end end destination_snapshot_id end |
#validate_config ⇒ Object
4 5 6 7 8 9 |
# File 'lib/aws_xregion_sync/rds_automated_snapshot_sync.rb', line 4 def validate_config raise AwsXRegionSyncConfigError, "The #{self.sync_name} configuration must provide a 'db_instance' option to use to locate automated snapshots." unless config['db_instance'] && config['db_instance'].length > 0 # This call will raise if there's an invalid value..so just call it right now max_snapshots super end |