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.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.InitProviderFromExistingFile()
  51. setting.LoadCommonSettings()
  52. var units []string
  53. if s := c.String("units"); s != "" {
  54. units = strings.Split(s, ",")
  55. }
  56. statusCode, errStr := private.RestoreRepo(
  57. ctx,
  58. c.String("repo_dir"),
  59. c.String("owner_name"),
  60. c.String("repo_name"),
  61. units,
  62. c.Bool("validation"),
  63. )
  64. if statusCode == http.StatusOK {
  65. return nil
  66. }
  67. log.Fatal("Failed to restore repository: %v", errStr)
  68. return errors.New(errStr)
  69. }