From 39f16a60e12c3e19b6c45fd2cba36d31641be10d Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Tue, 26 Apr 2022 14:42:20 +0000 Subject: [PATCH 1/4] Added addReader to support verbose. --- cmd/dump.go | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/cmd/dump.go b/cmd/dump.go index f72ef05e948f9..c4f82e6271e33 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -7,6 +7,7 @@ package cmd import ( "fmt" + "io" "os" "path" "path/filepath" @@ -25,10 +26,21 @@ import ( "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 { - log.Info("Adding file %s\n", filePath) + log.Info("Adding file %s\n", 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) if err != nil { return err @@ -39,13 +51,7 @@ func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error { return err } - return w.Write(archiver.File{ - FileInfo: archiver.FileInfo{ - FileInfo: fileInfo, - CustomName: filePath, - }, - ReadCloser: file, - }) + return addReader(w, file, fileInfo, filePath, verbose) } func isSubdir(upper, lower string) (bool, error) { @@ -241,13 +247,7 @@ func runDump(ctx *cli.Context) error { return err } - return w.Write(archiver.File{ - FileInfo: archiver.FileInfo{ - FileInfo: info, - CustomName: path.Join("data", "lfs", objPath), - }, - ReadCloser: object, - }) + return addReader(w, object, info, path.Join("data", "lfs", objPath), verbose) }); err != nil { fatal("Failed to dump LFS objects: %v", err) } @@ -341,13 +341,7 @@ func runDump(ctx *cli.Context) error { return err } - return w.Write(archiver.File{ - FileInfo: archiver.FileInfo{ - FileInfo: info, - CustomName: path.Join("data", "attachments", objPath), - }, - ReadCloser: object, - }) + return addReader(w, object, info, path.Join("data", "attachments", objPath), verbose) }); err != nil { fatal("Failed to dump attachments: %v", err) } From 2718d75c82a83c44c6a3324bf950e35fc0f60955 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Tue, 26 Apr 2022 14:42:48 +0000 Subject: [PATCH 2/4] Allow skipping packages. --- cmd/dump.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmd/dump.go b/cmd/dump.go index c4f82e6271e33..2641b96827061 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -142,6 +142,10 @@ It can be used for backup and capture Gitea server image to send to maintainer`, Name: "skip-attachment-data", Usage: "Skip attachment data", }, + cli.BoolFlag{ + Name: "skip-package-data", + Usage: "Skip package data", + }, cli.GenericFlag{ Name: "type", Value: outputTypeEnum, @@ -326,6 +330,7 @@ func runDump(ctx *cli.Context) error { excludes = append(excludes, setting.RepoRootPath) excludes = append(excludes, setting.LFS.Path) excludes = append(excludes, setting.Attachment.Path) + excludes = append(excludes, setting.Packages.Path) excludes = append(excludes, setting.LogRootPath) excludes = append(excludes, absFileName) if err := addRecursiveExclude(w, "data", setting.AppDataPath, excludes, verbose); err != nil { @@ -346,6 +351,19 @@ func runDump(ctx *cli.Context) error { 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, // ensuring that it's clear the dump is skipped whether the directory's initialized // yet or not. From 3024e21b09a4236517c94c202d7cdb659f79680c Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Tue, 26 Apr 2022 14:50:13 +0000 Subject: [PATCH 3/4] Updated docs. --- docs/content/doc/usage/command-line.en-us.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/content/doc/usage/command-line.en-us.md b/docs/content/doc/usage/command-line.en-us.md index 3b75a5c843d20..8cc420ed11b1f 100644 --- a/docs/content/doc/usage/command-line.en-us.md +++ b/docs/content/doc/usage/command-line.en-us.md @@ -313,8 +313,13 @@ in the current directory. - `--tempdir path`, `-t path`: Path to the temporary directory used. Optional. (default: /tmp). - `--skip-repository`, `-R`: Skip the repository dumping. Optional. - `--skip-custom-dir`: Skip dumping of the custom dir. Optional. + - `--skip-lfs-data`: Skip dumping of LFS data. Optional. + - `--skip-attachment-data`: Skip dumping of attachment data. Optional. + - `--skip-package-data`: Skip dumping of package data. Optional. + - `--skip-log`: Skip dumping of log data. Optional. - `--database`, `-d`: Specify the database SQL syntax. Optional. - `--verbose`, `-V`: If provided, shows additional details. Optional. + - `--type`: Set the dump output format. Optional. (default: zip) - Examples: - `gitea dump` - `gitea dump --verbose` From ee467b0c4ca79e3c4117a501969b138b96259d78 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 26 Apr 2022 18:03:15 +0200 Subject: [PATCH 4/4] Update cmd/dump.go Co-authored-by: wxiaoguang --- cmd/dump.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/dump.go b/cmd/dump.go index 2641b96827061..ea41c0c029d9b 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -28,7 +28,7 @@ import ( func addReader(w archiver.Writer, r io.ReadCloser, info os.FileInfo, customName string, verbose bool) error { if verbose { - log.Info("Adding file %s\n", customName) + log.Info("Adding file %s", customName) } return w.Write(archiver.File{