You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

restore_repo.go 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2020 The Gitea 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. "errors"
  7. "net/http"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/private"
  10. "code.gitea.io/gitea/modules/setting"
  11. "github.com/urfave/cli"
  12. )
  13. // CmdRestoreRepository represents the available restore a repository sub-command.
  14. var CmdRestoreRepository = cli.Command{
  15. Name: "restore-repo",
  16. Usage: "Restore the repository from disk",
  17. Description: "This is a command for restoring the repository data.",
  18. Action: runRestoreRepository,
  19. Flags: []cli.Flag{
  20. cli.StringFlag{
  21. Name: "repo_dir, r",
  22. Value: "./data",
  23. Usage: "Repository dir path to restore from",
  24. },
  25. cli.StringFlag{
  26. Name: "owner_name",
  27. Value: "",
  28. Usage: "Restore destination owner name",
  29. },
  30. cli.StringFlag{
  31. Name: "repo_name",
  32. Value: "",
  33. Usage: "Restore destination repository name",
  34. },
  35. cli.StringFlag{
  36. Name: "units",
  37. Value: "",
  38. Usage: `Which items will be restored, one or more units should be separated as comma.
  39. wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
  40. },
  41. cli.BoolFlag{
  42. Name: "validation",
  43. Usage: "Sanity check the content of the files before trying to load them",
  44. },
  45. },
  46. }
  47. func runRestoreRepository(c *cli.Context) error {
  48. ctx, cancel := installSignals()
  49. defer cancel()
  50. setting.LoadFromExisting()
  51. statusCode, errStr := private.RestoreRepo(
  52. ctx,
  53. c.String("repo_dir"),
  54. c.String("owner_name"),
  55. c.String("repo_name"),
  56. c.StringSlice("units"),
  57. c.Bool("validation"),
  58. )
  59. if statusCode == http.StatusOK {
  60. return nil
  61. }
  62. log.Fatal("Failed to restore repository: %v", errStr)
  63. return errors.New(errStr)
  64. }