def start_migrate(self, user, current_team, current_region, migrate_team, migrate_region, backup_id, migrate_type): backup_record = backup_record_repo.get_record_by_backup_id( current_team.tenant_id, backup_id) if not backup_record: return 404, "无备份记录", None if migrate_type == "recover": is_all_services_closed = self.__check_group_service_status( current_region, current_team, backup_record.group_id) if not is_all_services_closed: return 409, "恢复备份请确保当前组下的应用全部关闭", None restore_mode = self.__get_restore_type(current_team, current_region, migrate_team, migrate_region) # 数据迁移到其他地方先处理数据中心数据拷贝 new_group, new_backup_record = self.__copy_backup_record( restore_mode, backup_record, current_team, current_region, migrate_team, migrate_region, migrate_type) if not new_backup_record: new_backup_record = backup_record backup_service_info = json.loads(new_backup_record.backup_server_info) service_slug = backup_service_info["slug_info"] service_image = backup_service_info["image_info"] data = { "backup_id": new_backup_record.backup_id, "restore_mode": restore_mode, "tenant_id": migrate_team.tenant_id, "slug_info": service_slug, "image_info": service_image } body = region_api.star_apps_migrate_task(migrate_region, migrate_team.tenant_name, new_backup_record.backup_id, data) # 创建迁移记录 params = { "group_id": new_group.ID, "group_uuid": new_backup_record.group_uuid, "event_id": make_uuid(), "version": backup_record.version, "backup_id": new_backup_record.backup_id, "migrate_team": migrate_team.tenant_name, "migrate_region": migrate_region, "status": "starting", "user": user.nick_name, "restore_id": body["bean"]["restore_id"], "original_group_id": backup_record.group_id, "original_group_uuid": backup_record.group_uuid, "migrate_type": migrate_type } migrate_record = migrate_repo.create_migrate_record(**params) return 200, "操作成功,开始迁移", migrate_record
def start_migrate(self, user, current_team, current_region, migrate_team, migrate_region, backup_id, migrate_type, event_id, restore_id): backup_record = backup_record_repo.get_record_by_backup_id(current_team.tenant_id, backup_id) if not backup_record: raise ErrBackupRecordNotFound s3_info = EnterpriseConfigService(user.enterprise_id).get_cloud_obj_storage_info() if backup_record.mode == "full-online" and not s3_info: raise ErrObjectStorageInfoNotFound if migrate_type == "recover": is_all_services_closed = self.__check_group_service_status(current_region, current_team, backup_record.group_id) if not is_all_services_closed: raise ErrNeedAllServiceCloesed restore_mode = self.__get_restore_type(current_team, current_region, migrate_team, migrate_region) # 数据迁移到其他地方先处理数据中心数据拷贝 new_group, new_backup_record = self.__copy_backup_record(restore_mode, backup_record, current_team, current_region, migrate_team, migrate_region, migrate_type) if not new_backup_record: new_backup_record = backup_record data = { "event_id": make_uuid(), "backup_id": new_backup_record.backup_id, "restore_mode": restore_mode, "tenant_id": migrate_team.tenant_id, "s3_config": s3_info, } body = region_api.star_apps_migrate_task(migrate_region, migrate_team.tenant_name, new_backup_record.backup_id, data) if event_id: migrate_record = migrate_repo.get_by_event_id(event_id) data = region_api.get_apps_migrate_status(migrate_record.migrate_region, migrate_record.migrate_team, migrate_record.backup_id, restore_id) bean = data["bean"] migrate_record.status = bean["status"] migrate_record.save() else: # 创建迁移记录 params = { "group_id": new_group.ID, "group_uuid": new_backup_record.group_uuid, "event_id": make_uuid(), "version": backup_record.version, "backup_id": new_backup_record.backup_id, "migrate_team": migrate_team.tenant_name, "migrate_region": migrate_region, "status": "starting", "user": user.nick_name, "restore_id": body["bean"]["restore_id"], "original_group_id": backup_record.group_id, "original_group_uuid": backup_record.group_uuid, "migrate_type": migrate_type } migrate_record = migrate_repo.create_migrate_record(**params) return migrate_record