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
This commit is contained in:
mbertozzi 2014-03-26 16:23:20 +00:00
parent b8975a0e8a
commit 8acd72dbba
2 changed files with 18 additions and 2 deletions

View File

@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.snapshot;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -665,6 +666,8 @@ public final class ExportSnapshot extends Configured implements Tool {
int filesMode = 0; int filesMode = 0;
int mappers = 0; int mappers = 0;
Configuration conf = getConf();
// Process command line args // Process command line args
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
String cmd = args[i]; String cmd = args[i];
@ -673,6 +676,11 @@ public final class ExportSnapshot extends Configured implements Tool {
snapshotName = args[++i]; snapshotName = args[++i];
} else if (cmd.equals("-copy-to")) { } else if (cmd.equals("-copy-to")) {
outputRoot = new Path(args[++i]); 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")) { } else if (cmd.equals("-no-checksum-verify")) {
verifyChecksum = false; verifyChecksum = false;
} else if (cmd.equals("-mappers")) { } else if (cmd.equals("-mappers")) {
@ -707,10 +715,11 @@ public final class ExportSnapshot extends Configured implements Tool {
printUsageAndExit(); printUsageAndExit();
} }
Configuration conf = getConf();
Path inputRoot = FSUtils.getRootDir(conf); 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); FileSystem outputFs = FileSystem.get(outputRoot.toUri(), conf);
LOG.debug("outputFs=" + outputFs.getUri().toString() + " outputRoot=" + outputRoot.toString());
Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, inputRoot); Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, inputRoot);
Path snapshotTmpDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshotName, outputRoot); 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(" -h|-help Show this help and exit.");
System.err.println(" -snapshot NAME Snapshot to restore."); System.err.println(" -snapshot NAME Snapshot to restore.");
System.err.println(" -copy-to NAME Remote destination hdfs://"); 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(" -no-checksum-verify Do not verify checksum.");
System.err.println(" -overwrite Rewrite the snapshot manifest if already exists"); System.err.println(" -overwrite Rewrite the snapshot manifest if already exists");
System.err.println(" -chuser USERNAME Change the owner of the files " + 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(" hbase " + getClass().getName() + " \\");
System.err.println(" -snapshot MySnapshot -copy-to hdfs://srv2:8082/hbase \\"); 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(" -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); System.exit(1);
} }

View File

@ -319,8 +319,10 @@ public class TestExportSnapshot {
conf.setBoolean(ExportSnapshot.CONF_TEST_RETRY, retry); conf.setBoolean(ExportSnapshot.CONF_TEST_RETRY, retry);
// Export Snapshot // Export Snapshot
Path sourceDir = TEST_UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir();
int res = ExportSnapshot.innerMain(conf, new String[] { int res = ExportSnapshot.innerMain(conf, new String[] {
"-snapshot", Bytes.toString(snapshotName), "-snapshot", Bytes.toString(snapshotName),
"-copy-from", sourceDir.toString(),
"-copy-to", copyDir.toString() "-copy-to", copyDir.toString()
}); });
return res; return res;