def free_required_space(self, name, required_bytes, dry_run=False): """Attempt to free at least ``required_bytes`` of old backups from a backupset :param name: name of the backupset to free space from :param required_bytes: integer number of bytes required for the backupset path :param dry_run: if true, this will only generate log messages but won't actually free space :returns: bool; True if freed or False otherwise """ LOG.info( "Insufficient disk space for adjusted estimated backup size: %s", format_bytes(required_bytes), ) LOG.info( "purge-on-demand is enabled. Discovering old backups to purge.") available_bytes = disk_free(os.path.join(self.spool.path, name)) to_purge = {} for backup in self.spool.list_backups(name): backup_size = directory_size(backup.path) LOG.info("Found backup '%s': %s", backup.path, format_bytes(backup_size)) available_bytes += backup_size to_purge[backup] = backup_size if available_bytes > required_bytes: break else: LOG.info("Purging would only recover an additional %s", format_bytes(sum(to_purge.values()))) LOG.info( "Only %s total would be available, but the current " "backup requires %s", format_bytes(available_bytes), format_bytes(required_bytes), ) return False purge_bytes = sum(to_purge.values()) LOG.info( "Found %d backups to purge which will recover %s", len(to_purge), format_bytes(purge_bytes), ) for backup in to_purge: if dry_run: LOG.info("Would purge: %s", backup.path) else: LOG.info("Purging: %s", backup.path) backup.purge() LOG.info( "%s now has %s of available space", os.path.join(self.spool.path, name), format_bytes(disk_free(os.path.join(self.spool.path, name))), ) return True
def free_required_space(self, name, required_bytes, dry_run=False): """Attempt to free at least ``required_bytes`` of old backups from a backupset :param name: name of the backupset to free space from :param required_bytes: integer number of bytes required for the backupset path :param dry_run: if true, this will only generate log messages but won't actually free space :returns: bool; True if freed or False otherwise """ LOG.info( "Insufficient disk space for adjusted estimated backup size: %s", format_bytes(required_bytes), ) LOG.info("purge-on-demand is enabled. Discovering old backups to purge.") available_bytes = disk_free(os.path.join(self.spool.path, name)) to_purge = {} for backup in self.spool.list_backups(name): backup_size = directory_size(backup.path) LOG.info("Found backup '%s': %s", backup.path, format_bytes(backup_size)) available_bytes += backup_size to_purge[backup] = backup_size if available_bytes > required_bytes: break else: LOG.info( "Purging would only recover an additional %s", format_bytes(sum(to_purge.values())) ) LOG.info( "Only %s total would be available, but the current " "backup requires %s", format_bytes(available_bytes), format_bytes(required_bytes), ) return False purge_bytes = sum(to_purge.values()) LOG.info( "Found %d backups to purge which will recover %s", len(to_purge), format_bytes(purge_bytes), ) for backup in to_purge: if dry_run: LOG.info("Would purge: %s", backup.path) else: LOG.info("Purging: %s", backup.path) backup.purge() LOG.info( "%s now has %s of available space", os.path.join(self.spool.path, name), format_bytes(disk_free(os.path.join(self.spool.path, name))), ) return True
def check_available_space(self, plugin, spool_entry, dry_run=False): available_bytes = disk_free(spool_entry.path) estimated_bytes_required = float(plugin.estimate_backup_size()) LOG.info("Estimated Backup Size: %s", format_bytes(estimated_bytes_required)) config = plugin.config['holland:backup'] adjustment_factor = float(config['estimated-size-factor']) adjusted_bytes_required = (estimated_bytes_required*adjustment_factor) if adjusted_bytes_required != estimated_bytes_required: LOG.info("Adjusting estimated size by %.2f to %s", adjustment_factor, format_bytes(adjusted_bytes_required)) if available_bytes <= adjusted_bytes_required: if not (config['purge-on-demand'] and self.free_required_space(spool_entry.backupset, adjusted_bytes_required, dry_run)): msg = ("Insufficient Disk Space. %s required, " "but only %s available on %s") % ( format_bytes(adjusted_bytes_required), format_bytes(available_bytes), self.spool.path) LOG.error(msg) if not dry_run: raise BackupError(msg) return float(estimated_bytes_required)
def check_available_space(self, plugin, dry_run=False): estimated_bytes_required = plugin.estimate_backup_size() LOG.info("Estimated Backup Size: %s", format_bytes(estimated_bytes_required)) config = plugin.config['holland:backup'] adjustment_factor = config['estimated-size-factor'] adjusted_bytes_required = (estimated_bytes_required*adjustment_factor) if adjusted_bytes_required != estimated_bytes_required: LOG.info("Adjusting estimated size by %.2f to %s", adjustment_factor, format_bytes(adjusted_bytes_required)) available_bytes = disk_free(self.spool.path) if available_bytes <= adjusted_bytes_required: msg = ("Insufficient Disk Space. %s required, " "but only %s available on %s") % ( format_bytes(adjusted_bytes_required), format_bytes(available_bytes), self.spool.path) if dry_run: LOG.error(msg) LOG.info("Note: This is a dry-run and this " "space may be available during a normal " "backup depending on your purge-policy " "configuration.") else: raise BackupError(msg) return estimated_bytes_required
def check_available_space(self, plugin, spool_entry, dry_run=False): available_bytes = disk_free(spool_entry.path) estimated_bytes_required = plugin.estimate_backup_size() LOG.info("Estimated Backup Size: %s", format_bytes(estimated_bytes_required)) config = plugin.config['holland:backup'] adjustment_factor = config['estimated-size-factor'] adjusted_bytes_required = (estimated_bytes_required*adjustment_factor) if adjusted_bytes_required != estimated_bytes_required: LOG.info("Adjusting estimated size by %.2f to %s", adjustment_factor, format_bytes(adjusted_bytes_required)) if available_bytes <= adjusted_bytes_required: if not (config['purge-on-demand'] and self.free_required_space(spool_entry.backupset, adjusted_bytes_required, dry_run)): msg = ("Insufficient Disk Space. %s required, " "but only %s available on %s") % ( format_bytes(adjusted_bytes_required), format_bytes(available_bytes), self.spool.path) LOG.error(msg) if not dry_run: raise BackupError(msg) return estimated_bytes_required
def report_low_space(event, entry): total_space = disk_capacity(entry.path) free_space = disk_free(entry.path) if free_space < 0.10 * total_space: LOG.warning("Extremely low free space on %s's filesystem (%s).", entry.path, getmount(entry.path)) LOG.warning("%s of %s [%.2f%%] remaining", format_bytes(free_space), format_bytes(total_space), (float(free_space) / total_space) * 100)
def verify_space(required_space, target_directory): available_space = disk_free(_find_existing_parent(target_directory)) if required_space >= available_space: LOGGER.error("Insufficient Disk Space. Required: %s Available: %s", format_bytes(required_space), format_bytes(available_space)) raise BackupError("%s required but only %s available on %s" % \ (format_bytes(required_space), format_bytes(available_space), target_directory))
def report_low_space(event, entry): total_space = disk_capacity(entry.path) free_space = disk_free(entry.path) if free_space < 0.10 * total_space: LOG.warning("Extremely low free space on %s's filesystem (%s).", entry.path, getmount(entry.path)) LOG.warning( "%s of %s [%.2f%%] remaining", format_bytes(free_space), format_bytes(total_space), (float(free_space) / total_space) * 100, )
def check_available_space(self, plugin, spool_entry, dry_run=False): """ calculate available space before performing backup """ available_bytes = disk_free(spool_entry.path) estimated_bytes_required = float(plugin.estimate_backup_size()) spool_entry.config["holland:backup"]["estimated-size"] = estimated_bytes_required LOG.info("Estimated Backup Size: %s", format_bytes(estimated_bytes_required)) adjusted_bytes_required = self.historic_required_space( plugin, spool_entry, estimated_bytes_required ) config = plugin.config["holland:backup"] if adjusted_bytes_required < 0: adjustment_factor = float(config["estimated-size-factor"]) adjusted_bytes_required = estimated_bytes_required * adjustment_factor if adjusted_bytes_required != estimated_bytes_required: LOG.info( "Adjusting estimated size by %.2f to %s", adjustment_factor, format_bytes(adjusted_bytes_required), ) else: adjustment_factor = float(config["historic-estimated-size-factor"]) LOG.info( "Adjusting estimated size to last backup total * %s: %s", adjustment_factor, format_bytes(adjusted_bytes_required), ) if available_bytes <= adjusted_bytes_required: if not ( config["purge-on-demand"] and self.free_required_space( spool_entry.backupset, adjusted_bytes_required, dry_run ) ): msg = ("Insufficient Disk Space. %s required, " "but only %s available on %s") % ( format_bytes(adjusted_bytes_required), format_bytes(available_bytes), self.spool.path, ) LOG.error(msg) if not dry_run: raise BackupError(msg) return float(estimated_bytes_required)
def check_available_space(self, plugin): estimated_bytes_required = plugin.estimate_backup_size() LOG.info("Estimated Backup Size: %s", format_bytes(estimated_bytes_required)) config = plugin.config['holland:backup'] adjustment_factor = config['estimated-size-factor'] adjusted_bytes_required = (estimated_bytes_required*adjustment_factor) if adjusted_bytes_required != estimated_bytes_required: LOG.info("Adjusting estimated size by %.2f to %s", adjustment_factor, format_bytes(adjusted_bytes_required)) available_bytes = disk_free(self.spool.path) if available_bytes <= adjusted_bytes_required: raise BackupError("Insufficient Disk Space. " "%s required, but only %s available on %s" % (format_bytes(adjusted_bytes_required), format_bytes(available_bytes), self.spool.path)) return estimated_bytes_required