Beispiel #1
0
    def main(self):
        """ main function """

        logger.info('Starting snapshot trimming')

        total_expired_snapshots = 0
        total_deleted_snapshots = 0
        total_orphans_deleted = 0
        total_deletion_errors = 0

        if self.args.aws_creds_profile:
            os.environ['AWS_PROFILE'] = self.args.aws_creds_profile

        if not ebs_snapshotter.EbsSnapshotter.is_region_valid(
                self.args.region):
            logger.info("Invalid region")
            sys.exit(1)
        else:
            logger.info("Region: %s:", self.args.region)
            ss = ebs_snapshotter.EbsSnapshotter(self.args.region, verbose=True)

            (expired_snapshots, deleted_snapshots, deleted_orphans,
             snapshot_deletion_errors) = ss.trim_snapshots(
                 hourly_backups=self.args.keep_hourly,
                 daily_backups=self.args.keep_daily,
                 weekly_backups=self.args.keep_weekly,
                 monthly_backups=self.args.keep_monthly,
                 dry_run=self.args.dry_run,
                 delete_orphans_older_than=self.args.delete_orphans_older_than,
                 sleep_between_delete=self.args.sleep_between_delete)

            num_deletion_errors = len(snapshot_deletion_errors)

            total_expired_snapshots += len(expired_snapshots)
            total_deleted_snapshots += len(deleted_snapshots)
            total_orphans_deleted += deleted_orphans
            total_deletion_errors += num_deletion_errors

            if num_deletion_errors > 0:
                logger.info("  Snapshot Deletion errors (%d):",
                            num_deletion_errors)
                for cur_err in snapshot_deletion_errors:
                    logger.info("%s", cur_err)

        logger.info("Total number of expired snapshots: %d",
                    total_expired_snapshots)
        logger.info("Total number of deleted snapshots: %d",
                    total_deleted_snapshots)
        logger.info("Total number of orphaned snapshots deleted: %d",
                    total_orphans_deleted)
        logger.info("Total number of snapshot deletion errors: %d",
                    total_deletion_errors)

        if self.args.dry_run:
            logger.info("*** DRY RUN, NO ACTION TAKEN ***")
        else:
            logger.debug('Sending values to zabbix')
            TrimmerCli.report_to_zabbix(total_expired_snapshots,
                                        total_deleted_snapshots,
                                        total_deletion_errors)
    def main(self):
        """ main function """

        total_expired_snapshots = 0
        total_deleted_snapshots = 0
        total_orphans_deleted = 0
        total_deletion_errors = 0

        if self.args.aws_creds_profile:
            os.environ['AWS_PROFILE'] = self.args.aws_creds_profile

        if not ebs_snapshotter.EbsSnapshotter.is_region_valid(
                self.args.region):
            print "Invalid region"
            sys.exit(1)
        else:
            print "Region: %s:" % self.args.region
            ss = ebs_snapshotter.EbsSnapshotter(self.args.region, verbose=True)

            (expired_snapshots, deleted_snapshots, deleted_orphans,
             snapshot_deletion_errors) = ss.trim_snapshots(
                 hourly_backups=self.args.keep_hourly,
                 daily_backups=self.args.keep_daily,
                 weekly_backups=self.args.keep_weekly,
                 monthly_backups=self.args.keep_monthly,
                 dry_run=self.args.dry_run,
                 delete_orphans_older_than=self.args.delete_orphans_older_than)

            num_deletion_errors = len(snapshot_deletion_errors)

            total_expired_snapshots += len(expired_snapshots)
            total_deleted_snapshots += len(deleted_snapshots)
            total_orphans_deleted += deleted_orphans
            total_deletion_errors += num_deletion_errors

            if num_deletion_errors > 0:
                print "  Snapshot Deletion errors (%d):" % num_deletion_errors
                for cur_err in snapshot_deletion_errors:
                    print "    %s" % cur_err

        print
        print "       Total number of expired snapshots: %d" % total_expired_snapshots
        print "       Total number of deleted snapshots: %d" % total_deleted_snapshots
        print "       Total number of orphaned snapshots deleted: {}".format(
            total_orphans_deleted)
        print "Total number of snapshot deletion errors: %d" % total_deletion_errors
        print

        print "Sending results to Zabbix:"
        if self.args.dry_run:
            print "  *** DRY RUN, NO ACTION TAKEN ***"
        else:
            TrimmerCli.report_to_zabbix(total_expired_snapshots,
                                        total_deleted_snapshots,
                                        total_deletion_errors)
Beispiel #3
0
    def main(self):
        """ main function """

        logger.info('Starting snapshot creation')

        total_snapshottable_vols = 0
        total_snapshots_created = 0
        total_snapshot_creation_errors = 0

        if self.args.aws_creds_profile:
            os.environ['AWS_PROFILE'] = self.args.aws_creds_profile

        script_name = os.path.basename(__file__)

        if not ebs_snapshotter.EbsSnapshotter.is_region_valid(
                self.args.region):
            logger.info("Invalid region")
            sys.exit(1)
        else:
            logger.info("Region: %s:", self.args.region)
            ss = ebs_snapshotter.EbsSnapshotter(self.args.region, verbose=True)

            avail_vols, snapshots_created, snapshot_creation_errors = \
                ss.create_snapshots(self.args.with_schedule, script_name, \
                    sleep_between_snaps=self.args.sleep_between_snaps, dry_run=self.args.dry_run)

            num_creation_errors = len(snapshot_creation_errors)

            total_snapshottable_vols += len(avail_vols)
            total_snapshots_created += len(snapshots_created)
            total_snapshot_creation_errors += num_creation_errors

            if num_creation_errors > 0:
                logger.info("Snapshot Creation errors (%d):",
                            num_creation_errors)
                for cur_err in snapshot_creation_errors:
                    logger.info("%s", cur_err)

        logger.info("Total number of snapshottable volumes: %d",
                    total_snapshottable_vols)
        logger.info("Total number of snapshots created: %d",
                    total_snapshots_created)
        logger.info("Total number of snapshots creation errors: %d",
                    total_snapshot_creation_errors)

        if self.args.dry_run:
            logger.info("*** DRY RUN, NO ACTION TAKEN ***")
        else:
            logger.debug('Sending values to zabbix')
            self.report_to_zabbix(total_snapshottable_vols,
                                  total_snapshots_created,
                                  total_snapshot_creation_errors)
Beispiel #4
0
    def main(self):
        """ main function """

        total_snapshottable_vols = 0
        total_snapshots_created = 0
        total_snapshot_creation_errors = 0

        if self.args.aws_creds_profile:
            os.environ['AWS_PROFILE'] = self.args.aws_creds_profile

        script_name = os.path.basename(__file__)

        if not ebs_snapshotter.EbsSnapshotter.is_region_valid(
                self.args.region):
            print "Invalid region"
            sys.exit(1)
        else:
            print "Region: %s:" % self.args.region
            ss = ebs_snapshotter.EbsSnapshotter(self.args.region, verbose=True)

            avail_vols, snapshots_created, snapshot_creation_errors = \
                ss.create_snapshots(self.args.with_schedule, script_name, \
                    sleep_between_snaps=self.args.sleep_between_snaps, dry_run=self.args.dry_run)

            num_creation_errors = len(snapshot_creation_errors)

            total_snapshottable_vols += len(avail_vols)
            total_snapshots_created += len(snapshots_created)
            total_snapshot_creation_errors += num_creation_errors

            if num_creation_errors > 0:
                print "  Snapshot Creation errors (%d):" % num_creation_errors
                for cur_err in snapshot_creation_errors:
                    print "    %s" % cur_err

        print
        print "    Total number of snapshottable volumes: %d" % total_snapshottable_vols
        print "        Total number of snapshots created: %d" % total_snapshots_created
        print "Total number of snapshots creation errors: %d" % total_snapshot_creation_errors
        print

        print "Sending results to Zabbix:"
        if self.args.dry_run:
            print "  *** DRY RUN, NO ACTION TAKEN ***"
        else:
            self.report_to_zabbix(total_snapshottable_vols,
                                  total_snapshots_created,
                                  total_snapshot_creation_errors)
Beispiel #5
0
    def main(self):
        """ main function """

        total_expired_snapshots = 0
        total_deleted_snapshots = 0
        total_deletion_errors = 0

        if self.args.aws_creds_profile:
            os.environ['AWS_PROFILE'] = self.args.aws_creds_profile

        regions = ebs_snapshotter.EbsSnapshotter.get_supported_regions()

        for region in regions:
            print "Region: %s:" % region
            ss = ebs_snapshotter.EbsSnapshotter(region.name, verbose=True)

            expired_snapshots, deleted_snapshots, snapshot_deletion_errors = \
                ss.trim_snapshots(hourly_backups=self.args.keep_hourly, \
                                  daily_backups=self.args.keep_daily, \
                                  weekly_backups=self.args.keep_weekly, \
                                  monthly_backups=self.args.keep_monthly, \
                                  dry_run=self.args.dry_run)

            num_deletion_errors = len(snapshot_deletion_errors)

            total_expired_snapshots += len(expired_snapshots)
            total_deleted_snapshots += len(deleted_snapshots)
            total_deletion_errors += num_deletion_errors

            if num_deletion_errors > 0:
                print "  Snapshot Deletion errors (%d):" % num_deletion_errors
                for cur_err in snapshot_deletion_errors:
                    print "    %s" % cur_err

        print
        print "       Total number of expired snapshots: %d" % total_expired_snapshots
        print "       Total number of deleted snapshots: %d" % total_deleted_snapshots
        print "Total number of snapshot deletion errors: %d" % total_deletion_errors
        print

        print "Sending results to Zabbix:"
        if self.args.dry_run:
            print "  *** DRY RUN, NO ACTION TAKEN ***"
        else:
            TrimmerCli.report_to_zabbix(total_expired_snapshots,
                                        total_deleted_snapshots,
                                        total_deletion_errors)
    def main(self):
        """ main function """

        total_snapshottable_vols = 0
        total_snapshots_created = 0
        total_snapshot_creation_errors = 0

        if self.args.aws_creds_profile:
            os.environ['AWS_PROFILE'] = self.args.aws_creds_profile

        regions = ebs_snapshotter.EbsSnapshotter.get_supported_regions()

        script_name = os.path.basename(__file__)

        for region in regions:
            print "Region: %s:" % region
            ss = ebs_snapshotter.EbsSnapshotter(region.name, verbose=True)

            avail_vols, snapshots_created, snapshot_creation_errors = \
                ss.create_snapshots(self.args.with_schedule, script_name, dry_run=self.args.dry_run)

            num_creation_errors = len(snapshot_creation_errors)

            total_snapshottable_vols += len(avail_vols)
            total_snapshots_created += len(snapshots_created)
            total_snapshot_creation_errors += num_creation_errors

            if num_creation_errors > 0:
                print "  Snapshot Deletion errors (%d):" % num_creation_errors
                for cur_err in snapshot_creation_errors:
                    print "    %s" % cur_err

        print
        print "    Total number of snapshottable volumes: %d" % total_snapshottable_vols
        print "        Total number of snapshots created: %d" % total_snapshots_created
        print "Total number of snapshots creation errors: %d" % total_snapshot_creation_errors
        print

        print "Sending results to Zabbix:"
        if self.args.dry_run:
            print "  *** DRY RUN, NO ACTION TAKEN ***"
        else:
            self.report_to_zabbix(total_snapshottable_vols,
                                  total_snapshots_created,
                                  total_snapshot_creation_errors)