diff options
author | Unknwon <u@gogs.io> | 2018-06-09 17:21:58 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2018-06-09 17:21:58 +0800 |
commit | b538c5345e1271fcaf413b82ba1ece555dd635a5 (patch) | |
tree | 6c129e56dca92bc8a9830b45bfd1a2ae15657929 /cmd/restore.go | |
parent | 694208865b103e6eb96f8e7e1b394037de9a89ba (diff) |
restore: reset original created_unix after insert (#5264)
Diffstat (limited to 'cmd/restore.go')
-rw-r--r-- | cmd/restore.go | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/cmd/restore.go b/cmd/restore.go index db81b8b0..9591b044 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -39,6 +39,10 @@ be skipped and remain unchanged.`, }, } +// lastSupportedVersionOfFormat returns the last supported version of the backup archive +// format that is able to import. +var lastSupportedVersionOfFormat = map[int]string{} + func runRestore(c *cli.Context) error { zip.Verbose = c.Bool("verbose") @@ -49,9 +53,10 @@ func runRestore(c *cli.Context) error { log.Info("Restore backup from: %s", c.String("from")) if err := zip.ExtractTo(c.String("from"), tmpDir); err != nil { - log.Fatal(0, "Fail to extract backup archive: %v", err) + log.Fatal(0, "Failed to extract backup archive: %v", err) } archivePath := path.Join(tmpDir, _ARCHIVE_ROOT_DIR) + defer os.RemoveAll(archivePath) // Check backup version metaFile := path.Join(archivePath, "metadata.ini") @@ -60,12 +65,20 @@ func runRestore(c *cli.Context) error { } metadata, err := ini.Load(metaFile) if err != nil { - log.Fatal(0, "Fail to load metadata '%s': %v", metaFile, err) + log.Fatal(0, "Failed to load metadata '%s': %v", metaFile, err) } backupVersion := metadata.Section("").Key("GOGS_VERSION").MustString("999.0") if version.Compare(setting.AppVer, backupVersion, "<") { log.Fatal(0, "Current Gogs version is lower than backup version: %s < %s", setting.AppVer, backupVersion) } + formatVersion := metadata.Section("").Key("VERSION").MustInt() + if formatVersion == 0 { + log.Fatal(0, "Failed to determine the backup format version from metadata '%s': %s", metaFile, "VERSION is not presented") + } + if formatVersion != _CURRENT_BACKUP_FORMAT_VERSION { + log.Fatal(0, "Backup format version found is %d but this binary only supports %d\nThe last known version that is able to import your backup is %s", + formatVersion, _CURRENT_BACKUP_FORMAT_VERSION, lastSupportedVersionOfFormat[formatVersion]) + } // If config file is not present in backup, user must set this file via flag. // Otherwise, it's optional to set config file flag. @@ -84,18 +97,18 @@ func runRestore(c *cli.Context) error { // Database dbDir := path.Join(archivePath, "db") if err = models.ImportDatabase(dbDir, c.Bool("verbose")); err != nil { - log.Fatal(0, "Fail to import database: %v", err) + log.Fatal(0, "Failed to import database: %v", err) } // Custom files if !c.Bool("database-only") { if com.IsExist(setting.CustomPath) { if err = os.Rename(setting.CustomPath, setting.CustomPath+".bak"); err != nil { - log.Fatal(0, "Fail to backup current 'custom': %v", err) + log.Fatal(0, "Failed to backup current 'custom': %v", err) } } if err = os.Rename(path.Join(archivePath, "custom"), setting.CustomPath); err != nil { - log.Fatal(0, "Fail to import 'custom': %v", err) + log.Fatal(0, "Failed to import 'custom': %v", err) } } @@ -112,11 +125,11 @@ func runRestore(c *cli.Context) error { dirPath := path.Join(setting.AppDataPath, dir) if com.IsExist(dirPath) { if err = os.Rename(dirPath, dirPath+".bak"); err != nil { - log.Fatal(0, "Fail to backup current 'data': %v", err) + log.Fatal(0, "Failed to backup current 'data': %v", err) } } if err = os.Rename(srcPath, dirPath); err != nil { - log.Fatal(0, "Fail to import 'data': %v", err) + log.Fatal(0, "Failed to import 'data': %v", err) } } } @@ -125,11 +138,10 @@ func runRestore(c *cli.Context) error { reposPath := path.Join(archivePath, "repositories.zip") if !c.Bool("exclude-repos") && !c.Bool("database-only") && com.IsExist(reposPath) { if err := zip.ExtractTo(reposPath, path.Dir(setting.RepoRootPath)); err != nil { - log.Fatal(0, "Fail to extract 'repositories.zip': %v", err) + log.Fatal(0, "Failed to extract 'repositories.zip': %v", err) } } - os.RemoveAll(path.Join(tmpDir, _ARCHIVE_ROOT_DIR)) log.Info("Restore succeed!") log.Shutdown() return nil |