preserve the same dir structure for backup and restore (#3313)

This commit is contained in:
ebozduman
2020-08-25 17:16:48 -07:00
committed by GitHub
parent c58148a421
commit 2a6bdd8164
2 changed files with 26 additions and 13 deletions
+1 -2
View File
@@ -165,8 +165,7 @@ func checkListSyntax(ctx context.Context, cliCtx *cli.Context) ([]string, bool,
// Bucket name empty is a valid error for 'ls myminio',
// treat it as such.
_, buckNameEmpty := err.ToGoError().(BucketNameEmpty)
_, noPath := err.ToGoError().(PathNotFound)
if buckNameEmpty || noPath {
if buckNameEmpty {
continue
}
fatalIf(err.Trace(url), "Unable to stat `"+url+"`.")
+25 -11
View File
@@ -745,15 +745,6 @@ func runMirror(ctx context.Context, cancelMirror context.CancelFunc, srcURL, dst
(srcClt.GetURL().Type == objectStorage &&
srcClt.GetURL().Path == string(srcClt.GetURL().Separator))
// Check if we are only trying to mirror one bucket from source.
if dstClt.GetURL().Type == objectStorage &&
dstClt.GetURL().Path == string(dstClt.GetURL().Separator) && !mirrorAllBuckets {
dstURL = urlJoinPath(dstURL, srcClt.GetURL().Path)
dstClt, err = newClient(dstURL)
fatalIf(err, "Unable to initialize `"+dstURL+"`.")
}
// Create a new mirror job and execute it
mj := newMirrorJob(srcURL, dstURL, mirrorOptions{
isFake: cli.Bool("fake"),
@@ -849,8 +840,31 @@ func runMirror(ctx context.Context, cancelMirror context.CancelFunc, srcURL, dst
return true
}
} else {
mj.status.fatalIf(dstClt.MakeBucket(ctx, cli.String("region"), true, withLock),
"Unable to create bucket at `"+dstURL+"`.")
targetAlias, targetURL, _ := mustExpandAlias(srcURL)
if !strings.HasSuffix(targetURL, string(srcClt.GetURL().Separator)) {
targetURL += string(srcClt.GetURL().Separator)
}
srcClt, err := newClientFromAlias(targetAlias, targetURL)
fatalIf(err.Trace(targetURL), "Unable to initialize target `"+targetURL+"`.")
dstInitialURL := dstURL
for content := range srcClt.List(ctx, ListOptions{isRecursive: false, showDir: DirNone}) {
if content.Err != nil {
errorIf(content.Err.Trace(srcClt.GetURL().String()), "Unable to list folder.")
continue
}
if content.Type.IsDir() {
dstURL = urlJoinPath(dstInitialURL, filepath.Base(content.URL.Path)+string(srcClt.GetURL().Separator))
dstClt, err = newClient(dstURL)
fatalIf(err, "Unable to initialize `"+dstURL+"`.")
mj.status.fatalIf(dstClt.MakeBucket(ctx, cli.String("region"), true, withLock),
"Unable to create bucket at `"+dstURL+"`.")
}
}
}
// object lock configuration set on bucket