diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupDriver.java hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupDriver.java
index 99b7460..4f17abf 100644
--- hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupDriver.java
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupDriver.java
@@ -26,7 +26,6 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.backup.BackupRestoreConstants.BackupCommand;
import org.apache.hadoop.hbase.backup.impl.BackupCommands;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;
@@ -39,27 +38,24 @@ import org.apache.log4j.Logger;
@InterfaceAudience.Private
@InterfaceStability.Evolving
-public class BackupDriver extends AbstractHBaseTool {
+public class BackupDriver extends AbstractHBaseTool implements BackupRestoreConstants {
private static final Log LOG = LogFactory.getLog(BackupDriver.class);
private CommandLine cmd;
-
- public BackupDriver() throws IOException
- {
+
+ public BackupDriver() throws IOException {
init();
}
-
+
protected void init() throws IOException {
// define supported options
- addOptNoArg("debug", "Enable debug loggings");
- addOptNoArg("all", "All tables");
- addOptWithArg("t", "Table name");
- addOptWithArg("b", "Bandwidth per worker (M/R task) in MB/s");
- addOptWithArg("w", "Number of workers (M/R tasks)");
- addOptWithArg("n", "History of backup length");
- addOptWithArg("set", "Backup set name");
- addOptWithArg("path", "Backup destination root directory path");
-
+ addOptNoArg(OPTION_DEBUG, OPTION_DEBUG_DESC);
+ addOptWithArg(OPTION_TABLE, OPTION_TABLE_DESC);
+ addOptWithArg(OPTION_BANDWIDTH, OPTION_BANDWIDTH_DESC);
+ addOptWithArg(OPTION_WORKERS, OPTION_WORKERS_DESC);
+ addOptWithArg(OPTION_RECORD_NUMBER, OPTION_RECORD_NUMBER_DESC);
+ addOptWithArg(OPTION_SET, OPTION_SET_DESC);
+ addOptWithArg(OPTION_PATH, OPTION_PATH_DESC);
// disable irrelevant loggers to avoid it mess up command output
LogUtils.disableUselessLoggers(LOG);
@@ -95,7 +91,7 @@ public class BackupDriver extends AbstractHBaseTool {
} else if (BackupCommand.SET.name().equalsIgnoreCase(cmd)) {
type = BackupCommand.SET;
} else {
- System.err.println("Unsupported command for backup: " + cmd);
+ System.out.println("Unsupported command for backup: " + cmd);
printToolUsage();
return -1;
}
@@ -110,13 +106,13 @@ public class BackupDriver extends AbstractHBaseTool {
// TODO: get rid of Command altogether?
BackupCommands.Command command = BackupCommands.createCommand(getConf(), type, this.cmd);
- if( type == BackupCommand.CREATE && conf != null) {
+ if (type == BackupCommand.CREATE && conf != null) {
((BackupCommands.CreateCommand) command).setConf(conf);
- }
+ }
try {
command.execute();
} catch (IOException e) {
- if (e.getMessage().equals(BackupCommands.INCORRECT_USAGE)){
+ if (e.getMessage().equals(BackupCommands.INCORRECT_USAGE)) {
return -1;
}
throw e;
@@ -143,10 +139,10 @@ public class BackupDriver extends AbstractHBaseTool {
Path hbasedir = FSUtils.getRootDir(conf);
URI defaultFs = hbasedir.getFileSystem(conf).getUri();
FSUtils.setFsDefault(conf, new Path(defaultFs));
- int ret = ToolRunner.run(conf, new BackupDriver(), args);
- System.exit(ret);
+ int ret = ToolRunner.run(conf, new BackupDriver(), args);
+ System.exit(ret);
}
-
+
@Override
public int run(String[] args) throws IOException {
if (conf == null) {
@@ -160,7 +156,7 @@ public class BackupDriver extends AbstractHBaseTool {
cmd = parseArgs(args);
cmdLineArgs = args;
} catch (Exception e) {
- System.err.println("Error when parsing command-line arguments: "+e.getMessage());
+ System.out.println("Error when parsing command-line arguments: " + e.getMessage());
printToolUsage();
return EXIT_FAILURE;
}
@@ -181,19 +177,19 @@ public class BackupDriver extends AbstractHBaseTool {
}
return ret;
}
-
+
protected boolean sanityCheckOptions(CommandLine cmd) {
boolean success = true;
for (String reqOpt : requiredOptions) {
if (!cmd.hasOption(reqOpt)) {
- System.err.println("Required option -" + reqOpt + " is missing");
+ System.out.println("Required option -" + reqOpt + " is missing");
success = false;
}
}
return success;
}
-
+
protected void printToolUsage() throws IOException {
- System.err.println(BackupCommands.USAGE);
+ System.out.println(BackupCommands.USAGE);
}
}
diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupRestoreConstants.java hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupRestoreConstants.java
index 76f0e75..1c82bbe 100644
--- hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupRestoreConstants.java
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupRestoreConstants.java
@@ -27,9 +27,47 @@ import org.apache.hadoop.hbase.classification.InterfaceStability;
*/
@InterfaceAudience.Private
@InterfaceStability.Stable
-public final class BackupRestoreConstants {
+public interface BackupRestoreConstants {
+ // Drivers option list
+ public static final String OPTION_OVERWRITE = "o";
+ public static final String OPTION_OVERWRITE_DESC =
+ "Overwrite data if any of the restore target tables exists";
+
+ public static final String OPTION_CHECK = "c";
+ public static final String OPTION_CHECK_DESC =
+ "Check restore sequence and dependencies only (does not execute the command)";
+
+ public static final String OPTION_SET = "s";
+ public static final String OPTION_SET_DESC = "Backup set name";
+ public static final String OPTION_SET_RESTORE_DESC =
+ "Backup set to restore, mutually exclusive with table list
";
+
+ public static final String OPTION_DEBUG = "d";
+ public static final String OPTION_DEBUG_DESC = "Enable debug loggings";
+
+ public static final String OPTION_TABLE = "t";
+ public static final String OPTION_TABLE_DESC = "Table name. If specified, only backup images,"+
+ " which contain this table will be listed.";
+
+ public static final String OPTION_BANDWIDTH = "b";
+ public static final String OPTION_BANDWIDTH_DESC = "Bandwidth per task (MapReduce task) in MB/s";
+
+ public static final String OPTION_WORKERS = "w";
+ public static final String OPTION_WORKERS_DESC = "Number of parallel MapReduce tasks to execute";
+ public static final String OPTION_RECORD_NUMBER = "n";
+ public static final String OPTION_RECORD_NUMBER_DESC = "Number of records of backup history. Default: 10";
+
+ public static final String OPTION_PATH = "p";
+ public static final String OPTION_PATH_DESC = "Backup destination root directory path";
+
+ public static final String OPTION_TABLE_MAPPING = "m";
+ public static final String OPTION_TABLE_MAPPING_DESC =
+ "A comma separated list of target tables. "+
+ "If specified, each table in must have a mapping";
+
+
// delimiter in tablename list in restore command
public static final String TABLENAME_DELIMITER_IN_COMMAND = ",";
@@ -50,7 +88,5 @@ public final class BackupRestoreConstants {
SET_ADD, SET_REMOVE, SET_DELETE, SET_DESCRIBE, SET_LIST
}
- private BackupRestoreConstants() {
- // Can't be instantiated with this ctor.
- }
+
}
diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java
index 67b5472..9043dcc 100644
--- hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java
@@ -22,6 +22,7 @@ import java.net.URI;
import java.util.List;
import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -42,33 +43,19 @@ import org.apache.hadoop.util.ToolRunner;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
-public class RestoreDriver extends AbstractHBaseTool {
+public class RestoreDriver extends AbstractHBaseTool implements BackupRestoreConstants{
private static final Log LOG = LogFactory.getLog(RestoreDriver.class);
private CommandLine cmd;
- private static final String OPTION_OVERWRITE = "overwrite";
- private static final String OPTION_CHECK = "check";
- private static final String OPTION_SET = "set";
- private static final String OPTION_DEBUG = "debug";
-
-
- private static final String USAGE =
- "Usage: hbase restore [-set set_name] [tableMapping] \n"
- + " [-overwrite] [-check]\n"
- + " backup_root_path The parent location where the backup images are stored\n"
- + " backup_id The id identifying the backup image\n"
- + " table(s) Table(s) from the backup image to be restored.\n"
- + " Tables are separated by comma.\n"
- + " Options:\n"
- + " tableMapping A comma separated list of target tables.\n"
- + " If specified, each table in must have a mapping.\n"
- + " -overwrite With this option, restore overwrites to the existing table "
- + "if there's any in\n"
- + " restore target. The existing table must be online before restore.\n"
- + " -check With this option, sequence and dependencies are checked\n"
- + " and verified without executing the restore command\n"
- + " -set set_name Backup set to restore, mutually exclusive with table list .";
+ private static final String USAGE_STRING =
+ "Usage: bin/hbase restore [options]\n"+
+ " backup_path Path to a backup destination root\n"+
+ " backup_id Backup image ID to restore" +
+ " table(s) Comma-separated list of tables to restore";
+
+
+ private static final String USAGE_FOOTER = "";
protected RestoreDriver() throws IOException
@@ -78,11 +65,13 @@ public class RestoreDriver extends AbstractHBaseTool {
protected void init() throws IOException {
// define supported options
- addOptNoArg(OPTION_OVERWRITE,
- "Overwrite the data if any of the restore target tables exists");
- addOptNoArg(OPTION_CHECK, "Check restore sequence and dependencies");
- addOptNoArg(OPTION_DEBUG, "Enable debug logging");
- addOptWithArg(OPTION_SET, "Backup set name");
+ addOptNoArg(OPTION_OVERWRITE, OPTION_OVERWRITE_DESC);
+ addOptNoArg(OPTION_CHECK, OPTION_CHECK_DESC);
+ addOptNoArg(OPTION_DEBUG, OPTION_DEBUG_DESC);
+ addOptWithArg(OPTION_SET, OPTION_SET_RESTORE_DESC);
+ addOptWithArg(OPTION_TABLE_MAPPING, OPTION_TABLE_MAPPING_DESC);
+
+
// disable irrelevant loggers to avoid it mess up command output
LogUtils.disableUselessLoggers(LOG);
@@ -97,8 +86,8 @@ public class RestoreDriver extends AbstractHBaseTool {
}
// whether to overwrite to existing table if any, false by default
- boolean isOverwrite = cmd.hasOption(OPTION_OVERWRITE);
- if (isOverwrite) {
+ boolean overwrite = cmd.hasOption(OPTION_OVERWRITE);
+ if (overwrite) {
LOG.debug("Found -overwrite option in restore command, "
+ "will overwrite to existing table if any in the restore target");
}
@@ -116,7 +105,6 @@ public class RestoreDriver extends AbstractHBaseTool {
String[] remainArgs = cmd.getArgs();
if (remainArgs.length < 3 && !cmd.hasOption(OPTION_SET) ||
(cmd.hasOption(OPTION_SET) && remainArgs.length < 2)) {
- System.err.println("ERROR: remain args length="+ remainArgs.length);
printToolUsage();
return -1;
}
@@ -124,7 +112,8 @@ public class RestoreDriver extends AbstractHBaseTool {
String backupRootDir = remainArgs[0];
String backupId = remainArgs[1];
String tables = null;
- String tableMapping = null;
+ String tableMapping = cmd.hasOption(OPTION_TABLE_MAPPING)?
+ cmd.getOptionValue(OPTION_TABLE_MAPPING): null;
try (final Connection conn = ConnectionFactory.createConnection(conf);
BackupAdmin client = new HBaseBackupAdmin(conn);) {
// Check backup set
@@ -133,33 +122,31 @@ public class RestoreDriver extends AbstractHBaseTool {
try{
tables = getTablesForSet(conn, setName, conf);
} catch(IOException e){
- System.err.println("ERROR: "+ e.getMessage()+" for setName="+setName);
+ System.out.println("ERROR: "+ e.getMessage()+" for setName="+setName);
printToolUsage();
return -2;
}
if (tables == null) {
- System.err.println("ERROR: Backup set '" + setName
+ System.out.println("ERROR: Backup set '" + setName
+ "' is either empty or does not exist");
printToolUsage();
return -3;
}
- tableMapping = (remainArgs.length > 2) ? remainArgs[2] : null;
} else {
tables = remainArgs[2];
- tableMapping = (remainArgs.length > 3) ? remainArgs[3] : null;
}
TableName[] sTableArray = BackupServerUtil.parseTableNames(tables);
TableName[] tTableArray = BackupServerUtil.parseTableNames(tableMapping);
if (sTableArray != null && tTableArray != null && (sTableArray.length != tTableArray.length)){
- System.err.println("ERROR: table mapping mismatch: " + tables + " : " + tableMapping);
+ System.out.println("ERROR: table mapping mismatch: " + tables + " : " + tableMapping);
printToolUsage();
return -4;
}
client.restore(RestoreServerUtil.createRestoreRequest(backupRootDir, backupId, check,
- sTableArray, tTableArray, isOverwrite));
+ sTableArray, tTableArray, overwrite));
} catch (Exception e){
e.printStackTrace();
return -5;
@@ -212,7 +199,7 @@ public class RestoreDriver extends AbstractHBaseTool {
cmd = parseArgs(args);
cmdLineArgs = args;
} catch (Exception e) {
- System.err.println("Error when parsing command-line arguments: " + e.getMessage());
+ System.out.println("Error when parsing command-line arguments: " + e.getMessage());
printToolUsage();
return EXIT_FAILURE;
}
@@ -239,7 +226,7 @@ public class RestoreDriver extends AbstractHBaseTool {
boolean success = true;
for (String reqOpt : requiredOptions) {
if (!cmd.hasOption(reqOpt)) {
- System.err.println("Required option -" + reqOpt + " is missing");
+ System.out.println("Required option -" + reqOpt + " is missing");
success = false;
}
}
@@ -247,6 +234,12 @@ public class RestoreDriver extends AbstractHBaseTool {
}
protected void printToolUsage() throws IOException {
- System.err.println(USAGE);
- }
+ System.out.println(USAGE_STRING);
+ HelpFormatter helpFormatter = new HelpFormatter();
+ helpFormatter.setLeftPadding(2);
+ helpFormatter.setDescPadding(8);
+ helpFormatter.setWidth(100);
+ helpFormatter.setSyntaxPrefix("Options:");
+ helpFormatter.printHelp(" ", null, options, USAGE_FOOTER);
+ }
}
diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java
index b2b4e78..62f2281 100644
--- hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java
@@ -19,12 +19,16 @@
package org.apache.hadoop.hbase.backup.impl;
import java.io.IOException;
+import java.net.URI;
import java.util.List;
import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
@@ -47,11 +51,11 @@ import com.google.common.collect.Lists;
*/
@InterfaceAudience.Private
@InterfaceStability.Evolving
-public final class BackupCommands {
+public final class BackupCommands implements BackupRestoreConstants {
public final static String INCORRECT_USAGE = "Incorrect usage";
- public static final String USAGE = "Usage: hbase backup COMMAND [command-specific arguments]\n"
+ public static final String USAGE = "Usage: bin/hbase backup COMMAND [command-specific arguments]\n"
+ "where COMMAND is one of:\n"
+ " create Create a new backup image\n"
+ " delete Delete an existing backup image\n"
@@ -59,43 +63,36 @@ public final class BackupCommands {
+ " history Show history of all successful backups\n"
+ " progress Show the progress of the latest backup request\n"
+ " set Backup set management\n"
- + "Run \'hbase backup COMMAND -h\' to see help message for each command\n";
+ + "Run \'bin/hbase backup COMMAND -h\' to see help message for each command\n";
public static final String CREATE_CMD_USAGE =
- "Usage: hbase backup create [tables] [-set name] "
- + "[-w workers][-b bandwith]\n"
- + " type \"full\" to create a full backup image\n"
- + " \"incremental\" to create an incremental backup image\n"
+ "Usage: bin/hbase backup create [tables] [options]\n"
+ + " type \"full\" to create a full backup image\n"
+ + " \"incremental\" to create an incremental backup image\n"
+ " backup_root Full path to store the backup image\n"
- + "Options:\n"
+ " tables If no tables (\"\") are specified, all tables are backed up.\n"
- + " otherwise it is a comma separated list of tables.\n"
- + " -w Number of parallel workers (MapReduce tasks).\n"
- + " -b Bandwith per one worker (MapReduce task) in MBs per sec\n"
- + " -set Name of backup set to use (mutually exclusive with [tables])" ;
+ + " otherwise it is a comma separated list of tables.";
- public static final String PROGRESS_CMD_USAGE = "Usage: hbase backup progress \n"
+
+ public static final String PROGRESS_CMD_USAGE = "Usage: bin/hbase backup progress \n"
+ " backupId Backup image id\n";
public static final String NO_INFO_FOUND = "No info was found for backup id: ";
- public static final String DESCRIBE_CMD_USAGE = "Usage: hbase backup decsribe \n"
+ public static final String DESCRIBE_CMD_USAGE = "Usage: bin/hbase backup describe \n"
+ " backupId Backup image id\n";
public static final String HISTORY_CMD_USAGE =
- "Usage: hbase backup history [-path BACKUP_ROOT] [-n N] [-t table]\n"
- + " -n N Show up to N last backup sessions, default - 10\n"
- + " -path Backup root path\n"
- + " -t table Table name. If specified, only backup images which contain this table\n"
- + " will be listed." ;
+ "Usage: bin/hbase backup history [options]";
+
- public static final String DELETE_CMD_USAGE = "Usage: hbase backup delete \n"
+ public static final String DELETE_CMD_USAGE = "Usage: bin/hbase backup delete \n"
+ " backupId Backup image id\n";
- public static final String CANCEL_CMD_USAGE = "Usage: hbase backup cancel \n"
+ public static final String CANCEL_CMD_USAGE = "Usage: bin/hbase backup cancel \n"
+ " backupId Backup image id\n";
- public static final String SET_CMD_USAGE = "Usage: hbase backup set COMMAND [name] [tables]\n"
+ public static final String SET_CMD_USAGE = "Usage: bin/hbase backup set COMMAND [name] [tables]\n"
+ " name Backup set name\n"
+ " tables If no tables (\"\") are specified, all tables will belong to the set.\n"
+ " Otherwise it is a comma separated list of tables.\n"
@@ -106,6 +103,8 @@ public final class BackupCommands {
+ " describe Describe backup set\n"
+ " delete Delete backup set\n";
+ public static final String USAGE_FOOTER = "";
+
public static abstract class Command extends Configured {
CommandLine cmdline;
@@ -176,43 +175,56 @@ public final class BackupCommands {
public void execute() throws IOException {
super.execute();
if (cmdline == null || cmdline.getArgs() == null) {
- System.err.println("ERROR: missing arguments");
printUsage();
throw new IOException(INCORRECT_USAGE);
}
String[] args = cmdline.getArgs();
if (args.length < 3 || args.length > 4) {
- System.err.println("ERROR: wrong number of arguments: "+ args.length);
printUsage();
throw new IOException(INCORRECT_USAGE);
}
if (!BackupType.FULL.toString().equalsIgnoreCase(args[1])
&& !BackupType.INCREMENTAL.toString().equalsIgnoreCase(args[1])) {
- System.err.println("ERROR: invalid backup type: "+ args[1]);
+ System.out.println("ERROR: invalid backup type: "+ args[1]);
printUsage();
throw new IOException(INCORRECT_USAGE);
}
-
+ if(!verifyPath(args[2])) {
+ System.out.println("ERROR: invalid backup destination: "+ args[2]);
+ printUsage();
+ throw new IOException(INCORRECT_USAGE);
+ }
+
String tables = null;
Configuration conf = getConf() != null? getConf(): HBaseConfiguration.create();
+ // Check if we have both: backup set and list of tables
+ if(args.length == 4 && cmdline.hasOption(OPTION_SET)) {
+ System.out.println("ERROR: You can specify either backup set or list"+
+ " of tables, but not both");
+ printUsage();
+ throw new IOException(INCORRECT_USAGE);
+ }
+
// Check backup set
String setName = null;
- if (cmdline.hasOption("set")) {
- setName = cmdline.getOptionValue("set");
+ if (cmdline.hasOption(OPTION_SET)) {
+ setName = cmdline.getOptionValue(OPTION_SET);
tables = getTablesForSet(setName, conf);
if (tables == null) {
- System.err.println("ERROR: Backup set '" + setName+ "' is either empty or does not exist");
+ System.out.println("ERROR: Backup set '" + setName+ "' is either empty or does not exist");
printUsage();
throw new IOException(INCORRECT_USAGE);
}
} else {
tables = (args.length == 4) ? args[3] : null;
}
- int bandwidth = cmdline.hasOption('b') ? Integer.parseInt(cmdline.getOptionValue('b')) : -1;
- int workers = cmdline.hasOption('w') ? Integer.parseInt(cmdline.getOptionValue('w')) : -1;
+ int bandwidth = cmdline.hasOption(OPTION_BANDWIDTH) ?
+ Integer.parseInt(cmdline.getOptionValue(OPTION_BANDWIDTH)) : -1;
+ int workers = cmdline.hasOption(OPTION_WORKERS) ?
+ Integer.parseInt(cmdline.getOptionValue(OPTION_WORKERS)) : -1;
try (Connection conn = ConnectionFactory.createConnection(getConf());
HBaseBackupAdmin admin = new HBaseBackupAdmin(conn);) {
@@ -225,12 +237,24 @@ public final class BackupCommands {
String backupId = admin.backupTables(request);
System.out.println("Backup session "+ backupId+" finished. Status: SUCCESS");
} catch (IOException e) {
- System.err.println("Backup session finished. Status: FAILURE");
+ System.out.println("Backup session finished. Status: FAILURE");
throw e;
}
}
-
+ private boolean verifyPath(String path) {
+ try{
+ Path p = new Path(path);
+ Configuration conf = getConf() != null? getConf():
+ HBaseConfiguration.create();
+ URI uri = p.toUri();
+ if(uri.getScheme() == null) return false;
+ FileSystem fs = FileSystem.get(uri, conf);
+ return true;
+ } catch(Exception e){
+ return false;
+ }
+ }
private String getTablesForSet(String name, Configuration conf)
throws IOException {
@@ -244,7 +268,19 @@ public final class BackupCommands {
@Override
protected void printUsage() {
- System.err.println(CREATE_CMD_USAGE);
+ System.out.println(CREATE_CMD_USAGE);
+ Options options = new Options();
+ options.addOption(OPTION_WORKERS, true, OPTION_WORKERS_DESC);
+ options.addOption(OPTION_BANDWIDTH, true, OPTION_BANDWIDTH_DESC);
+ options.addOption(OPTION_SET, true, OPTION_SET_RESTORE_DESC);
+
+ HelpFormatter helpFormatter = new HelpFormatter();
+ helpFormatter.setLeftPadding(2);
+ helpFormatter.setDescPadding(8);
+ helpFormatter.setWidth(100);
+ helpFormatter.setSyntaxPrefix("Options:");
+ helpFormatter.printHelp(" ", null, options, USAGE_FOOTER);
+
}
}
@@ -270,7 +306,7 @@ public final class BackupCommands {
}
if (args.length != 2) {
- System.err.println("Only supports help message of a single command type");
+ System.out.println("ERROR: Only supports help message of a single command type");
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -299,7 +335,7 @@ public final class BackupCommands {
@Override
protected void printUsage() {
- System.err.println(USAGE);
+ System.out.println(USAGE);
}
}
@@ -314,13 +350,11 @@ public final class BackupCommands {
public void execute() throws IOException {
super.execute();
if (cmdline == null || cmdline.getArgs() == null) {
- System.err.println("ERROR: missing arguments");
printUsage();
throw new IOException(INCORRECT_USAGE);
}
String[] args = cmdline.getArgs();
if (args.length != 2) {
- System.err.println("ERROR: wrong number of arguments");
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -331,7 +365,7 @@ public final class BackupCommands {
final BackupSystemTable sysTable = new BackupSystemTable(conn);) {
BackupInfo info = sysTable.readBackupInfo(backupId);
if (info == null) {
- System.err.println("ERROR: " + backupId + " does not exist");
+ System.out.println("ERROR: " + backupId + " does not exist");
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -341,7 +375,7 @@ public final class BackupCommands {
@Override
protected void printUsage() {
- System.err.println(DESCRIBE_CMD_USAGE);
+ System.out.println(DESCRIBE_CMD_USAGE);
}
}
@@ -375,7 +409,7 @@ public final class BackupCommands {
BackupInfo info = sysTable.readBackupInfo(backupId);
int progress = info == null? -1: info.getProgress();
if(progress < 0){
- System.err.println(NO_INFO_FOUND + backupId);
+ System.out.println(NO_INFO_FOUND + backupId);
} else{
System.out.println(backupId+" progress=" + progress+"%");
}
@@ -384,7 +418,7 @@ public final class BackupCommands {
@Override
protected void printUsage() {
- System.err.println(PROGRESS_CMD_USAGE);
+ System.out.println(PROGRESS_CMD_USAGE);
}
}
@@ -399,7 +433,6 @@ public final class BackupCommands {
public void execute() throws IOException {
super.execute();
if (cmdline == null || cmdline.getArgs() == null || cmdline.getArgs().length < 2) {
- System.err.println("No backup id(s) was specified");
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -419,7 +452,7 @@ public final class BackupCommands {
@Override
protected void printUsage() {
- System.err.println(DELETE_CMD_USAGE);
+ System.out.println(DELETE_CMD_USAGE);
}
}
@@ -506,40 +539,40 @@ public final class BackupCommands {
private Path getBackupRootPath() throws IOException {
String value = null;
try{
- value = cmdline.getOptionValue("path");
+ value = cmdline.getOptionValue(OPTION_PATH);
if (value == null) return null;
return new Path(value);
} catch (IllegalArgumentException e) {
- System.err.println("ERROR: Illegal argument for backup root path: "+ value);
+ System.out.println("ERROR: Illegal argument for backup root path: "+ value);
printUsage();
throw new IOException(INCORRECT_USAGE);
}
}
private TableName getTableName() throws IOException {
- String value = cmdline.getOptionValue("t");
+ String value = cmdline.getOptionValue(OPTION_TABLE);
if (value == null) return null;
try{
return TableName.valueOf(value);
} catch (IllegalArgumentException e){
- System.err.println("Illegal argument for table name: "+ value);
+ System.out.println("Illegal argument for table name: "+ value);
printUsage();
throw new IOException(INCORRECT_USAGE);
}
}
private String getTableSetName() throws IOException {
- String value = cmdline.getOptionValue("set");
+ String value = cmdline.getOptionValue(OPTION_SET);
return value;
}
private int parseHistoryLength() throws IOException {
- String value = cmdline.getOptionValue("n");
+ String value = cmdline.getOptionValue(OPTION_RECORD_NUMBER);
try{
if (value == null) return DEFAULT_HISTORY_LENGTH;
return Integer.parseInt(value);
} catch(NumberFormatException e) {
- System.err.println("Illegal argument for history length: "+ value);
+ System.out.println("Illegal argument for history length: "+ value);
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -547,7 +580,19 @@ public final class BackupCommands {
@Override
protected void printUsage() {
- System.err.println(HISTORY_CMD_USAGE);
+ System.out.println(HISTORY_CMD_USAGE);
+ Options options = new Options();
+ options.addOption(OPTION_RECORD_NUMBER, true, OPTION_RECORD_NUMBER_DESC);
+ options.addOption(OPTION_PATH, true, OPTION_PATH_DESC);
+ options.addOption(OPTION_TABLE, true, OPTION_TABLE_DESC);
+ options.addOption(OPTION_SET, true, OPTION_SET_DESC);
+
+ HelpFormatter helpFormatter = new HelpFormatter();
+ helpFormatter.setLeftPadding(2);
+ helpFormatter.setDescPadding(8);
+ helpFormatter.setWidth(100);
+ helpFormatter.setSyntaxPrefix("Options:");
+ helpFormatter.printHelp(" ", null, options, USAGE_FOOTER);
}
}
@@ -568,7 +613,6 @@ public final class BackupCommands {
super.execute();
// Command-line must have at least one element
if (cmdline == null || cmdline.getArgs() == null || cmdline.getArgs().length < 2) {
- System.err.println("ERROR: Command line format");
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -614,8 +658,6 @@ public final class BackupCommands {
private void processSetDescribe(String[] args) throws IOException {
if (args == null || args.length != 3) {
- System.err.println("ERROR: Wrong number of args for 'set describe' command: "
- + numOfArgs(args));
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -635,8 +677,6 @@ public final class BackupCommands {
private void processSetDelete(String[] args) throws IOException {
if (args == null || args.length != 3) {
- System.err.println("ERROR: Wrong number of args for 'set delete' command: "
- + numOfArgs(args));
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -655,8 +695,6 @@ public final class BackupCommands {
private void processSetRemove(String[] args) throws IOException {
if (args == null || args.length != 4) {
- System.err.println("ERROR: Wrong number of args for 'set remove' command: "
- + numOfArgs(args));
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -672,8 +710,6 @@ public final class BackupCommands {
private void processSetAdd(String[] args) throws IOException {
if (args == null || args.length != 4) {
- System.err.println("ERROR: Wrong number of args for 'set add' command: "
- + numOfArgs(args));
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -703,7 +739,7 @@ public final class BackupCommands {
} else if (cmdStr.equals(SET_LIST_CMD)) {
return BackupCommand.SET_LIST;
} else {
- System.err.println("ERROR: Unknown command for 'set' :" + cmdStr);
+ System.out.println("ERROR: Unknown command for 'set' :" + cmdStr);
printUsage();
throw new IOException(INCORRECT_USAGE);
}
@@ -711,7 +747,7 @@ public final class BackupCommands {
@Override
protected void printUsage() {
- System.err.println(SET_CMD_USAGE);
+ System.out.println(SET_CMD_USAGE);
}
}
diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java hbase-server/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
index 485eef7..2e4c167 100644
--- hbase-server/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java
@@ -49,7 +49,7 @@ public abstract class AbstractHBaseTool implements Tool {
private static final Log LOG = LogFactory.getLog(AbstractHBaseTool.class);
- private final Options options = new Options();
+ protected final Options options = new Options();
protected Configuration conf = null;
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupCommandLineTool.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupCommandLineTool.java
index 1e267d2..89e5da6 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupCommandLineTool.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupCommandLineTool.java
@@ -41,228 +41,228 @@ public class TestBackupCommandLineTool {
@Test
public void testBackupDriverDescribeHelp() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"describe", "-help" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup decsribe ") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup describe ") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"describe", "-h" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup decsribe ") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup describe ") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"describe" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup decsribe ") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup describe ") >= 0);
}
@Test
public void testBackupDriverCreateHelp() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"create", "-help" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup create") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup create") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"create", "-h" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup create") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup create") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"create"};
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup create") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup create") >= 0);
}
@Test
public void testBackupDriverHistoryHelp () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"history", "-help" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup history") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup history") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"history", "-h" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup history") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup history") >= 0);
}
@Test
public void testBackupDriverDeleteHelp () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"delete", "-help" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup delete") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup delete") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"delete", "-h" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup delete") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup delete") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"delete" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup delete") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup delete") >= 0);
}
@Test
public void testBackupDriverProgressHelp() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"progress", "-help" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup progress") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup progress") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"progress", "-h" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup progress") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup progress") >= 0);
}
@Test
public void testBackupDriverSetHelp () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"set", "-help" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup set") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup set") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"set", "-h" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup set") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup set") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"set"};
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup set") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup set") >= 0);
}
@Test
public void testBackupDriverHelp () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"-help" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"-h" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup") >= 0);
}
@Test
public void testRestoreDriverHelp () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"-help" };
ToolRunner.run(conf, new RestoreDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase restore") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase restore") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"-h" };
ToolRunner.run(conf, new RestoreDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase restore") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase restore") >= 0);
}
@Test
public void testBackupDriverUnrecognizedCommand () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"command" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"command" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup") >= 0);
}
@@ -270,117 +270,143 @@ public class TestBackupCommandLineTool {
@Test
public void testBackupDriverUnrecognizedOption () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"create", "-xx" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"describe", "-xx" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"history", "-xx" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"delete", "-xx" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"set", "-xx" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup") >= 0);
}
@Test
public void testRestoreDriverUnrecognizedOption () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"-xx" };
ToolRunner.run(conf, new RestoreDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase restore") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase restore") >= 0);
}
@Test
public void testBackupDriverCreateWrongArgNumber () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"create" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup create") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup create") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"create", "22" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup create") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup create") >= 0);
baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"create", "22", "22", "22", "22", "22" };
ToolRunner.run(conf, new BackupDriver(), args);
output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup create") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup create") >= 0);
}
@Test
public void testBackupDriverDeleteWrongArgNumber () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"delete" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup delete") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup delete") >= 0);
}
@Test
public void testBackupDriverHistoryWrongArgs () throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
String[] args = new String[]{"history", "-n", "xx" };
ToolRunner.run(conf, new BackupDriver(), args);
String output = baos.toString();
System.out.println(baos.toString());
- assertTrue(output.indexOf("Usage: hbase backup history") >= 0);
+ assertTrue(output.indexOf("Usage: bin/hbase backup history") >= 0);
+
+ }
+
+ @Test
+ public void testBackupDriverWrongBackupDestination () throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(baos));
+ String[] args = new String[]{"create", "full", "clicks" };
+ ToolRunner.run(conf, new BackupDriver(), args);
+
+ String output = baos.toString();
+ System.out.println(baos.toString());
+ assertTrue(output.indexOf("ERROR: invalid backup destination") >= 0);
+
+ }
+
+ @Test
+ public void testBackupDriverBackupSetAndList () throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(baos));
+ String[] args = new String[]{"create", "full", "file:/", "clicks", "-s", "s" };
+ ToolRunner.run(conf, new BackupDriver(), args);
+
+ String output = baos.toString();
+ System.out.println(baos.toString());
+ assertTrue(output.indexOf("ERROR: You can specify either backup set or list") >= 0);
}
}
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDelete.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDelete.java
index d3c451d..a09dd0c 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDelete.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDelete.java
@@ -28,7 +28,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
import org.apache.hadoop.hbase.testclassification.LargeTests;
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDescribe.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDescribe.java
index 0a2f2e1..b7d41e0 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDescribe.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDescribe.java
@@ -57,7 +57,7 @@ public class TestBackupDescribe extends TestBackupBase {
assertTrue(ret < 0);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baos));
+ System.setOut(new PrintStream(baos));
args = new String[]{"progress" };
ToolRunner.run(TEST_UTIL.getConfiguration(), new BackupDriver(), args);
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupShowHistory.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupShowHistory.java
index 4594338..d023406 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupShowHistory.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupShowHistory.java
@@ -82,7 +82,7 @@ public class TestBackupShowHistory extends TestBackupBase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos));
- String[] args = new String[]{"history", "-n", "10", "-path", BACKUP_ROOT_DIR };
+ String[] args = new String[]{"history", "-n", "10", "-p", BACKUP_ROOT_DIR };
// Run backup
int ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertTrue(ret == 0);
@@ -135,8 +135,8 @@ public class TestBackupShowHistory extends TestBackupBase {
}
assertTrue(success);
- args = new String[]{"history", "-n", "10", "-path", BACKUP_ROOT_DIR,
- "-t", "table1", "-set", "backup"};
+ args = new String[]{"history", "-n", "10", "-p", BACKUP_ROOT_DIR,
+ "-t", "table1", "-s", "backup"};
// Run backup
ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertTrue(ret == 0);
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackup.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackup.java
index e9aa478..94b5bc2 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackup.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackup.java
@@ -19,20 +19,16 @@ package org.apache.hadoop.hbase.backup;
import static org.junit.Assert.assertTrue;
-import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.util.ToolRunner;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import com.google.common.collect.Lists;
-
@Category(LargeTests.class)
public class TestFullBackup extends TestBackupBase {
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackupSet.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackupSet.java
index db9da3b..1c67aeb 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackupSet.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackupSet.java
@@ -59,7 +59,7 @@ public class TestFullBackupSet extends TestBackupBase {
assertTrue(names.size() == 1);
assertTrue(names.get(0).equals(table1));
- String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-set", name };
+ String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-s", name };
// Run backup
int ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertTrue(ret == 0);
@@ -73,7 +73,7 @@ public class TestFullBackupSet extends TestBackupBase {
// Restore from set into other table
args = new String[]{BACKUP_ROOT_DIR, backupId,
- "-set", name, table1_restore.getNameAsString(), "-overwrite" };
+ "-s", name, "-m", table1_restore.getNameAsString(), "-o" };
// Run backup
ret = ToolRunner.run(conf1, new RestoreDriver(), args);
assertTrue(ret == 0);
@@ -95,7 +95,7 @@ public class TestFullBackupSet extends TestBackupBase {
LOG.info("test full backup, backup set does not exist");
String name = "name1";
- String[] args = new String[]{"create", "full", BACKUP_ROOT_DIR, "-set", name };
+ String[] args = new String[]{"create", "full", BACKUP_ROOT_DIR, "-s", name };
// Run backup
int ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertTrue(ret != 0);
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackupSetRestoreSet.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackupSetRestoreSet.java
index 4a14061..c533b0d 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackupSetRestoreSet.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullBackupSetRestoreSet.java
@@ -54,7 +54,7 @@ public class TestFullBackupSetRestoreSet extends TestBackupBase {
assertTrue(names.size() == 1);
assertTrue(names.get(0).equals(table1));
- String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-set", name };
+ String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-s", name };
// Run backup
int ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertTrue(ret == 0);
@@ -68,8 +68,8 @@ public class TestFullBackupSetRestoreSet extends TestBackupBase {
// Restore from set into other table
args =
- new String[] { BACKUP_ROOT_DIR, backupId, "-set", name, table1_restore.getNameAsString(),
- "-overwrite" };
+ new String[] { BACKUP_ROOT_DIR, backupId, "-s", name, "-m", table1_restore.getNameAsString(),
+ "-o" };
// Run backup
ret = ToolRunner.run(conf1, new RestoreDriver(), args);
assertTrue(ret == 0);
@@ -98,7 +98,7 @@ public class TestFullBackupSetRestoreSet extends TestBackupBase {
assertTrue(names.size() == 1);
assertTrue(names.get(0).equals(table1));
- String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-set", name };
+ String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-s", name };
// Run backup
int ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertTrue(ret == 0);
@@ -111,7 +111,7 @@ public class TestFullBackupSetRestoreSet extends TestBackupBase {
TEST_UTIL.deleteTable(table1);
// Restore from set into other table
- args = new String[] { BACKUP_ROOT_DIR, backupId, "-set", name, "-overwrite" };
+ args = new String[] { BACKUP_ROOT_DIR, backupId, "-s", name, "-o" };
// Run backup
ret = ToolRunner.run(conf1, new RestoreDriver(), args);
assertTrue(ret == 0);
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullRestore.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullRestore.java
index a01801d..bd2bfff 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullRestore.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestFullRestore.java
@@ -34,31 +34,6 @@ public class TestFullRestore extends TestBackupBase {
private static final Log LOG = LogFactory.getLog(TestFullRestore.class);
- /*
- void restoreTables(String backupRootDir,
- String backupId, boolean check, boolean autoRestore, List sTable,
- List tTable, boolean isOverwrite) throws IOException {
- Connection conn = null;
- HBaseAdmin admin = null;
- RestoreRequest request = new RestoreRequest();
- request.setAutoRestore(autoRestore).setDependencyCheckOnly(check).setOverwrite(isOverwrite);
- request.setBackupId(backupId).setBackupRootDir(backupRootDir);
- request.setTableList(sTable).setTargetTableList(tTable);
- try {
- conn = ConnectionFactory.createConnection(conf1);
- admin = (HBaseAdmin) conn.getAdmin();
- admin.restoreTablesSync(request);
- } finally {
- if (admin != null) {
- admin.close();
- }
- if (conn != null) {
- conn.close();
- }
- }
- }
- */
-
/**
* Verify that a single table is restored to a new table
* @throws Exception
@@ -97,7 +72,7 @@ public class TestFullRestore extends TestBackupBase {
assertTrue(checkSucceeded(backupId));
//restore [tableMapping]
String[] args = new String[]{BACKUP_ROOT_DIR, backupId,
- table1.getNameAsString(), table1_restore.getNameAsString() };
+ table1.getNameAsString(), "-m", table1_restore.getNameAsString() };
// Run backup
int ret = ToolRunner.run(conf1, new RestoreDriver(), args);
@@ -150,7 +125,7 @@ public class TestFullRestore extends TestBackupBase {
//restore [tableMapping]
String[] args = new String[]{BACKUP_ROOT_DIR, backupId,
StringUtils.join(restore_tableset, ","),
- StringUtils.join(tablemap, ",") };
+ "-m", StringUtils.join(tablemap, ",") };
// Run backup
int ret = ToolRunner.run(conf1, new RestoreDriver(), args);
@@ -199,7 +174,7 @@ public class TestFullRestore extends TestBackupBase {
TableName[] tableset = new TableName[] { table1 };
//restore [tableMapping]
String[] args = new String[]{BACKUP_ROOT_DIR, backupId,
- StringUtils.join(tableset, ","), "-overwrite" };
+ StringUtils.join(tableset, ","), "-o" };
// Run restore
int ret = ToolRunner.run(conf1, new RestoreDriver(), args);
assertTrue(ret==0);
@@ -243,7 +218,7 @@ public class TestFullRestore extends TestBackupBase {
TableName[] restore_tableset = new TableName[] { table2, table3 };
//restore [tableMapping]
String[] args = new String[]{BACKUP_ROOT_DIR, backupId,
- StringUtils.join(restore_tableset, ","), "-overwrite" };
+ StringUtils.join(restore_tableset, ","), "-o" };
// Run backup
int ret = ToolRunner.run(conf1, new RestoreDriver(), args);
@@ -294,7 +269,7 @@ public class TestFullRestore extends TestBackupBase {
TableName[] tablemap = new TableName[] { table1_restore };
String[] args = new String[]{BACKUP_ROOT_DIR, backupId,
StringUtils.join(tableset, ","),
- StringUtils.join(tablemap, ",") };
+ "-m", StringUtils.join(tablemap, ",") };
// Run restore
int ret = ToolRunner.run(conf1, new RestoreDriver(), args);
assertTrue(ret != 0);
@@ -339,7 +314,7 @@ public class TestFullRestore extends TestBackupBase {
TableName[] tablemap = new TableName[] { table2_restore, table3_restore };
String[] args = new String[]{BACKUP_ROOT_DIR, backupId,
StringUtils.join(restore_tableset, ","),
- StringUtils.join(tablemap, ",") };
+ "-m", StringUtils.join(tablemap, ",") };
// Run restore
int ret = ToolRunner.run(conf1, new RestoreDriver(), args);
assertTrue(ret != 0);
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestIncrementalBackup.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestIncrementalBackup.java
index 705a066..9a845ba 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestIncrementalBackup.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestIncrementalBackup.java
@@ -22,13 +22,10 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map.Entry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.MiniHBaseCluster;
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestRemoteBackup.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestRemoteBackup.java
index 42f0ee7..2bc9aa0 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestRemoteBackup.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestRemoteBackup.java
@@ -31,7 +31,6 @@ import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils;
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.Threads;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;
diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestSystemTableSnapshot.java hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestSystemTableSnapshot.java
index 0c035db..0979ef8 100644
--- hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestSystemTableSnapshot.java
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestSystemTableSnapshot.java
@@ -18,11 +18,6 @@
package org.apache.hadoop.hbase.backup;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.TableName;
@@ -32,8 +27,6 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import com.google.common.collect.Lists;
-
@Category(LargeTests.class)
public class TestSystemTableSnapshot extends TestBackupBase {