public static boolean archiveRegion(Configuration conf, FileSystem fs, Path rootdir,
    Path tableDir, Path regionDir) throws IOException {
    // otherwise, we archive the files
    // make sure we can archive
    if (tableDir == null || regionDir == null) {
      LOG.error("No archive directory could be found because tabledir (" + tableDir
        + ") or regiondir (" + regionDir + "was null. Deleting files instead.");
      if (regionDir != null) {
        deleteRegionWithoutArchiving(fs, regionDir);
      }
      // we should have archived, but failed to. Doesn't matter if we deleted
      // the archived files correctly or not.
      return false;
    }

    LOG.debug("ARCHIVING {}", regionDir);

    // make sure the regiondir lives under the tabledir
    Preconditions.checkArgument(regionDir.toString().startsWith(tableDir.toString()));
    Path regionArchiveDir = HFileArchiveUtil.getRegionArchiveDir(rootdir,
      CommonFSUtils.getTableName(tableDir), regionDir.getName());

    FileStatusConverter getAsFile = new FileStatusConverter(fs);
    // otherwise, we attempt to archive the store files

    // build collection of just the store directories to archive
    Collection<File> toArchive = new ArrayList<>();
    final PathFilter dirFilter = new FSUtils.DirFilter(fs);
    PathFilter nonHidden = new PathFilter() {
      @Override
      public boolean accept(Path file) {
        return dirFilter.accept(file) && !file.getName().startsWith(".");
      }
    };
    FileStatus[] storeDirs = CommonFSUtils.listStatus(fs, regionDir, nonHidden);
    // if there no files, we can just delete the directory and return;
    if (storeDirs == null) {
      LOG.debug("Directory {} empty.", regionDir);
      return deleteRegionWithoutArchiving(fs, regionDir);
    }

    // convert the files in the region to a File
    Stream.of(storeDirs).map(getAsFile).forEachOrdered(toArchive::add);
    LOG.debug("Archiving " + toArchive);
    List<File> failedArchive = resolveAndArchive(conf, fs, regionArchiveDir, toArchive,
      EnvironmentEdgeManager.currentTime());
    if (!failedArchive.isEmpty()) {
      throw new FailedArchiveException(
        "Failed to archive/delete all the files for region:" + regionDir.getName() + " into "
          + regionArchiveDir + ". Something is probably awry on the filesystem.",
        failedArchive.stream().map(FUNC_FILE_TO_PATH).collect(Collectors.toList()));
    }
    // if that was successful, then we delete the region
    return deleteRegionWithoutArchiving(fs, regionDir);
  }
Remove an entire region from the table directory via archiving the region's hfiles.
@param fs        {@link FileSystem} from which to remove the region
@param rootdir   {@link Path} to the root directory where hbase files are stored (for building
                 the archive path)
@param tableDir  {@link Path} to where the table is being stored (for building the archive
                 path)
@param regionDir {@link Path} to where a region is being stored (for building the archive path)
@return <tt>true</tt> if the region was successfully deleted. <tt>false</tt> if the filesystem
        operations could not complete.
@throws IOException if the request cannot be completed
hbase-server/src/main/java/org/apache/hadoop/hbase/backup/HFileArchiver.java