Exemple #1
0
    def add_sub_parser(cls, sub_parsers):
        """
        """

        sub_parser = super(ListSubCommand, cls).add_sub_parser(sub_parsers)

        sub_parser.add_argument(
            '--all',
            action='store_true',
            dest='list_all',
            default=False,
            help="List all backups that match the criteria. Otherwise only "
            "the most recent backup for the specified day is listed.")

        sub_parser.add_argument('--day',
                                default=dt_util.to_iso(dt_util.now_local()),
                                help="Day to return list the backups from.")

        sub_parser.add_argument("keyspace",
                                help="Keyspace to list backups from.")
        sub_parser.add_argument(
            '--host',
            default=socket.getfqdn(),
            help="Host to list backups from. Defaults to the current host.")

        return sub_parser
Exemple #2
0
    def __call__(self):
        """Implements the command."""

        endpoint = self._endpoint(self.args)

        # Work out which days we want to keep
        # the exact cut off time for backups to keep
        purge_before = self._calc_purge_before()
        # list of full or partial days to keep
        manifest_days = self._manifest_days(purge_before)
        self.log.info("To purge backups older then %s will read "
                      " manifests from %s", purge_before, manifest_days)

        # Read the manifests we want to keep.
        self.log.debug("Reading manifests after %s to keep.", purge_before)
        manifests = []
        for manifest_day in manifest_days:
            for manifest in self._list_manifests(endpoint, self.args.keyspace,
                                                 self.args.host, manifest_day):

                if manifest.timestamp >= purge_before:
                    manifests.append(manifest)
                else:
                    self.log.debug("Will not keep manifest %s", manifest)
        self.log.info("Keeping backups %s", manifests)

        # Build a list of the files we want to keep.
        # We purge everything else so that a failed purge can be fixed.
        keep_components = []
        for manifest in manifests:
            keep_components.extend(manifest.iter_components())
        self.log.info("Keeping sstable files: %s", keep_components)

        # Step 4 - Purge the manifests
        deleted_files = self._purge_manifests(endpoint, manifests)

        # Step 5 - Purge the files that are not referenced from a manifest.
        deleted_files.extend(self._purge_sstables(endpoint, keep_components))

        str_build = [
            "Purge backups before {purge_before}".format(
                purge_before=dt_util.to_iso(purge_before))
        ]
        if self.args.dry_run:
            str_build.append("DRY RUN: no files deleted, candidate files:")
        else:
            str_build.append("Deleted files:")
        str_build.append("")

        if deleted_files:
            str_build.extend(deleted_files)
        else:
            str_build.append("No files")

        return (0, "\n".join(str_build))
    def __call__(self):
        """Implements the command."""
        
        endpoint = self._endpoint(self.args)
        
        # Work out which days we want to keep 
        # the exact cut off time for backups to keep
        purge_before = self._calc_purge_before()
        # list of full or partial days to keep
        manifest_days = self._manifest_days(purge_before)
        self.log.info("To purge backups older then %s will read "\
            " manifests from %s", purge_before, manifest_days)
        
        # Read the manifests we want to keep. 
        self.log.debug("Reading manifests after %s to keep.", purge_before)
        manifests = []
        for manifest_day in manifest_days:
            for manifest in self._list_manifests(endpoint, 
                self.args.keyspace, self.args.host, manifest_day):
                
                if manifest.timestamp >= purge_before:
                    manifests.append(manifest)
                else:
                    self.log.debug("Will not keep manifest %s", manifest)
        self.log.info("Keeping backups %s", manifests)
        

        # Build a list of the files we want to keep. 
        # We purge everything else so that a failed purge can be fixed.
        keep_components = []
        for manifest in manifests:
            keep_components.extend(manifest.iter_components())
        self.log.info("Keeping sstable files: %s", keep_components)

        # Step 4 - Purge the manifests
        deleted_files = self._purge_manifests(endpoint, manifests)

        # Step 5 - Purge the files that are not referenced from a manifest.
        deleted_files.extend(self._purge_sstables(endpoint, keep_components))

        str_build = ["Purge backups before {purge_before}".format(
            purge_before=dt_util.to_iso(purge_before))
        ]
        if self.args.dry_run:
            str_build.append("DRY RUN: no files deleted, candidate files:")
        else:
            str_build.append("Deleted files:")
        str_build.append("")
        
        if deleted_files:
            str_build.extend(deleted_files)
        else:
            str_build.append("No files")

        return (0, "\n".join(str_build))
    def add_sub_parser(cls, sub_parsers):
        """
        """

        sub_parser = super(ListSubCommand, cls).add_sub_parser(sub_parsers)

        sub_parser.add_argument('--all',
            action='store_true', dest='list_all', default=False,
            help="List all backups that match the criteria. Otherwise only "\
            "the most recent backup for the specified day is listed.")

        sub_parser.add_argument('--day',
            default=dt_util.to_iso(dt_util.now_local()),
            help="Day to return list the backups from.")

        sub_parser.add_argument("keyspace",
            help="Keyspace to list backups from.")
        sub_parser.add_argument('--host',
            default=socket.getfqdn(),
            help="Host to list backups from. Defaults to the current host.")

        return sub_parser