2020-12-26 20:34:19 -07:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-05-10 01:57:45 -06:00
|
|
|
"errors"
|
|
|
|
"net/http"
|
2020-12-26 20:34:19 -07:00
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
2021-05-10 01:57:45 -06:00
|
|
|
"code.gitea.io/gitea/modules/private"
|
2020-12-26 20:34:19 -07:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdRestoreRepository represents the available restore a repository sub-command.
|
|
|
|
var CmdRestoreRepository = 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, 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: "",
|
2021-07-14 08:43:13 -06:00
|
|
|
Usage: `Which items will be restored, one or more units should be separated as comma.
|
2020-12-26 20:34:19 -07:00
|
|
|
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-07-14 08:43:13 -06:00
|
|
|
func runRestoreRepository(c *cli.Context) error {
|
|
|
|
ctx, cancel := installSignals()
|
|
|
|
defer cancel()
|
|
|
|
|
2021-12-01 00:50:01 -07:00
|
|
|
setting.LoadFromExisting()
|
2020-12-26 20:34:19 -07:00
|
|
|
|
2021-05-10 01:57:45 -06:00
|
|
|
statusCode, errStr := private.RestoreRepo(
|
2021-07-14 08:43:13 -06:00
|
|
|
ctx,
|
|
|
|
c.String("repo_dir"),
|
|
|
|
c.String("owner_name"),
|
|
|
|
c.String("repo_name"),
|
|
|
|
c.StringSlice("units"),
|
2021-05-10 01:57:45 -06:00
|
|
|
)
|
|
|
|
if statusCode == http.StatusOK {
|
|
|
|
return nil
|
2020-12-26 20:34:19 -07:00
|
|
|
}
|
|
|
|
|
2021-05-10 01:57:45 -06:00
|
|
|
log.Fatal("Failed to restore repository: %v", errStr)
|
|
|
|
return errors.New(errStr)
|
2020-12-26 20:34:19 -07:00
|
|
|
}
|