aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/cmd/backup.go41
-rw-r--r--internal/cmd/restore.go6
2 files changed, 37 insertions, 10 deletions
diff --git a/internal/cmd/backup.go b/internal/cmd/backup.go
index 1a9d4f95..63a73a71 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 f38a7fdd..c7116523 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