DockerEnvironmentBackupManager implements EnvironmentBackupManager { @Override public void backupWorkspace(String workspaceId) throws ServerException, NotFoundException { try { WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId); if (workspace.getRuntime() == null) { throw new NotFoundException("Workspace is not running"); } Machine devMachine = workspace.getRuntime().getDevMachine(); if (devMachine == null || devMachine.getStatus() != MachineStatus.RUNNING) { return; } DockerInstance dockerDevMachine = (DockerInstance) workspaceManager.getMachineInstance(workspaceId, devMachine.getId()); String nodeHost = dockerDevMachine.getNode().getHost(); String destPath = workspaceIdHashLocationFinder.calculateDirPath(backupsRootDir, workspaceId).toString(); String srcUserName = getUserInfo(workspaceId, dockerDevMachine.getContainer()).name; int syncPort = getSyncPort(dockerDevMachine); backupInsideLock(workspaceId, projectFolderPath, nodeHost, syncPort, srcUserName, destPath); } catch (IOException e) { throw new ServerException(e.getLocalizedMessage(), e); } } @Inject  DockerEnvironmentBackupManager(
      @Named("machine.backup.backup_script") String backupScript,
      @Named("machine.backup.restore_script") String restoreScript,
      @Named("machine.backup.backup_duration_second") int maxBackupDurationSec,
      @Named("machine.backup.restore_duration_second") int restoreDurationSec,
      @Named("che.user.workspaces.storage") File backupsRootDir,
      WorkspaceIdHashLocationFinder workspaceIdHashLocationFinder,
      @Named("che.workspace.projects.storage") String projectFolderPath,
      WorkspaceManager workspaceManager,
      DockerConnector dockerConnector); @Override void backupWorkspace(String workspaceId); void backupWorkspaceAndCleanup(String workspaceId, String containerId, String nodeHost); void restoreWorkspaceBackup(String workspaceId, String containerId, String nodeHost);  }
@Test( expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Sync port is not exposed in ws-machine. Workspace projects syncing is not possible" ) public void backupShouldThrowErrorIfMachineDoesNotContainServerWithSshPort() throws Exception { when(machineRuntimeInfo.getServers()) .thenReturn( singletonMap( "23/tcp", new ServerImpl("ref", "proto", "127.0.0.1:" + PUBLISHED_SSH_PORT, null, null))); backupManager.backupWorkspace(WORKSPACE_ID); backupManager.backupWorkspace(WORKSPACE_ID); }