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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package cmd
  4. import (
  5. "errors"
  6. "net/http"
  7. "strings"
  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. var units []string
  52. if s := c.String("units"); s != "" {
  53. units = strings.Split(s, ",")
  54. }
  55. statusCode, errStr := private.RestoreRepo(
  56. ctx,
  57. c.String("repo_dir"),
  58. c.String("owner_name"),
  59. c.String("repo_name"),
  60. units,
  61. c.Bool("validation"),
  62. )
  63. if statusCode == http.StatusOK {
  64. return nil
  65. }
  66. log.Fatal("Failed to restore repository: %v", errStr)
  67. return errors.New(errStr)
  68. }