public int compactTTLRegionsOnGroup(Configuration conf, String rsgroup, int concurrency,
    long sleep, int numServers, int numRegions, boolean dryRun, boolean skipWait) throws Exception {
    try (Connection conn = ConnectionFactory.createConnection(conf);
      Admin admin = conn.getAdmin()) {
      if (admin.getRSGroup(rsgroup) == null) {
        LOG.error("Invalid rsgroup specified: " + rsgroup);
        throw new IllegalArgumentException("Invalid rsgroup specified: " + rsgroup);
      }
      for (TableName tableName : admin.listTablesInRSGroup(rsgroup)) {
        int status = compactRegionsTTLOnTable(conf, tableName.getNameAsString(), concurrency, sleep,
          numServers, numRegions, dryRun, skipWait);
        if (status != 0) {
          LOG.error("Failed to compact table: " + tableName);
          return status;
        }
      }
    }
    return 0;
  }
This script takes an rsgroup as argument and compacts part/all of regions of that table based on
the table's TTL.
hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupMajorCompactionTTL.java