From 8acd72dbbaf23b6d7c52bfbf443c89377b6266f1 Mon Sep 17 00:00:00 2001 From: mbertozzi Date: Wed, 26 Mar 2014 16:23:20 +0000 Subject: [PATCH] HBASE-10825 Add copy-from option to ExportSnapshot git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1581909 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/snapshot/ExportSnapshot.java | 18 ++++++++++++++++-- .../hbase/snapshot/TestExportSnapshot.java | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java index 3f54f37ba80..9cdd57a6fac 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.snapshot; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -665,6 +666,8 @@ public final class ExportSnapshot extends Configured implements Tool { int filesMode = 0; int mappers = 0; + Configuration conf = getConf(); + // Process command line args for (int i = 0; i < args.length; i++) { String cmd = args[i]; @@ -673,6 +676,11 @@ public final class ExportSnapshot extends Configured implements Tool { snapshotName = args[++i]; } else if (cmd.equals("-copy-to")) { outputRoot = new Path(args[++i]); + } else if (cmd.equals("-copy-from")) { + Path sourceDir = new Path(args[++i]); + URI defaultFs = sourceDir.getFileSystem(conf).getUri(); + FSUtils.setFsDefault(conf, new Path(defaultFs)); + FSUtils.setRootDir(conf, sourceDir); } else if (cmd.equals("-no-checksum-verify")) { verifyChecksum = false; } else if (cmd.equals("-mappers")) { @@ -707,10 +715,11 @@ public final class ExportSnapshot extends Configured implements Tool { printUsageAndExit(); } - Configuration conf = getConf(); Path inputRoot = FSUtils.getRootDir(conf); - FileSystem inputFs = FileSystem.get(conf); + FileSystem inputFs = FileSystem.get(inputRoot.toUri(), conf); + LOG.debug("inputFs=" + inputFs.getUri().toString() + " inputRoot=" + inputRoot); FileSystem outputFs = FileSystem.get(outputRoot.toUri(), conf); + LOG.debug("outputFs=" + outputFs.getUri().toString() + " outputRoot=" + outputRoot.toString()); Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, inputRoot); Path snapshotTmpDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshotName, outputRoot); @@ -803,6 +812,7 @@ public final class ExportSnapshot extends Configured implements Tool { System.err.println(" -h|-help Show this help and exit."); System.err.println(" -snapshot NAME Snapshot to restore."); System.err.println(" -copy-to NAME Remote destination hdfs://"); + System.err.println(" -copy-from NAME Input folder hdfs:// (default hbase.rootdir)"); System.err.println(" -no-checksum-verify Do not verify checksum."); System.err.println(" -overwrite Rewrite the snapshot manifest if already exists"); System.err.println(" -chuser USERNAME Change the owner of the files " + @@ -818,6 +828,10 @@ public final class ExportSnapshot extends Configured implements Tool { System.err.println(" hbase " + getClass().getName() + " \\"); System.err.println(" -snapshot MySnapshot -copy-to hdfs://srv2:8082/hbase \\"); System.err.println(" -chuser MyUser -chgroup MyGroup -chmod 700 -mappers 16"); + System.err.println(); + System.err.println(" hbase " + getClass().getName() + " \\"); + System.err.println(" -snapshot MySnapshot -copy-from hdfs://srv2:8082/hbase \\"); + System.err.println(" -copy-to hdfs://srv1:50070/hbase \\"); System.exit(1); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java index d29ec8c54d4..9b21f36da40 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java @@ -319,8 +319,10 @@ public class TestExportSnapshot { conf.setBoolean(ExportSnapshot.CONF_TEST_RETRY, retry); // Export Snapshot + Path sourceDir = TEST_UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); int res = ExportSnapshot.innerMain(conf, new String[] { "-snapshot", Bytes.toString(snapshotName), + "-copy-from", sourceDir.toString(), "-copy-to", copyDir.toString() }); return res;