2020-12-27 11:34:19 +08:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-27 11:34:19 +08:00
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
2025-06-10 14:35:12 +02:00
|
|
|
"context"
|
2022-07-01 15:47:44 +08:00
|
|
|
"strings"
|
2020-12-27 11:34:19 +08:00
|
|
|
|
2021-05-10 15:57:45 +08:00
|
|
|
"code.gitea.io/gitea/modules/private"
|
2020-12-27 11:34:19 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
|
2025-06-10 14:35:12 +02:00
|
|
|
"github.com/urfave/cli/v3"
|
2020-12-27 11:34:19 +08:00
|
|
|
)
|
|
|
|
|
|
2026-03-25 10:53:13 -04:00
|
|
|
func newRestoreRepositoryCommand() *cli.Command {
|
|
|
|
|
return &cli.Command{
|
|
|
|
|
Name: "restore-repo",
|
|
|
|
|
Usage: "Restore the repository from disk",
|
|
|
|
|
Description: "This is a command for restoring the repository data.",
|
|
|
|
|
Action: runRestoreRepository,
|
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
|
&cli.StringFlag{
|
|
|
|
|
Name: "repo_dir",
|
|
|
|
|
Aliases: []string{"r"},
|
|
|
|
|
Value: "./data",
|
|
|
|
|
Usage: "Repository dir path to restore from",
|
|
|
|
|
},
|
|
|
|
|
&cli.StringFlag{
|
|
|
|
|
Name: "owner_name",
|
|
|
|
|
Value: "",
|
|
|
|
|
Usage: "Restore destination owner name",
|
|
|
|
|
},
|
|
|
|
|
&cli.StringFlag{
|
|
|
|
|
Name: "repo_name",
|
|
|
|
|
Value: "",
|
|
|
|
|
Usage: "Restore destination repository name",
|
|
|
|
|
},
|
|
|
|
|
&cli.StringFlag{
|
|
|
|
|
Name: "units",
|
|
|
|
|
Value: "",
|
|
|
|
|
Usage: `Which items will be restored, one or more units should be separated as comma.
|
2020-12-27 11:34:19 +08:00
|
|
|
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
|
2026-03-25 10:53:13 -04:00
|
|
|
},
|
|
|
|
|
&cli.BoolFlag{
|
|
|
|
|
Name: "validation",
|
|
|
|
|
Usage: "Sanity check the content of the files before trying to load them",
|
|
|
|
|
},
|
2020-12-27 11:34:19 +08:00
|
|
|
},
|
2026-03-25 10:53:13 -04:00
|
|
|
}
|
2020-12-27 11:34:19 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-10 14:35:12 +02:00
|
|
|
func runRestoreRepository(ctx context.Context, c *cli.Command) error {
|
2023-06-21 13:50:26 +08:00
|
|
|
setting.MustInstalled()
|
2022-07-01 15:47:44 +08:00
|
|
|
var units []string
|
|
|
|
|
if s := c.String("units"); s != "" {
|
|
|
|
|
units = strings.Split(s, ",")
|
|
|
|
|
}
|
2023-03-29 14:32:26 +08:00
|
|
|
extra := private.RestoreRepo(
|
2021-07-14 15:43:13 +01:00
|
|
|
ctx,
|
|
|
|
|
c.String("repo_dir"),
|
|
|
|
|
c.String("owner_name"),
|
|
|
|
|
c.String("repo_name"),
|
2022-07-01 15:47:44 +08:00
|
|
|
units,
|
2022-01-26 09:45:51 +00:00
|
|
|
c.Bool("validation"),
|
2021-05-10 15:57:45 +08:00
|
|
|
)
|
2023-03-29 14:32:26 +08:00
|
|
|
return handleCliResponseExtra(extra)
|
2020-12-27 11:34:19 +08:00
|
|
|
}
|