public static void backupFiles(@NotNull Collection<? extends Path> files, @NotNull Path parentDir, @NotNull Path backupDir) throws IOException {
    Files.createDirectories(backupDir);
    for (Path sourceFile : files) {
      Path targetFile;
      if (sourceFile.startsWith(parentDir)) {
        targetFile = backupDir.resolve(parentDir.relativize(sourceFile));

        Path parent = targetFile.getParent();
        if (parent != backupDir) {
          Files.createDirectories(parent);
        }
      }
      else {
        targetFile = backupDir.resolve(sourceFile.getFileName());
      }

      // any file here expected to be regular file and not a directory
      try {
        Files.copy(sourceFile, targetFile, StandardCopyOption.COPY_ATTRIBUTES);
      }
      catch (NoSuchFileException ignore) {
        // if source file doesn't exist - it's ok
      }
    }
  }
public static void backupFiles(@NotNull Collection<? extends Path> files, @NotNull Path parentDir, @NotNull Path backupDir)