diff --git a/CHANGELOG.md b/CHANGELOG.md index b1871a0c1..929c7b60b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ All notable changes to Gogs are documented in this file. - Unable to use LDAP authentication on ARM machines. [#6761](https://github.com/gogs/gogs/issues/6761) - Unable to choose "Lookup Avatar by mail" in user settings without deleting custom avatar. [#7267](https://github.com/gogs/gogs/pull/7267) +- Mistakenly include the "data" directory under the custom directory in the Docker setup. [#7343](https://github.com/gogs/gogs/pull/7343) ### Removed diff --git a/internal/cmd/backup.go b/internal/cmd/backup.go index 1a9d4f959..63a73a71e 100644 --- a/internal/cmd/backup.go +++ b/internal/cmd/backup.go @@ -101,15 +101,14 @@ func runBackup(c *cli.Context) error { log.Fatal("Failed to include 'db': %v", err) } - // Custom files if !c.Bool("database-only") { - if err = z.AddDir(archiveRootDir+"/custom", conf.CustomDir()); err != nil { - log.Fatal("Failed to include 'custom': %v", err) + // Custom files + err = addCustomDirToBackup(z) + if err != nil { + log.Fatal("Failed to add custom directory to backup: %v", err) } - } - // Data files - if !c.Bool("database-only") { + // Data files for _, dir := range []string{"attachments", "avatars", "repo-avatars"} { dirPath := filepath.Join(conf.Server.AppDataPath, dir) if !com.IsDir(dirPath) { @@ -166,3 +165,33 @@ func runBackup(c *cli.Context) error { log.Stop() return nil } + +func addCustomDirToBackup(z *zip.ZipArchive) error { + customDir := conf.CustomDir() + entries, err := os.ReadDir(customDir) + if err != nil { + return errors.Wrap(err, "list custom directory entries") + } + + for _, e := range entries { + if e.Name() == "data" { + // Skip the "data" directory because it lives under the "custom" directory in + // the Docker setup and will be backed up separately. + log.Trace(`Skipping "data" directory in custom directory`) + continue + } + + add := z.AddFile + if e.IsDir() { + add = z.AddDir + } + err = add( + fmt.Sprintf("%s/custom/%s", archiveRootDir, e.Name()), + filepath.Join(customDir, e.Name()), + ) + if err != nil { + return errors.Wrapf(err, "add %q", e.Name()) + } + } + return nil +} diff --git a/internal/cmd/restore.go b/internal/cmd/restore.go index f38a7fdd1..c71165236 100644 --- a/internal/cmd/restore.go +++ b/internal/cmd/restore.go @@ -119,8 +119,8 @@ func runRestore(c *cli.Context) error { log.Fatal("Failed to import database: %v", err) } - // Custom files if !c.Bool("database-only") { + // Custom files if osutil.IsDir(conf.CustomDir()) { if err = os.Rename(conf.CustomDir(), conf.CustomDir()+".bak"); err != nil { log.Fatal("Failed to backup current 'custom': %v", err) @@ -129,10 +129,8 @@ func runRestore(c *cli.Context) error { if err = os.Rename(filepath.Join(archivePath, "custom"), conf.CustomDir()); err != nil { log.Fatal("Failed to import 'custom': %v", err) } - } - // Data files - if !c.Bool("database-only") { + // Data files _ = os.MkdirAll(conf.Server.AppDataPath, os.ModePerm) for _, dir := range []string{"attachments", "avatars", "repo-avatars"} { // Skip if backup archive does not have corresponding data