HBASE-16939 ExportSnapshot: set owner and permission on right directory
Signed-off-by: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
This commit is contained in:
parent
36aa416856
commit
c4be87d050
|
@ -939,6 +939,19 @@ public class ExportSnapshot extends Configured implements Tool {
|
||||||
Path outputSnapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(targetName, outputRoot);
|
Path outputSnapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(targetName, outputRoot);
|
||||||
Path initialOutputSnapshotDir = skipTmp ? outputSnapshotDir : snapshotTmpDir;
|
Path initialOutputSnapshotDir = skipTmp ? outputSnapshotDir : snapshotTmpDir;
|
||||||
|
|
||||||
|
// Find the necessary directory which need to change owner and group
|
||||||
|
Path needSetOwnerDir = SnapshotDescriptionUtils.getSnapshotRootDir(outputRoot);
|
||||||
|
if (outputFs.exists(needSetOwnerDir)) {
|
||||||
|
if (skipTmp) {
|
||||||
|
needSetOwnerDir = outputSnapshotDir;
|
||||||
|
} else {
|
||||||
|
needSetOwnerDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(outputRoot);
|
||||||
|
if (outputFs.exists(needSetOwnerDir)) {
|
||||||
|
needSetOwnerDir = snapshotTmpDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the snapshot already exists
|
// Check if the snapshot already exists
|
||||||
if (outputFs.exists(outputSnapshotDir)) {
|
if (outputFs.exists(outputSnapshotDir)) {
|
||||||
if (overwrite) {
|
if (overwrite) {
|
||||||
|
@ -976,15 +989,21 @@ public class ExportSnapshot extends Configured implements Tool {
|
||||||
try {
|
try {
|
||||||
LOG.info("Copy Snapshot Manifest");
|
LOG.info("Copy Snapshot Manifest");
|
||||||
FileUtil.copy(inputFs, snapshotDir, outputFs, initialOutputSnapshotDir, false, false, conf);
|
FileUtil.copy(inputFs, snapshotDir, outputFs, initialOutputSnapshotDir, false, false, conf);
|
||||||
if (filesUser != null || filesGroup != null) {
|
|
||||||
setOwner(outputFs, snapshotTmpDir, filesUser, filesGroup, true);
|
|
||||||
}
|
|
||||||
if (filesMode > 0) {
|
|
||||||
setPermission(outputFs, snapshotTmpDir, (short)filesMode, true);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ExportSnapshotException("Failed to copy the snapshot directory: from=" +
|
throw new ExportSnapshotException("Failed to copy the snapshot directory: from=" +
|
||||||
snapshotDir + " to=" + initialOutputSnapshotDir, e);
|
snapshotDir + " to=" + initialOutputSnapshotDir, e);
|
||||||
|
} finally {
|
||||||
|
if (filesUser != null || filesGroup != null) {
|
||||||
|
LOG.warn((filesUser == null ? "" : "Change the owner of " + needSetOwnerDir + " to "
|
||||||
|
+ filesUser)
|
||||||
|
+ (filesGroup == null ? "" : ", Change the group of " + needSetOwnerDir + " to "
|
||||||
|
+ filesGroup));
|
||||||
|
setOwner(outputFs, needSetOwnerDir, filesUser, filesGroup, true);
|
||||||
|
}
|
||||||
|
if (filesMode > 0) {
|
||||||
|
LOG.warn("Change the permission of " + needSetOwnerDir + " to " + filesMode);
|
||||||
|
setPermission(outputFs, needSetOwnerDir, (short)filesMode, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write a new .snapshotinfo if the target name is different from the source name
|
// Write a new .snapshotinfo if the target name is different from the source name
|
||||||
|
|
Loading…
Reference in New Issue