bc.build_common_parser(), ], ) args = parser.parse_args() # process common command line arguments log = logging.getLogger("botocross") bc.configure_logging(log, args.log_level) credentials = bc.parse_credentials(args) regions = bc.filter_regions(boto.ec2.regions(), args.region) filter = bc.build_filter(args.filter, args.exclude) # execute business logic log.info("Expire EBS snapshots") for region in regions: try: ec2 = boto.connect_ec2(region=region, **credentials) # NOTE: Not filtering by id allows expiring snapshots of deregistered volumes as well. volumes = ec2.get_all_volumes(filters=filter["filters"]) if filter["excludes"]: exclusions = ec2.get_all_volumes(filters=filter["excludes"]) volumes = bc.filter_list_by_attribute(volumes, exclusions, "id") volume_ids = [volume.id for volume in volumes] if args.resource_ids: volume_ids.extend(args.resource_ids) print region.name + ": " + str(len(volumes)) + " volumes / " + str(len(volume_ids)) + " volume IDs" expire_snapshots(ec2, volume_ids, args.backup_set, args.backup_retention, args.no_origin_safeguard) except boto.exception.BotoServerError, e: log.error(e.error_message)
]) args = parser.parse_args() # process common command line arguments log = logging.getLogger('botocross') bc.configure_logging(log, args.log_level) credentials = bc.parse_credentials(args) regions = bc.filter_regions(boto.ec2.regions(), args.region) filter = bc.build_filter(args.filter, args.exclude) # execute business logic log.info("Expire EBS snapshots") for region in regions: try: ec2 = boto.connect_ec2(region=region, **credentials) # NOTE: Not filtering by id allows expiring snapshots of deregistered volumes as well. volumes = ec2.get_all_volumes(filters=filter['filters']) if filter['excludes']: exclusions = ec2.get_all_volumes(filters=filter['excludes']) volumes = bc.filter_list_by_attribute(volumes, exclusions, 'id') volume_ids = [volume.id for volume in volumes] if args.resource_ids: volume_ids.extend(args.resource_ids) print region.name + ": " + str(len(volumes)) + " volumes / " + str( len(volume_ids)) + " volume IDs" expire_snapshots(ec2, volume_ids, args.backup_set, args.backup_retention, args.no_origin_safeguard) except boto.exception.BotoServerError, e: log.error(e.error_message)
# process common command line arguments log = logging.getLogger('botocross') bc.configure_logging(log, args.log_level) credentials = bc.parse_credentials(args) regions = bc.filter_regions(boto.ec2.regions(), args.region) filter = bc.build_filter(args.filter, args.exclude) # execute business logic log.info("Snapshotting EBS volumes:") # REVIEW: For backup purposes it seems reasonable to only consider all OK vs. FAIL?! exit_code = bc.ExitCodes.OK for region in regions: try: ec2 = boto.connect_ec2(region=region, **credentials) volumes = ec2.get_all_volumes(volume_ids=args.resource_ids, filters=filter['filters']) if filter['excludes']: exclusions = ec2.get_all_volumes(filters=filter['excludes']) volumes = bc.filter_list_by_attribute(volumes, exclusions, 'id') print region.name + ": " + str(len(volumes)) + " volumes" snapshots = create_snapshots(ec2, volumes, args.backup_set, args.description) if args.backup_timeout: try: states = await_snapshots(ec2, snapshots, timeout=args.backup_timeout) if not bc.ec2.SNAPSHOT_STATES_SUCCEEDED.issuperset(states): message = "FAILED to create some snapshots: {0}!".format(format_states(states)) log.error(message) exit_code = bc.ExitCodes.FAIL except bc.BotocrossAwaitTimeoutError, e: