dump.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package cmd
  5. import (
  6. "log"
  7. "os"
  8. "path"
  9. "github.com/Unknwon/cae/zip"
  10. "github.com/codegangsta/cli"
  11. "github.com/gogits/gogs/modules/base"
  12. )
  13. var CmdDump = cli.Command{
  14. Name: "dump",
  15. Usage: "Dump Gogs files except database",
  16. Description: `
  17. Dump compresses all related files into zip file except database,
  18. it can be used for backup and capture Gogs server image to send
  19. to maintainer`,
  20. Action: runDump,
  21. Flags: []cli.Flag{},
  22. }
  23. func runDump(*cli.Context) {
  24. base.NewConfigContext()
  25. log.Printf("Dumping local repositories...%s", base.RepoRootPath)
  26. zip.Verbose = false
  27. defer os.Remove("gogs-repo.zip")
  28. if err := zip.PackTo(base.RepoRootPath, "gogs-repo.zip", true); err != nil {
  29. log.Fatalf("Fail to dump local repositories: %v", err)
  30. }
  31. z, err := zip.Create("gogs-dump.zip")
  32. if err != nil {
  33. os.Remove("gogs-dump.zip")
  34. log.Fatalf("Fail to create gogs-dump.zip: %v", err)
  35. }
  36. execDir, _ := base.ExecDir()
  37. z.AddFile("gogs-repo.zip", path.Join(execDir, "gogs-repo.zip"))
  38. z.AddFile("custom/conf/app.ini", path.Join(execDir, "custom/conf/app.ini"))
  39. z.AddDir("log", path.Join(execDir, "log"))
  40. z.Close()
  41. log.Println("Finish dumping!")
  42. }