diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java index 8a4d48a..d952b73 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java @@ -50,59 +50,60 @@ import com.google.common.collect.Lists; @InterfaceStability.Evolving public final class BackupCommands { - private static final String USAGE = "Usage: hbase backup COMMAND\n" + private static final String USAGE = "Usage: hbase backup COMMAND [command-specific arguments]\n" + "where COMMAND is one of:\n" + " create create a new backup image\n" - + " cancel cancel an ongoing backup\n" + " delete delete an existing backup image\n" + " describe show the detailed information of a backup image\n" + " history show history of all successful backups\n" + " progress show the progress of the latest backup request\n" + " set backup set management\n" - + "Enter \'help COMMAND\' to see help message for each command\n"; + + "Run \'hbase backup help COMMAND\' to see help message for each command\n"; private static final String CREATE_CMD_USAGE = - "Usage: hbase backup create [tables] [-s name] [-convert] " - + "[-silent] [-w workers][-b bandwith]\n" - + " type \"full\" to create a full backup image;\n" - + " \"incremental\" to create an incremental backup image\n" - + " BACKUP_ROOT The full root path to store the backup image,\n" - + " the prefix can be hdfs, webhdfs or gpfs\n" + " Options:\n" - + " tables If no tables (\"\") are specified, all tables are backed up. " - + "Otherwise it is a\n" + " comma separated list of tables.\n" - + " -w number of parallel workers.\n" - + " -b bandwith per one worker (in MB sec)\n" - + " -set name of backup set" ; + "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" + + " BACKUP_ROOT The full root path to store the backup image,\n" + + " the prefix can be hdfs, webhdfs or gpfs\n" + + "Options:\n" + + " tables If no tables (\"\") are specified, all tables are backed up. " + + " 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])" ; private static final String PROGRESS_CMD_USAGE = "Usage: hbase backup progress \n" - + " backupId backup image id;\n"; + + " backupId backup image id\n"; private static final String DESCRIBE_CMD_USAGE = "Usage: hbase backup decsribe \n" - + " backupId backup image id\n"; + + " backupId backup image id\n"; private 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 name; "; + + " -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." ; private static final String DELETE_CMD_USAGE = "Usage: hbase backup delete \n" - + " backupId backup image id;\n"; + + " backupId backup image id\n"; private static final String CANCEL_CMD_USAGE = "Usage: hbase backup cancel \n" - + " backupId backup image id;\n"; + + " backupId backup image id\n"; private static final String SET_CMD_USAGE = "Usage: 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. " - + "Otherwise it is a\n" + " comma separated list of tables.\n" - + "where COMMAND is one of:\n" - + " add add tables to a set, crete set if needed\n" - + " remove remove tables from set\n" - + " list list all sets\n" - + " describe describes set\n" - + " delete delete backup set\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" + + "COMMAND is one of:\n" + + " add add tables to a set, create a set if needed\n" + + " remove remove tables from a set\n" + + " list list all backup sets in the system\n" + + " describe describe set\n" + + " delete delete backup set\n"; public static abstract class Command extends Configured { Command(Configuration conf) { @@ -159,21 +160,21 @@ public final class BackupCommands { @Override public void execute() throws IOException { if (cmdline == null || cmdline.getArgs() == null) { - System.out.println("ERROR: missing arguments"); - System.out.println(CREATE_CMD_USAGE); + System.err.println("ERROR: missing arguments"); + System.err.println(CREATE_CMD_USAGE); System.exit(-1); } String[] args = cmdline.getArgs(); if (args.length < 3 || args.length > 4) { - System.out.println("ERROR: wrong number of arguments"); - System.out.println(CREATE_CMD_USAGE); + System.err.println("ERROR: wrong number of arguments"); + System.err.println(CREATE_CMD_USAGE); System.exit(-1); } if (!BackupType.FULL.toString().equalsIgnoreCase(args[1]) && !BackupType.INCREMENTAL.toString().equalsIgnoreCase(args[1])) { - System.out.println("ERROR: invalid backup type"); - System.out.println(CREATE_CMD_USAGE); + System.err.println("ERROR: invalid backup type"); + System.err.println(CREATE_CMD_USAGE); System.exit(-1); } @@ -185,8 +186,11 @@ public final class BackupCommands { String setName = cmdline.getOptionValue("set"); tables = getTablesForSet(setName, conf); - if (tables == null) throw new IOException("Backup set '" + setName - + "' is either empty or does not exist"); + if (tables == null) { + System.err.println("ERROR: Backup set '" + setName+ "' is either empty or does not exist"); + System.err.println(CREATE_CMD_USAGE); + System.exit(-1); + } } else { tables = (args.length == 4) ? args[3] : null; } @@ -229,20 +233,20 @@ public final class BackupCommands { @Override public void execute() throws IOException { if (cmdline == null) { - System.out.println(USAGE); - System.exit(0); + System.err.println(USAGE); + System.exit(-1); } String[] args = cmdline.getArgs(); if (args == null || args.length == 0) { - System.out.println(USAGE); - System.exit(0); + System.err.println(USAGE); + System.exit(-1); } if (args.length != 2) { - System.out.println("Only support check help message of a single command type"); - System.out.println(USAGE); - System.exit(0); + System.err.println("Only supports help message of a single command type"); + System.err.println(USAGE); + System.exit(-1); } String type = args[1]; @@ -280,14 +284,14 @@ public final class BackupCommands { @Override public void execute() throws IOException { if (cmdline == null || cmdline.getArgs() == null) { - System.out.println("ERROR: missing arguments"); - System.out.println(DESCRIBE_CMD_USAGE); + System.err.println("ERROR: missing arguments"); + System.err.println(DESCRIBE_CMD_USAGE); System.exit(-1); } String[] args = cmdline.getArgs(); if (args.length != 2) { - System.out.println("ERROR: wrong number of arguments"); - System.out.println(DESCRIBE_CMD_USAGE); + System.err.println("ERROR: wrong number of arguments"); + System.err.println(DESCRIBE_CMD_USAGE); System.exit(-1); } @@ -318,8 +322,8 @@ public final class BackupCommands { } String[] args = cmdline.getArgs(); if (args.length > 2) { - System.out.println("ERROR: wrong number of arguments: " + args.length); - System.out.println(PROGRESS_CMD_USAGE); + System.err.println("ERROR: wrong number of arguments: " + args.length); + System.err.println(PROGRESS_CMD_USAGE); System.exit(-1); } @@ -348,8 +352,8 @@ public final class BackupCommands { @Override public void execute() throws IOException { if (cmdline == null || cmdline.getArgs() == null || cmdline.getArgs().length < 2) { - System.out.println("No backup id(s) was specified"); - System.out.println(PROGRESS_CMD_USAGE); + System.err.println("No backup id(s) was specified"); + System.err.println(DELETE_CMD_USAGE); System.exit(-1); } String[] args = cmdline.getArgs(); @@ -424,9 +428,17 @@ public final class BackupCommands { } private Path getBackupRootPath() { - String value = cmdline.getOptionValue("path"); - if (value == null) return null; - return new Path(value); + String value = null; + try{ + value = cmdline.getOptionValue("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.err.println(HISTORY_CMD_USAGE); + System.exit(-1); + } + return null; } private TableName getTableName() { @@ -435,15 +447,24 @@ public final class BackupCommands { try{ return TableName.valueOf(value); } catch (IllegalArgumentException e){ - System.out.println("Illegal argument: "+ value); - return null; + System.err.println("Illegal argument for table name: "+ value); + System.err.println(HISTORY_CMD_USAGE); + System.exit(-1); } + return null; } private int parseHistoryLength() { String value = cmdline.getOptionValue("n"); - if (value == null) return DEFAULT_HISTORY_LENGTH; - return Integer.parseInt(value); + 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.err.println(HISTORY_CMD_USAGE); + System.exit(-1); + } + return 0; } } @@ -466,8 +487,11 @@ public final class BackupCommands { // Command-line must have at least one element if (cmdline == null || cmdline.getArgs() == null || cmdline.getArgs().length < 2) { - throw new IOException("command line format"); + System.err.println("ERROR: Command line format"); + System.err.println(SET_CMD_USAGE); + System.exit(-1); } + String[] args = cmdline.getArgs(); String cmdStr = args[1]; BackupCommand cmd = getCommand(cmdStr); @@ -509,7 +533,9 @@ public final class BackupCommands { private void processSetDescribe(String[] args) throws IOException { if (args == null || args.length != 3) { - throw new RuntimeException("Wrong number of args: "+args.length); + System.err.println("ERROR: Wrong number of args for 'set describe' command: "+args.length); + System.err.println(SET_CMD_USAGE); + System.exit(-1); } String setName = args[2]; Configuration conf = getConf() != null? getConf(): HBaseConfiguration.create(); @@ -526,7 +552,9 @@ public final class BackupCommands { private void processSetDelete(String[] args) throws IOException { if (args == null || args.length != 3) { - throw new RuntimeException("Wrong number of args"); + System.err.println("ERROR: Wrong number of args for 'set delete' command: "+args.length); + System.err.println(SET_CMD_USAGE); + System.exit(-1); } String setName = args[2]; Configuration conf = getConf() != null? getConf(): HBaseConfiguration.create(); @@ -543,8 +571,11 @@ public final class BackupCommands { private void processSetRemove(String[] args) throws IOException { if (args == null || args.length != 4) { - throw new RuntimeException("Wrong args"); + System.err.println("ERROR: Wrong number of args for 'set remove' command: "+args.length); + System.err.println(SET_CMD_USAGE); + System.exit(-1); } + String setName = args[2]; String[] tables = args[3].split(","); Configuration conf = getConf() != null? getConf(): HBaseConfiguration.create(); @@ -556,7 +587,9 @@ public final class BackupCommands { private void processSetAdd(String[] args) throws IOException { if (args == null || args.length != 4) { - throw new RuntimeException("Wrong args"); + System.err.println("ERROR: Wrong number of args for 'set add' command: "+args.length); + System.err.println(SET_CMD_USAGE); + System.exit(-1); } String setName = args[2]; String[] tables = args[3].split(","); @@ -584,7 +617,10 @@ public final class BackupCommands { } else if (cmdStr.equals(SET_LIST_CMD)) { return BackupCommand.SET_LIST; } else { - throw new IOException("Unknown command for 'set' :" + cmdStr); + System.err.println("ERROR: Unknown command for 'set' :" + cmdStr); + System.err.println(SET_CMD_USAGE); + System.exit(-1); + return null; } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupDriver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupDriver.java index 8eb2ff8..a16d42d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupDriver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/BackupDriver.java @@ -52,9 +52,9 @@ public class BackupDriver extends AbstractHBaseTool { addOptNoArg("debug", "Enable debug loggings"); addOptNoArg("all", "All tables"); addOptWithArg("t", "Table name"); - addOptWithArg("b", "Bandwidth (MB/s)"); - addOptWithArg("w", "Number of workers"); - addOptWithArg("n", "History length"); + 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"); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java index 32ef218..978010a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java @@ -47,14 +47,13 @@ public class RestoreDriver extends AbstractHBaseTool { private static final String OPTION_OVERWRITE = "overwrite"; private static final String OPTION_CHECK = "check"; - private static final String OPTION_AUTOMATIC = "automatic"; 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] [-automatic]\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" @@ -65,8 +64,8 @@ public class RestoreDriver extends AbstractHBaseTool { + " -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, restore sequence and dependencies are checked\n" - + " and verified without executing the 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 ."; @@ -80,7 +79,6 @@ public class RestoreDriver extends AbstractHBaseTool { addOptNoArg(OPTION_OVERWRITE, "Overwrite the data if any of the restore target tables exists"); addOptNoArg(OPTION_CHECK, "Check restore sequence and dependencies"); - addOptNoArg(OPTION_AUTOMATIC, "Restore all dependencies"); addOptNoArg(OPTION_DEBUG, "Enable debug logging"); addOptWithArg(OPTION_SET, "Backup set name"); @@ -134,11 +132,13 @@ public class RestoreDriver extends AbstractHBaseTool { tables = getTablesForSet(conn, setName, conf); } catch(IOException e){ System.out.println("ERROR: "+ e.getMessage()+" for setName="+setName); + System.out.println(USAGE); return -2; } if (tables == null) { System.out.println("ERROR: Backup set '" + setName + "' is either empty or does not exist"); + System.out.println(USAGE); return -3; } tableMapping = (remainArgs.length > 2) ? remainArgs[2] : null;