|
|
@ -7,6 +7,7 @@ package cmd |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"io" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
@ -25,10 +26,21 @@ import ( |
|
|
|
"github.com/urfave/cli" |
|
|
|
"github.com/urfave/cli" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error { |
|
|
|
func addReader(w archiver.Writer, r io.ReadCloser, info os.FileInfo, customName string, verbose bool) error { |
|
|
|
if verbose { |
|
|
|
if verbose { |
|
|
|
log.Info("Adding file %s\n", filePath) |
|
|
|
log.Info("Adding file %s", customName) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return w.Write(archiver.File{ |
|
|
|
|
|
|
|
FileInfo: archiver.FileInfo{ |
|
|
|
|
|
|
|
FileInfo: info, |
|
|
|
|
|
|
|
CustomName: customName, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
ReadCloser: r, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error { |
|
|
|
file, err := os.Open(absPath) |
|
|
|
file, err := os.Open(absPath) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
@ -39,13 +51,7 @@ func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return w.Write(archiver.File{ |
|
|
|
return addReader(w, file, fileInfo, filePath, verbose) |
|
|
|
FileInfo: archiver.FileInfo{ |
|
|
|
|
|
|
|
FileInfo: fileInfo, |
|
|
|
|
|
|
|
CustomName: filePath, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
ReadCloser: file, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func isSubdir(upper, lower string) (bool, error) { |
|
|
|
func isSubdir(upper, lower string) (bool, error) { |
|
|
@ -136,6 +142,10 @@ It can be used for backup and capture Gitea server image to send to maintainer`, |
|
|
|
Name: "skip-attachment-data", |
|
|
|
Name: "skip-attachment-data", |
|
|
|
Usage: "Skip attachment data", |
|
|
|
Usage: "Skip attachment data", |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
cli.BoolFlag{ |
|
|
|
|
|
|
|
Name: "skip-package-data", |
|
|
|
|
|
|
|
Usage: "Skip package data", |
|
|
|
|
|
|
|
}, |
|
|
|
cli.GenericFlag{ |
|
|
|
cli.GenericFlag{ |
|
|
|
Name: "type", |
|
|
|
Name: "type", |
|
|
|
Value: outputTypeEnum, |
|
|
|
Value: outputTypeEnum, |
|
|
@ -241,13 +251,7 @@ func runDump(ctx *cli.Context) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return w.Write(archiver.File{ |
|
|
|
return addReader(w, object, info, path.Join("data", "lfs", objPath), verbose) |
|
|
|
FileInfo: archiver.FileInfo{ |
|
|
|
|
|
|
|
FileInfo: info, |
|
|
|
|
|
|
|
CustomName: path.Join("data", "lfs", objPath), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
ReadCloser: object, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}); err != nil { |
|
|
|
}); err != nil { |
|
|
|
fatal("Failed to dump LFS objects: %v", err) |
|
|
|
fatal("Failed to dump LFS objects: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -326,6 +330,7 @@ func runDump(ctx *cli.Context) error { |
|
|
|
excludes = append(excludes, setting.RepoRootPath) |
|
|
|
excludes = append(excludes, setting.RepoRootPath) |
|
|
|
excludes = append(excludes, setting.LFS.Path) |
|
|
|
excludes = append(excludes, setting.LFS.Path) |
|
|
|
excludes = append(excludes, setting.Attachment.Path) |
|
|
|
excludes = append(excludes, setting.Attachment.Path) |
|
|
|
|
|
|
|
excludes = append(excludes, setting.Packages.Path) |
|
|
|
excludes = append(excludes, setting.LogRootPath) |
|
|
|
excludes = append(excludes, setting.LogRootPath) |
|
|
|
excludes = append(excludes, absFileName) |
|
|
|
excludes = append(excludes, absFileName) |
|
|
|
if err := addRecursiveExclude(w, "data", setting.AppDataPath, excludes, verbose); err != nil { |
|
|
|
if err := addRecursiveExclude(w, "data", setting.AppDataPath, excludes, verbose); err != nil { |
|
|
@ -341,17 +346,24 @@ func runDump(ctx *cli.Context) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return w.Write(archiver.File{ |
|
|
|
return addReader(w, object, info, path.Join("data", "attachments", objPath), verbose) |
|
|
|
FileInfo: archiver.FileInfo{ |
|
|
|
|
|
|
|
FileInfo: info, |
|
|
|
|
|
|
|
CustomName: path.Join("data", "attachments", objPath), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
ReadCloser: object, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}); err != nil { |
|
|
|
}); err != nil { |
|
|
|
fatal("Failed to dump attachments: %v", err) |
|
|
|
fatal("Failed to dump attachments: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.IsSet("skip-package-data") && ctx.Bool("skip-package-data") { |
|
|
|
|
|
|
|
log.Info("Skip dumping package data") |
|
|
|
|
|
|
|
} else if err := storage.Packages.IterateObjects(func(objPath string, object storage.Object) error { |
|
|
|
|
|
|
|
info, err := object.Stat() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return addReader(w, object, info, path.Join("data", "packages", objPath), verbose) |
|
|
|
|
|
|
|
}); err != nil { |
|
|
|
|
|
|
|
fatal("Failed to dump packages: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Doesn't check if LogRootPath exists before processing --skip-log intentionally,
|
|
|
|
// Doesn't check if LogRootPath exists before processing --skip-log intentionally,
|
|
|
|
// ensuring that it's clear the dump is skipped whether the directory's initialized
|
|
|
|
// ensuring that it's clear the dump is skipped whether the directory's initialized
|
|
|
|
// yet or not.
|
|
|
|
// yet or not.
|
|
|
|