def execute_restore(self, context, backup_id, restore_location): try: LOG.debug("Cleaning out restore location: %s", restore_location) utils.execute_with_timeout("sudo", "chmod", "-R", "0777", restore_location) utils.clean_out(restore_location) LOG.debug("Finding backup %s to restore", backup_id) backup = DBBackup.find_by(id=backup_id) LOG.debug("Getting Restore Runner of type %s", backup.backup_type) restore_runner = self._get_restore_runner(backup.backup_type) LOG.debug("Getting Storage Strategy") storage_strategy = get_storage_strategy(CONF.storage_strategy, CONF.storage_namespace)(context) LOG.debug("Preparing storage to download stream.") download_stream = storage_strategy.load(context, backup.location, restore_runner.is_zipped, backup.checksum) with restore_runner(restore_stream=download_stream, restore_location=restore_location) as runner: LOG.debug("Restoring instance from backup %s to %s", backup_id, restore_location) content_size = runner.restore() LOG.info("Restore from backup %s completed successfully to %s", backup_id, restore_location) LOG.info("Restore size: %s", content_size) utils.execute_with_timeout("sudo", "chown", "-R", "mysql", restore_location) except Exception as e: LOG.error(e) LOG.error("Error restoring backup %s", backup_id) raise else: LOG.info("Restored Backup %s", backup_id)
def migrate_when_backup_fail(self): self.inst_id = self._get_rid() utils.check_server_status(self.inst_id, type = DBInstanceType.READ_REPLI) backup = utils.create_backup_byclient(self.inst_id) utils.check_backup_status(backup.id) bk_info = DBBackup.find_by(utils.get_context(), id = backup.id) bk_info.state = 'FAILED' bk_info.save() self.migrate()
def execute_backup(self, context, backup_id, runner=RUNNER): LOG.debug("Searching for backup instance %s", backup_id) backup = DBBackup.find_by(id=backup_id) LOG.info("Setting task state to %s for instance %s", BackupState.NEW, backup.instance_id) backup.state = BackupState.NEW backup.save() LOG.info("Running backup %s", backup_id) user = ADMIN_USER_NAME password = get_auth_password() swiftStorage = get_storage_strategy( CONF.storage_strategy, CONF.storage_namespace)(context) # Store the size of the filesystem before the backup. stats = get_filesystem_volume_stats(CONF.mount_point) backup.size = stats.get('used', 0.0) backup.state = BackupState.BUILDING backup.save() try: with runner(filename=backup_id, user=user, password=password)\ as bkup: LOG.info("Starting Backup %s", backup_id) success, note, checksum, location = swiftStorage.save( BACKUP_CONTAINER, bkup) LOG.info("Backup %s completed status: %s", backup_id, success) LOG.info("Backup %s file size: %s", backup_id, bkup.content_length) LOG.info('Backup %s file checksum: %s', backup_id, checksum) LOG.info('Backup %s location: %s', backup_id, location) if not success: raise BackupError(backup.note) except Exception as e: LOG.error(e) LOG.error("Error saving %s Backup", backup_id) backup.state = BackupState.FAILED backup.save() raise else: LOG.info("Saving %s Backup Info to model", backup_id) backup.state = BackupState.COMPLETED backup.checksum = checksum backup.location = location backup.note = note backup.backup_type = bkup.backup_type backup.save()
def execute_backup(self, context, backup_id, runner=RUNNER): LOG.debug("Searching for backup instance %s", backup_id) backup = DBBackup.find_by(id=backup_id) LOG.info("Setting task state to %s for instance %s", BackupState.NEW, backup.instance_id) backup.state = BackupState.NEW backup.save() LOG.info("Running backup %s", backup_id) user = ADMIN_USER_NAME password = get_auth_password() swiftStorage = get_storage_strategy(CONF.storage_strategy, CONF.storage_namespace)(context) # Store the size of the filesystem before the backup. stats = get_filesystem_volume_stats(CONF.mount_point) backup.size = stats.get('used', 0.0) backup.state = BackupState.BUILDING backup.save() try: with runner(filename=backup_id, user=user, password=password)\ as bkup: LOG.info("Starting Backup %s", backup_id) success, note, checksum, location = swiftStorage.save( BACKUP_CONTAINER, bkup) LOG.info("Backup %s completed status: %s", backup_id, success) LOG.info("Backup %s file size: %s", backup_id, bkup.content_length) LOG.info('Backup %s swift checksum: %s', backup_id, checksum) LOG.info('Backup %s location: %s', backup_id, location) if not success: raise BackupError(backup.note) except Exception as e: LOG.error(e) LOG.error("Error saving %s Backup", backup_id) backup.state = BackupState.FAILED backup.save() raise else: LOG.info("Saving %s Backup Info to model", backup_id) backup.state = BackupState.COMPLETED backup.checksum = checksum backup.location = location backup.note = note backup.backup_type = bkup.backup_type backup.save()
def execute_restore(self, context, backup_id, restore_location): try: LOG.debug("Cleaning out restore location: %s", restore_location) utils.execute_with_timeout("sudo", "chmod", "-R", "0777", restore_location) utils.clean_out(restore_location) LOG.debug("Finding backup %s to restore", backup_id) backup = DBBackup.find_by(id=backup_id) LOG.debug("Getting Restore Runner of type %s", backup.backup_type) restore_runner = self._get_restore_runner(backup.backup_type) LOG.debug("Getting Storage Strategy") storage_strategy = get_storage_strategy( CONF.storage_strategy, CONF.storage_namespace)(context) LOG.debug("Preparing storage to download stream.") download_stream = storage_strategy.load(context, backup.location, restore_runner.is_zipped, backup.checksum) with restore_runner(restore_stream=download_stream, restore_location=restore_location) as runner: LOG.debug("Restoring instance from backup %s to %s", backup_id, restore_location) content_size = runner.restore() LOG.info("Restore from backup %s completed successfully to %s", backup_id, restore_location) LOG.info("Restore size: %s", content_size) utils.execute_with_timeout("sudo", "chown", "-R", "mysql", restore_location) except Exception as e: LOG.error(e) LOG.error("Error restoring backup %s", backup_id) raise else: LOG.info("Restored Backup %s", backup_id)
def test_backup_size(self): from trove.backup.models import DBBackup print DBBackup db_record = DBBackup.find_by(id=self.backup.id) self.assertEqual(db_record.size, self.backup.size)