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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. },
  42. }
  43. func runRestoreRepository(c *cli.Context) error {
  44. ctx, cancel := installSignals()
  45. defer cancel()
  46. setting.LoadFromExisting()
  47. statusCode, errStr := private.RestoreRepo(
  48. ctx,
  49. c.String("repo_dir"),
  50. c.String("owner_name"),
  51. c.String("repo_name"),
  52. c.StringSlice("units"),
  53. )
  54. if statusCode == http.StatusOK {
  55. return nil
  56. }
  57. log.Fatal("Failed to restore repository: %v", errStr)
  58. return errors.New(errStr)
  59. }