http://git-wip-us.apache.org/repos/asf/hbase-site/blob/3b220124/devapidocs/src-html/org/apache/hadoop/hbase/backup/impl/BackupCommands.CancelCommand.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/backup/impl/BackupCommands.CancelCommand.html b/devapidocs/src-html/org/apache/hadoop/hbase/backup/impl/BackupCommands.CancelCommand.html deleted file mode 100644 index 27e9c24..0000000 --- a/devapidocs/src-html/org/apache/hadoop/hbase/backup/impl/BackupCommands.CancelCommand.html +++ /dev/null @@ -1,1104 +0,0 @@ - - - -Source code - - - -
-
001/**
-002 * Licensed to the Apache Software Foundation (ASF) under one
-003 * or more contributor license agreements.  See the NOTICE file
-004 * distributed with this work for additional information
-005 * regarding copyright ownership.  The ASF licenses this file
-006 * to you under the Apache License, Version 2.0 (the
-007 * "License"); you may not use this file except in compliance
-008 * with the License.  You may obtain a copy of the License at
-009 *
-010 *     http://www.apache.org/licenses/LICENSE-2.0
-011 *
-012 * Unless required by applicable law or agreed to in writing, software
-013 * distributed under the License is distributed on an "AS IS" BASIS,
-014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-015 * See the License for the specific language governing permissions and
-016 * limitations under the License.
-017 */
-018
-019package org.apache.hadoop.hbase.backup.impl;
-020
-021import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_BANDWIDTH;
-022import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_BANDWIDTH_DESC;
-023import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_PATH;
-024import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_PATH_DESC;
-025import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_RECORD_NUMBER;
-026import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_RECORD_NUMBER_DESC;
-027import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_SET;
-028import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_SET_BACKUP_DESC;
-029import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_SET_DESC;
-030import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_TABLE;
-031import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_TABLE_DESC;
-032import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_TABLE_LIST_DESC;
-033import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_WORKERS;
-034import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_WORKERS_DESC;
-035import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_YARN_QUEUE_NAME;
-036import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_YARN_QUEUE_NAME_DESC;
-037
-038import java.io.IOException;
-039import java.net.URI;
-040import java.util.List;
-041
-042import org.apache.commons.cli.CommandLine;
-043import org.apache.commons.cli.HelpFormatter;
-044import org.apache.commons.cli.Options;
-045import org.apache.commons.lang.StringUtils;
-046import org.apache.hadoop.conf.Configuration;
-047import org.apache.hadoop.conf.Configured;
-048import org.apache.hadoop.fs.FileSystem;
-049import org.apache.hadoop.fs.Path;
-050import org.apache.hadoop.hbase.HBaseConfiguration;
-051import org.apache.hadoop.hbase.TableName;
-052import org.apache.hadoop.hbase.backup.BackupAdmin;
-053import org.apache.hadoop.hbase.backup.BackupInfo;
-054import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
-055import org.apache.hadoop.hbase.backup.BackupRequest;
-056import org.apache.hadoop.hbase.backup.BackupRestoreConstants;
-057import org.apache.hadoop.hbase.backup.BackupRestoreConstants.BackupCommand;
-058import org.apache.hadoop.hbase.backup.BackupType;
-059import org.apache.hadoop.hbase.backup.util.BackupSet;
-060import org.apache.hadoop.hbase.backup.util.BackupUtils;
-061import org.apache.hadoop.hbase.classification.InterfaceAudience;
-062import org.apache.hadoop.hbase.client.Connection;
-063import org.apache.hadoop.hbase.client.ConnectionFactory;
-064import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists;
-065import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-066
-067/**
-068 * General backup commands, options and usage messages
-069 */
-070
-071@InterfaceAudience.Private
-072public final class BackupCommands {
-073
-074  public final static String INCORRECT_USAGE = "Incorrect usage";
-075
-076  public static final String USAGE = "Usage: hbase backup COMMAND [command-specific arguments]\n"
-077      + "where COMMAND is one of:\n" + "  create     create a new backup image\n"
-078      + "  delete     delete an existing backup image\n"
-079      + "  describe   show the detailed information of a backup image\n"
-080      + "  history    show history of all successful backups\n"
-081      + "  progress   show the progress of the latest backup request\n"
-082      + "  set        backup set management\n"
-083      + "  repair     repair backup system table\n"
-084      + "  merge      merge backup images\n"
-085      + "Run \'hbase backup COMMAND -h\' to see help message for each command\n";
-086
-087  public static final String CREATE_CMD_USAGE =
-088      "Usage: hbase backup create <type> <backup_path> [options]\n"
-089          + "  type           \"full\" to create a full backup image\n"
-090          + "                 \"incremental\" to create an incremental backup image\n"
-091          + "  backup_path     Full path to store the backup image\n";
-092
-093  public static final String PROGRESS_CMD_USAGE = "Usage: hbase backup progress <backup_id>\n"
-094      + "  backup_id       Backup image id (optional). If no id specified, the command will show\n"
-095      + "                  progress for currently running backup session.";
-096  public static final String NO_INFO_FOUND = "No info was found for backup id: ";
-097  public static final String NO_ACTIVE_SESSION_FOUND = "No active backup sessions found.";
-098
-099  public static final String DESCRIBE_CMD_USAGE = "Usage: hbase backup describe <backup_id>\n"
-100      + "  backup_id       Backup image id\n";
-101
-102  public static final String HISTORY_CMD_USAGE = "Usage: hbase backup history [options]";
-103
-104  public static final String DELETE_CMD_USAGE = "Usage: hbase backup delete <backup_id>\n"
-105      + "  backup_id       Backup image id\n";
-106
-107  public static final String REPAIR_CMD_USAGE = "Usage: hbase backup repair\n";
-108
-109  public static final String CANCEL_CMD_USAGE = "Usage: hbase backup cancel <backup_id>\n"
-110      + "  backup_id       Backup image id\n";
-111
-112  public static final String SET_CMD_USAGE = "Usage: hbase backup set COMMAND [name] [tables]\n"
-113      + "  name            Backup set name\n"
-114      + "  tables          Comma separated list of tables.\n" + "COMMAND is one of:\n"
-115      + "  add             add tables to a set, create a set if needed\n"
-116      + "  remove          remove tables from a set\n"
-117      + "  list            list all backup sets in the system\n"
-118      + "  describe        describe set\n" + "  delete          delete backup set\n";
-119  public static final String MERGE_CMD_USAGE = "Usage: hbase backup merge [backup_ids]\n"
-120      + "  backup_ids      Comma separated list of backup image ids.\n";
-121
-122  public static final String USAGE_FOOTER = "";
-123
-124  public static abstract class Command extends Configured {
-125    CommandLine cmdline;
-126    Connection conn;
-127
-128    Command(Configuration conf) {
-129      if (conf == null) {
-130        conf = HBaseConfiguration.create();
-131      }
-132      setConf(conf);
-133    }
-134
-135    public void execute() throws IOException {
-136      if (cmdline.hasOption("h") || cmdline.hasOption("help")) {
-137        printUsage();
-138        throw new IOException(INCORRECT_USAGE);
-139      }
-140
-141      // Create connection
-142      conn = ConnectionFactory.createConnection(getConf());
-143      if (requiresNoActiveSession()) {
-144        // Check active session
-145        try (BackupSystemTable table = new BackupSystemTable(conn);) {
-146          List<BackupInfo> sessions = table.getBackupInfos(BackupState.RUNNING);
-147
-148          if (sessions.size() > 0) {
-149            System.err.println("Found backup session in a RUNNING state: ");
-150            System.err.println(sessions.get(0));
-151            System.err.println("This may indicate that a previous session has failed abnormally.");
-152            System.err.println("In this case, backup recovery is recommended.");
-153            throw new IOException("Active session found, aborted command execution");
-154          }
-155        }
-156      }
-157      if (requiresConsistentState()) {
-158        // Check failed delete
-159        try (BackupSystemTable table = new BackupSystemTable(conn);) {
-160          String[] ids = table.getListOfBackupIdsFromDeleteOperation();
-161
-162          if (ids != null && ids.length > 0) {
-163            System.err.println("Found failed backup DELETE coommand. ");
-164            System.err.println("Backup system recovery is required.");
-165            throw new IOException("Failed backup DELETE found, aborted command execution");
-166          }
-167
-168          ids = table.getListOfBackupIdsFromMergeOperation();
-169          if (ids != null && ids.length > 0) {
-170            System.err.println("Found failed backup MERGE coommand. ");
-171            System.err.println("Backup system recovery is required.");
-172            throw new IOException("Failed backup MERGE found, aborted command execution");
-173          }
-174
-175        }
-176      }
-177    }
-178
-179    public void finish() throws IOException {
-180      if (conn != null) {
-181        conn.close();
-182      }
-183    }
-184
-185    protected abstract void printUsage();
-186
-187    /**
-188     * The command can't be run if active backup session is in progress
-189     * @return true if no active sessions are in progress
-190     */
-191    protected boolean requiresNoActiveSession() {
-192      return false;
-193    }
-194
-195    /**
-196     * Command requires consistent state of a backup system Backup system may become inconsistent
-197     * because of an abnormal termination of a backup session or delete command
-198     * @return true, if yes
-199     */
-200    protected boolean requiresConsistentState() {
-201      return false;
-202    }
-203  }
-204
-205  private BackupCommands() {
-206    throw new AssertionError("Instantiating utility class...");
-207  }
-208
-209  public static Command createCommand(Configuration conf, BackupCommand type, CommandLine cmdline) {
-210    Command cmd = null;
-211    switch (type) {
-212    case CREATE:
-213      cmd = new CreateCommand(conf, cmdline);
-214      break;
-215    case DESCRIBE:
-216      cmd = new DescribeCommand(conf, cmdline);
-217      break;
-218    case PROGRESS:
-219      cmd = new ProgressCommand(conf, cmdline);
-220      break;
-221    case DELETE:
-222      cmd = new DeleteCommand(conf, cmdline);
-223      break;
-224    case CANCEL:
-225      cmd = new CancelCommand(conf, cmdline);
-226      break;
-227    case HISTORY:
-228      cmd = new HistoryCommand(conf, cmdline);
-229      break;
-230    case SET:
-231      cmd = new BackupSetCommand(conf, cmdline);
-232      break;
-233    case REPAIR:
-234      cmd = new RepairCommand(conf, cmdline);
-235      break;
-236    case MERGE:
-237      cmd = new MergeCommand(conf, cmdline);
-238      break;
-239    case HELP:
-240    default:
-241      cmd = new HelpCommand(conf, cmdline);
-242      break;
-243    }
-244    return cmd;
-245  }
-246
-247  static int numOfArgs(String[] args) {
-248    if (args == null) return 0;
-249    return args.length;
-250  }
-251
-252  public static class CreateCommand extends Command {
-253
-254    CreateCommand(Configuration conf, CommandLine cmdline) {
-255      super(conf);
-256      this.cmdline = cmdline;
-257    }
-258
-259    @Override
-260    protected boolean requiresNoActiveSession() {
-261      return true;
-262    }
-263
-264    @Override
-265    protected boolean requiresConsistentState() {
-266      return true;
-267    }
-268
-269    @Override
-270    public void execute() throws IOException {
-271      if (cmdline == null || cmdline.getArgs() == null) {
-272        printUsage();
-273        throw new IOException(INCORRECT_USAGE);
-274      }
-275      String[] args = cmdline.getArgs();
-276      if (args.length != 3) {
-277        printUsage();
-278        throw new IOException(INCORRECT_USAGE);
-279      }
-280
-281      if (!BackupType.FULL.toString().equalsIgnoreCase(args[1])
-282          && !BackupType.INCREMENTAL.toString().equalsIgnoreCase(args[1])) {
-283        System.out.println("ERROR: invalid backup type: " + args[1]);
-284        printUsage();
-285        throw new IOException(INCORRECT_USAGE);
-286      }
-287      if (!verifyPath(args[2])) {
-288        System.out.println("ERROR: invalid backup destination: " + args[2]);
-289        printUsage();
-290        throw new IOException(INCORRECT_USAGE);
-291      }
-292
-293      String tables = null;
-294
-295      // Check if we have both: backup set and list of tables
-296      if (cmdline.hasOption(OPTION_TABLE) && cmdline.hasOption(OPTION_SET)) {
-297        System.out.println("ERROR: You can specify either backup set or list"
-298            + " of tables, but not both");
-299        printUsage();
-300        throw new IOException(INCORRECT_USAGE);
-301      }
-302      // Creates connection
-303      super.execute();
-304      // Check backup set
-305      String setName = null;
-306      if (cmdline.hasOption(OPTION_SET)) {
-307        setName = cmdline.getOptionValue(OPTION_SET);
-308        tables = getTablesForSet(setName, getConf());
-309
-310        if (tables == null) {
-311          System.out.println("ERROR: Backup set '" + setName
-312              + "' is either empty or does not exist");
-313          printUsage();
-314          throw new IOException(INCORRECT_USAGE);
-315        }
-316      } else {
-317        tables = cmdline.getOptionValue(OPTION_TABLE);
-318      }
-319      int bandwidth =
-320          cmdline.hasOption(OPTION_BANDWIDTH) ? Integer.parseInt(cmdline
-321              .getOptionValue(OPTION_BANDWIDTH)) : -1;
-322      int workers =
-323          cmdline.hasOption(OPTION_WORKERS) ? Integer.parseInt(cmdline
-324              .getOptionValue(OPTION_WORKERS)) : -1;
-325
-326      if (cmdline.hasOption(OPTION_YARN_QUEUE_NAME)) {
-327        String queueName = cmdline.getOptionValue(OPTION_YARN_QUEUE_NAME);
-328        // Set system property value for MR job
-329        System.setProperty("mapreduce.job.queuename", queueName);
-330      }
-331
-332      try (BackupAdminImpl admin = new BackupAdminImpl(conn);) {
-333
-334        BackupRequest.Builder builder = new BackupRequest.Builder();
-335        BackupRequest request =
-336            builder
-337                .withBackupType(BackupType.valueOf(args[1].toUpperCase()))
-338                .withTableList(
-339                  tables != null ? Lists.newArrayList(BackupUtils.parseTableNames(tables)) : null)
-340                .withTargetRootDir(args[2]).withTotalTasks(workers)
-341                .withBandwidthPerTasks(bandwidth).withBackupSetName(setName).build();
-342        String backupId = admin.backupTables(request);
-343        System.out.println("Backup session " + backupId + " finished. Status: SUCCESS");
-344      } catch (IOException e) {
-345        System.out.println("Backup session finished. Status: FAILURE");
-346        throw e;
-347      }
-348    }
-349
-350    private boolean verifyPath(String path) {
-351      try {
-352        Path p = new Path(path);
-353        Configuration conf = getConf() != null ? getConf() : HBaseConfiguration.create();
-354        URI uri = p.toUri();
-355        if (uri.getScheme() == null) return false;
-356        FileSystem.get(uri, conf);
-357        return true;
-358      } catch (Exception e) {
-359        return false;
-360      }
-361    }
-362
-363    private String getTablesForSet(String name, Configuration conf) throws IOException {
-364      try (final BackupSystemTable table = new BackupSystemTable(conn)) {
-365        List<TableName> tables = table.describeBackupSet(name);
-366        if (tables == null) return null;
-367        return StringUtils.join(tables, BackupRestoreConstants.TABLENAME_DELIMITER_IN_COMMAND);
-368      }
-369    }
-370
-371    @Override
-372    protected void printUsage() {
-373      System.out.println(CREATE_CMD_USAGE);
-374      Options options = new Options();
-375      options.addOption(OPTION_WORKERS, true, OPTION_WORKERS_DESC);
-376      options.addOption(OPTION_BANDWIDTH, true, OPTION_BANDWIDTH_DESC);
-377      options.addOption(OPTION_SET, true, OPTION_SET_BACKUP_DESC);
-378      options.addOption(OPTION_TABLE, true, OPTION_TABLE_LIST_DESC);
-379      options.addOption(OPTION_YARN_QUEUE_NAME, true, OPTION_YARN_QUEUE_NAME_DESC);
-380
-381
-382      HelpFormatter helpFormatter = new HelpFormatter();
-383      helpFormatter.setLeftPadding(2);
-384      helpFormatter.setDescPadding(8);
-385      helpFormatter.setWidth(100);
-386      helpFormatter.setSyntaxPrefix("Options:");
-387      helpFormatter.printHelp(" ", null, options, USAGE_FOOTER);
-388
-389    }
-390  }
-391
-392  private static class HelpCommand extends Command {
-393
-394    HelpCommand(Configuration conf, CommandLine cmdline) {
-395      super(conf);
-396      this.cmdline = cmdline;
-397    }
-398
-399    @Override
-400    public void execute() throws IOException {
-401      if (cmdline == null) {
-402        printUsage();
-403        throw new IOException(INCORRECT_USAGE);
-404      }
-405
-406      String[] args = cmdline.getArgs();
-407      if (args == null || args.length == 0) {
-408        printUsage();
-409        throw new IOException(INCORRECT_USAGE);
-410      }
-411
-412      if (args.length != 2) {
-413        System.out.println("ERROR: Only supports help message of a single command type");
-414        printUsage();
-415        throw new IOException(INCORRECT_USAGE);
-416      }
-417
-418      String type = args[1];
-419
-420      if (BackupCommand.CREATE.name().equalsIgnoreCase(type)) {
-421        System.out.println(CREATE_CMD_USAGE);
-422      } else if (BackupCommand.DESCRIBE.name().equalsIgnoreCase(type)) {
-423        System.out.println(DESCRIBE_CMD_USAGE);
-424      } else if (BackupCommand.HISTORY.name().equalsIgnoreCase(type)) {
-425        System.out.println(HISTORY_CMD_USAGE);
-426      } else if (BackupCommand.PROGRESS.name().equalsIgnoreCase(type)) {
-427        System.out.println(PROGRESS_CMD_USAGE);
-428      } else if (BackupCommand.DELETE.name().equalsIgnoreCase(type)) {
-429        System.out.println(DELETE_CMD_USAGE);
-430      } else if (BackupCommand.CANCEL.name().equalsIgnoreCase(type)) {
-431        System.out.println(CANCEL_CMD_USAGE);
-432      } else if (BackupCommand.SET.name().equalsIgnoreCase(type)) {
-433        System.out.println(SET_CMD_USAGE);
-434      } else {
-435        System.out.println("Unknown command : " + type);
-436        printUsage();
-437      }
-438    }
-439
-440    @Override
-441    protected void printUsage() {
-442      System.out.println(USAGE);
-443    }
-444  }
-445
-446  private static class DescribeCommand extends Command {
-447
-448    DescribeCommand(Configuration conf, CommandLine cmdline) {
-449      super(conf);
-450      this.cmdline = cmdline;
-451    }
-452
-453    @Override
-454    public void execute() throws IOException {
-455      if (cmdline == null || cmdline.getArgs() == null) {
-456        printUsage();
-457        throw new IOException(INCORRECT_USAGE);
-458      }
-459      String[] args = cmdline.getArgs();
-460      if (args.length != 2) {
-461        printUsage();
-462        throw new IOException(INCORRECT_USAGE);
-463      }
-464
-465      super.execute();
-466
-467      String backupId = args[1];
-468      try (final BackupSystemTable sysTable = new BackupSystemTable(conn);) {
-469        BackupInfo info = sysTable.readBackupInfo(backupId);
-470        if (info == null) {
-471          System.out.println("ERROR: " + backupId + " does not exist");
-472          printUsage();
-473          throw new IOException(INCORRECT_USAGE);
-474        }
-475        System.out.println(info.getShortDescription());
-476      }
-477    }
-478
-479    @Override
-480    protected void printUsage() {
-481      System.out.println(DESCRIBE_CMD_USAGE);
-482    }
-483  }
-484
-485  private static class ProgressCommand extends Command {
-486
-487    ProgressCommand(Configuration conf, CommandLine cmdline) {
-488      super(conf);
-489      this.cmdline = cmdline;
-490    }
-491
-492    @Override
-493    public void execute() throws IOException {
-494
-495      if (cmdline == null || cmdline.getArgs() == null || cmdline.getArgs().length == 1) {
-496        System.out.println("No backup id was specified, "
-497            + "will retrieve the most recent (ongoing) session");
-498      }
-499      String[] args = cmdline == null ? null : cmdline.getArgs();
-500      if (args != null && args.length > 2) {
-501        System.err.println("ERROR: wrong number of arguments: " + args.length);
-502        printUsage();
-503        throw new IOException(INCORRECT_USAGE);
-504      }
-505
-506      super.execute();
-507
-508      String backupId = (args == null || args.length <= 1) ? null : args[1];
-509      try (final BackupSystemTable sysTable = new BackupSystemTable(conn);) {
-510        BackupInfo info = null;
-511
-512        if (backupId != null) {
-513          info = sysTable.readBackupInfo(backupId);
-514        } else {
-515          List<BackupInfo> infos = sysTable.getBackupInfos(BackupState.RUNNING);
-516          if (infos != null && infos.size() > 0) {
-517            info = infos.get(0);
-518            backupId = info.getBackupId();
-519            System.out.println("Found ongoing session with backupId=" + backupId);
-520          } else {
-521          }
-522        }
-523        int progress = info == null ? -1 : info.getProgress();
-524        if (progress < 0) {
-525          if (backupId != null) {
-526            System.out.println(NO_INFO_FOUND + backupId);
-527          } else {
-528            System.err.println(NO_ACTIVE_SESSION_FOUND);
-529          }
-530        } else {
-531          System.out.println(backupId + " progress=" + progress + "%");
-532        }
-533      }
-534    }
-535
-536    @Override
-537    protected void printUsage() {
-538      System.out.println(PROGRESS_CMD_USAGE);
-539    }
-540  }
-541
-542  private static class DeleteCommand extends Command {
-543
-544    DeleteCommand(Configuration conf, CommandLine cmdline) {
-545      super(conf);
-546      this.cmdline = cmdline;
-547    }
-548
-549    @Override
-550    protected boolean requiresNoActiveSession() {
-551      return true;
-552    }
-553
-554    @Override
-555    public void execute() throws IOException {
-556      if (cmdline == null || cmdline.getArgs() == null || cmdline.getArgs().length < 2) {
-557        printUsage();
-558        throw new IOException(INCORRECT_USAGE);
-559      }
-560
-561      super.execute();
-562
-563      String[] args = cmdline.getArgs();
-564      String[] backupIds = new String[args.length - 1];
-565      System.arraycopy(args, 1, backupIds, 0, backupIds.length);
-566      try (BackupAdminImpl admin = new BackupAdminImpl(conn);) {
-567        int deleted = admin.deleteBackups(backupIds);
-568        System.out.println("Deleted " + deleted + " backups. Total requested: " + args.length);
-569      } catch (IOException e) {
-570        System.err
-571            .println("Delete command FAILED. Please run backup repair tool to restore backup system integrity");
-572        throw e;
-573      }
-574
-575    }
-576
-577    @Override
-578    protected void printUsage() {
-579      System.out.println(DELETE_CMD_USAGE);
-580    }
-581  }
-582
-583  private static class RepairCommand extends Command {
-584
-585    RepairCommand(Configuration conf, CommandLine cmdline) {
-586      super(conf);
-587      this.cmdline = cmdline;
-588    }
-589
-590    @Override
-591    public void execute() throws IOException {
-592      super.execute();
-593
-594      String[] args = cmdline == null ? null : cmdline.getArgs();
-595      if (args != null && args.length > 1) {
-596        System.err.println("ERROR: wrong number of arguments: " + args.length);
-597        printUsage();
-598        throw new IOException(INCORRECT_USAGE);
-599      }
-600
-601      Configuration conf = getConf() != null ? getConf() : HBaseConfiguration.create();
-602      try (final Connection conn = ConnectionFactory.createConnection(conf);
-603          final BackupSystemTable sysTable = new BackupSystemTable(conn);) {
-604
-605        // Failed backup
-606        BackupInfo backupInfo;
-607        List<BackupInfo> list = sysTable.getBackupInfos(BackupState.RUNNING);
-608        if (list.size() == 0) {
-609          // No failed sessions found
-610          System.out.println("REPAIR status: no failed sessions found."
-611              + " Checking failed delete backup operation ...");
-612          repairFailedBackupDeletionIfAny(conn, sysTable);
-613          repairFailedBackupMergeIfAny(conn, sysTable);
-614          return;
-615        }
-616        backupInfo = list.get(0);
-617        // If this is a cancel exception, then we've already cleaned.
-618        // set the failure timestamp of the overall backup
-619        backupInfo.setCompleteTs(EnvironmentEdgeManager.currentTime());
-620        // set failure message
-621        backupInfo.setFailedMsg("REPAIR status: repaired after failure:\n" + backupInfo);
-622        // set overall backup status: failed
-623        backupInfo.setState(BackupState.FAILED);
-624        // compose the backup failed data
-625        String backupFailedData =
-626            "BackupId=" + backupInfo.getBackupId() + ",startts=" + backupInfo.getStartTs()
-627                + ",failedts=" + backupInfo.getCompleteTs() + ",failedphase="
-628                + backupInfo.getPhase() + ",failedmessage=" + backupInfo.getFailedMsg();
-629        System.out.println(backupFailedData);
-630        TableBackupClient.cleanupAndRestoreBackupSystem(conn, backupInfo, conf);
-631        // If backup session is updated to FAILED state - means we
-632        // processed recovery already.
-633        sysTable.updateBackupInfo(backupInfo);
-634        sysTable.finishBackupExclusiveOperation();
-635        System.out.println("REPAIR status: finished repair failed session:\n " + backupInfo);
-636
-637      }
-638    }
-639
-640    private void repairFailedBackupDeletionIfAny(Connection conn, BackupSystemTable sysTable)
-641        throws IOException {
-642      String[] backupIds = sysTable.getListOfBackupIdsFromDeleteOperation();
-643      if (backupIds == null || backupIds.length == 0) {
-644        System.out.println("No failed backup DELETE operation found");
-645        // Delete backup table snapshot if exists
-646        BackupSystemTable.deleteSnapshot(conn);
-647        return;
-648      }
-649      System.out.println("Found failed DELETE operation for: " + StringUtils.join(backupIds));
-650      System.out.println("Running DELETE again ...");
-651      // Restore table from snapshot
-652      BackupSystemTable.restoreFromSnapshot(conn);
-653      // Finish previous failed session
-654      sysTable.finishBackupExclusiveOperation();
-655      try (BackupAdmin admin = new BackupAdminImpl(conn);) {
-656        admin.deleteBackups(backupIds);
-657      }
-658      System.out.println("DELETE operation finished OK: " + StringUtils.join(backupIds));
-659
-660    }
-661
-662    private void repairFailedBackupMergeIfAny(Connection conn, BackupSystemTable sysTable)
-663        throws IOException {
-664      String[] backupIds = sysTable.getListOfBackupIdsFromMergeOperation();
-665      if (backupIds == null || backupIds.length == 0) {
-666        System.out.println("No failed backup MERGE operation found");
-667        // Delete backup table snapshot if exists
-668        BackupSystemTable.deleteSnapshot(conn);
-669        return;
-670      }
-671      System.out.println("Found failed MERGE operation for: " + StringUtils.join(backupIds));
-672      System.out.println("Running MERGE again ...");
-673      // Restore table from snapshot
-674      BackupSystemTable.restoreFromSnapshot(conn);
-675      // Unlock backupo system
-676      sysTable.finishBackupExclusiveOperation();
-677      // Finish previous failed session
-678      sysTable.finishMergeOperation();
-679      try (BackupAdmin admin = new BackupAdminImpl(conn);) {
-680        admin.mergeBackups(backupIds);
-681      }
-682      System.out.println("MERGE operation finished OK: " + StringUtils.join(backupIds));
-683
-684    }
-685
-686    @Override
-687    protected void printUsage() {
-688      System.out.println(REPAIR_CMD_USAGE);
-689    }
-690  }
-691
-692  private static class MergeCommand extends Command {
-693
-694    MergeCommand(Configuration conf, CommandLine cmdline) {
-695      super(conf);
-696      this.cmdline = cmdline;
-697    }
-698
-699    @Override
-700    protected boolean requiresNoActiveSession() {
-701      return true;
-702    }
-703
-704    @Override
-705    protected boolean requiresConsistentState() {
-706      return true;
-707    }
-708
-709    @Override
-710    public void execute() throws IOException {
-711      super.execute();
-712
-713      String[] args = cmdline == null ? null : cmdline.getArgs();
-714      if (args == null || (args.length != 2)) {
-715        System.err.println("ERROR: wrong number of arguments: "
-716            + (args == null ? null : args.length));
-717        printUsage();
-718        throw new IOException(INCORRECT_USAGE);
-719      }
-720
-721      String[] backupIds = args[1].split(",");
-722      if (backupIds.length < 2) {
-723        String msg = "ERROR: can not merge a single backup image. "+
-724            "Number of images must be greater than 1.";
-725        System.err.println(msg);
-726        throw new IOException(msg);
-727
-728      }
-729      Configuration conf = getConf() != null ? getConf() : HBaseConfiguration.create();
-730      try (final Connection conn = ConnectionFactory.createConnection(conf);
-731          final BackupAdminImpl admin = new BackupAdminImpl(conn);) {
-732        admin.mergeBackups(backupIds);
-733      }
-734    }
-735
-736    @Override
-737    protected void printUsage() {
-738      System.out.println(MERGE_CMD_USAGE);
-739    }
-740  }
-741
-742  // TODO Cancel command
-743
-744  private static class CancelCommand extends Command {
-745
-746    CancelCommand(Configuration conf, CommandLine cmdline) {
-747      super(conf);
-748      this.cmdline = cmdline;
-749    }
-750
-751    @Override
-752    public void execute() throws IOException {
-753      throw new UnsupportedOperationException("Cancel command is not supported yet.");
-754    }
-755
-756    @Override
-757    protected void printUsage() {
-758    }
-759  }
-760
-761  private static class HistoryCommand extends Command {
-762
-763    private final static int DEFAULT_HISTORY_LENGTH = 10;
-764
-765    HistoryCommand(Configuration conf, CommandLine cmdline) {
-766      super(conf);
-767      this.cmdline = cmdline;
-768    }
-769
-770    @Override
-771    public void execute() throws IOException {
-772
-773      int n = parseHistoryLength();
-774      final TableName tableName = getTableName();
-775      final String setName = getTableSetName();
-776      BackupInfo.Filter tableNameFilter = new BackupInfo.Filter() {
-777        @Override
-778        public boolean apply(BackupInfo info) {
-779          if (tableName == null) return true;
-780          List<TableName> names = info.getTableNames();
-781          return names.contains(tableName);
-782        }
-783      };
-784      BackupInfo.Filter tableSetFilter = new BackupInfo.Filter() {
-785        @Override
-786        public boolean apply(BackupInfo info) {
-787          if (setName == null) return true;
-788          String backupId = info.getBackupId();
-789          return backupId.startsWith(setName);
-790        }
-791      };
-792      Path backupRootPath = getBackupRootPath();
-793      List<BackupInfo> history = null;
-794      if (backupRootPath == null) {
-795        // Load from backup system table
-796        super.execute();
-797        try (final BackupSystemTable sysTable = new BackupSystemTable(conn);) {
-798          history = sysTable.getBackupHistory(n, tableNameFilter, tableSetFilter);
-799        }
-800      } else {
-801        // load from backup FS
-802        history =
-803            BackupUtils.getHistory(getConf(), n, backupRootPath, tableNameFilter, tableSetFilter);
-804      }
-805      for (BackupInfo info : history) {
-806        System.out.println(info.getShortDescription());
-807      }
-808    }
-809
-810    private Path getBackupRootPath() throws IOException {
-811      String value = null;
-812      try {
-813        value = cmdline.getOptionValue(OPTION_PATH);
-814        if (value == null) return null;
-815        return new Path(value);
-816      } catch (IllegalArgumentException e) {
-817        System.out.println("ERROR: Illegal argument for backup root path: " + value);
-818        printUsage();
-819        throw new IOException(INCORRECT_USAGE);
-820      }
-821    }
-822
-823    private TableName getTableName() throws IOException {
-824      String value = cmdline.getOptionValue(OPTION_TABLE);
-825      if (value == null) return null;
-826      try {
-827        return TableName.valueOf(value);
-828      } catch (IllegalArgumentException e) {
-829        System.out.println("Illegal argument for table name: " + value);
-830        printUsage();
-831        throw new IOException(INCORRECT_USAGE);
-832      }
-833    }
-834
-835    private String getTableSetName() throws IOException {
-836      String value = cmdline.getOptionValue(OPTION_SET);
-837      return value;
-838    }
-839
-840    private int parseHistoryLength() throws IOException {
-841      String value = cmdline.getOptionValue(OPTION_RECORD_NUMBER);
-842      try {
-843        if (value == null) return DEFAULT_HISTORY_LENGTH;
-844        return Integer.parseInt(value);
-845      } catch (NumberFormatException e) {
-846        System.out.println("Illegal argument for history length: " + value);
-847        printUsage();
-848        throw new IOException(INCORRECT_USAGE);
-849      }
-850    }
-851
-852    @Override
-853    protected void printUsage() {
-854      System.out.println(HISTORY_CMD_USAGE);
-855      Options options = new Options();
-856      options.addOption(OPTION_RECORD_NUMBER, true, OPTION_RECORD_NUMBER_DESC);
-857      options.addOption(OPTION_PATH, true, OPTION_PATH_DESC);
-858      options.addOption(OPTION_TABLE, true, OPTION_TABLE_DESC);
-859      options.addOption(OPTION_SET, true, OPTION_SET_DESC);
-860
-861      HelpFormatter helpFormatter = new HelpFormatter();
-862      helpFormatter.setLeftPadding(2);
-863      helpFormatter.setDescPadding(8);
-864      helpFormatter.setWidth(100);
-865      helpFormatter.setSyntaxPrefix("Options:");
-866      helpFormatter.printHelp(" ", null, options, USAGE_FOOTER);
-867    }
-868  }
-869
-870  private static class BackupSetCommand extends Command {
-871    private final static String SET_ADD_CMD = "add";
-872    private final static String SET_REMOVE_CMD = "remove";
-873    private final static String SET_DELETE_CMD = "delete";
-874    private final static String SET_DESCRIBE_CMD = "describe";
-875    private final static String SET_LIST_CMD = "list";
-876
-877    BackupSetCommand(Configuration conf, CommandLine cmdline) {
-878      super(conf);
-879      this.cmdline = cmdline;
-880    }
-881
-882    @Override
-883    public void execute() throws IOException {
-884      // Command-line must have at least one element
-885      if (cmdline == null || cmdline.getArgs() == null || cmdline.getArgs().length < 2) {
-886        printUsage();
-887        throw new IOException(INCORRECT_USAGE);
-888      }
-889
-890      String[] args = cmdline.getArgs();
-891      String cmdStr = args[1];
-892      BackupCommand cmd = getCommand(cmdStr);
-893
-894      switch (cmd) {
-895      case SET_ADD:
-896        processSetAdd(args);
-897        break;
-898      case SET_REMOVE:
-899        processSetRemove(args);
-900        break;
-901      case SET_DELETE:
-902        processSetDelete(args);
-903        break;
-904      case SET_DESCRIBE:
-905        processSetDescribe(args);
-906        break;
-907      case SET_LIST:
-908        processSetList(args);
-909        break;
-910      default:
-911        break;
-912