From 818c74469a7aa466fd1104b97affefd2c95b729e Mon Sep 17 00:00:00 2001 From: Johan Van de Wauw Date: Sun, 11 Apr 2021 20:56:58 +0200 Subject: [PATCH 1/2] Add option to skip dumping LFS/attachment files --- cmd/dump.go | 72 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/cmd/dump.go b/cmd/dump.go index 43997c8da8c57..a043648f82d21 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -129,6 +129,14 @@ It can be used for backup and capture Gitea server image to send to maintainer`, Name: "skip-custom-dir", Usage: "Skip custom directory", }, + cli.BoolFlag{ + Name: "skip-lfs-data", + Usage: "Skip LFS data", + }, + cli.BoolFlag{ + Name: "skip-attachment-data", + Usage: "Skip attachment data", + }, cli.GenericFlag{ Name: "type", Value: outputTypeEnum, @@ -214,21 +222,25 @@ func runDump(ctx *cli.Context) error { fatal("Failed to include repositories: %v", err) } - if err := storage.LFS.IterateObjects(func(objPath string, object storage.Object) error { - info, err := object.Stat() - if err != nil { - return err - } + if ctx.IsSet("skip-lfs-data") && ctx.Bool("skip-lfs-data") { + log.Info("Skip dumping LFS data") + } else { + if err := storage.LFS.IterateObjects(func(objPath string, object storage.Object) error { + info, err := object.Stat() + if err != nil { + return err + } - return w.Write(archiver.File{ - FileInfo: archiver.FileInfo{ - FileInfo: info, - CustomName: path.Join("data", "lfs", objPath), - }, - ReadCloser: object, - }) - }); err != nil { - fatal("Failed to dump LFS objects: %v", err) + return w.Write(archiver.File{ + FileInfo: archiver.FileInfo{ + FileInfo: info, + CustomName: path.Join("data", "lfs", objPath), + }, + ReadCloser: object, + }) + }); err != nil { + fatal("Failed to dump LFS objects: %v", err) + } } } @@ -313,21 +325,25 @@ func runDump(ctx *cli.Context) error { } } - if err := storage.Attachments.IterateObjects(func(objPath string, object storage.Object) error { - info, err := object.Stat() - if err != nil { - return err - } + if ctx.IsSet("skip-attachment-data") && ctx.Bool("skip-attachment-data") { + log.Info("Skip dumping attachment data") + } else { + if err := storage.Attachments.IterateObjects(func(objPath string, object storage.Object) error { + info, err := object.Stat() + if err != nil { + return err + } - return w.Write(archiver.File{ - FileInfo: archiver.FileInfo{ - FileInfo: info, - CustomName: path.Join("data", "attachments", objPath), - }, - ReadCloser: object, - }) - }); err != nil { - fatal("Failed to dump attachments: %v", err) + return w.Write(archiver.File{ + FileInfo: archiver.FileInfo{ + FileInfo: info, + CustomName: path.Join("data", "attachments", objPath), + }, + ReadCloser: object, + }) + }); err != nil { + fatal("Failed to dump attachments: %v", err) + } } // Doesn't check if LogRootPath exists before processing --skip-log intentionally, From db71b0363e6aedd127286d1b566c4f15761f0ed2 Mon Sep 17 00:00:00 2001 From: Johan Van de Wauw Date: Sun, 11 Apr 2021 21:48:26 +0200 Subject: [PATCH 2/2] Fix fmt issues --- cmd/dump.go | 60 +++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/cmd/dump.go b/cmd/dump.go index a043648f82d21..458f9f91e017b 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -224,23 +224,21 @@ func runDump(ctx *cli.Context) error { if ctx.IsSet("skip-lfs-data") && ctx.Bool("skip-lfs-data") { log.Info("Skip dumping LFS data") - } else { - if err := storage.LFS.IterateObjects(func(objPath string, object storage.Object) error { - info, err := object.Stat() - if err != nil { - return err - } - - return w.Write(archiver.File{ - FileInfo: archiver.FileInfo{ - FileInfo: info, - CustomName: path.Join("data", "lfs", objPath), - }, - ReadCloser: object, - }) - }); err != nil { - fatal("Failed to dump LFS objects: %v", err) + } else if err := storage.LFS.IterateObjects(func(objPath string, object storage.Object) error { + info, err := object.Stat() + if err != nil { + return err } + + return w.Write(archiver.File{ + FileInfo: archiver.FileInfo{ + FileInfo: info, + CustomName: path.Join("data", "lfs", objPath), + }, + ReadCloser: object, + }) + }); err != nil { + fatal("Failed to dump LFS objects: %v", err) } } @@ -327,23 +325,21 @@ func runDump(ctx *cli.Context) error { if ctx.IsSet("skip-attachment-data") && ctx.Bool("skip-attachment-data") { log.Info("Skip dumping attachment data") - } else { - if err := storage.Attachments.IterateObjects(func(objPath string, object storage.Object) error { - info, err := object.Stat() - if err != nil { - return err - } - - return w.Write(archiver.File{ - FileInfo: archiver.FileInfo{ - FileInfo: info, - CustomName: path.Join("data", "attachments", objPath), - }, - ReadCloser: object, - }) - }); err != nil { - fatal("Failed to dump attachments: %v", err) + } else if err := storage.Attachments.IterateObjects(func(objPath string, object storage.Object) error { + info, err := object.Stat() + if err != nil { + return err } + + return w.Write(archiver.File{ + FileInfo: archiver.FileInfo{ + FileInfo: info, + CustomName: path.Join("data", "attachments", objPath), + }, + ReadCloser: object, + }) + }); err != nil { + fatal("Failed to dump attachments: %v", err) } // Doesn't check if LogRootPath exists before processing --skip-log intentionally,