code.gitea.io/gitea@v1.21.7/cmd/restore_repo.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package cmd 5 6 import ( 7 "strings" 8 9 "code.gitea.io/gitea/modules/private" 10 "code.gitea.io/gitea/modules/setting" 11 12 "github.com/urfave/cli/v2" 13 ) 14 15 // CmdRestoreRepository represents the available restore a repository sub-command. 16 var CmdRestoreRepository = &cli.Command{ 17 Name: "restore-repo", 18 Usage: "Restore the repository from disk", 19 Description: "This is a command for restoring the repository data.", 20 Action: runRestoreRepository, 21 Flags: []cli.Flag{ 22 &cli.StringFlag{ 23 Name: "repo_dir", 24 Aliases: []string{"r"}, 25 Value: "./data", 26 Usage: "Repository dir path to restore from", 27 }, 28 &cli.StringFlag{ 29 Name: "owner_name", 30 Value: "", 31 Usage: "Restore destination owner name", 32 }, 33 &cli.StringFlag{ 34 Name: "repo_name", 35 Value: "", 36 Usage: "Restore destination repository name", 37 }, 38 &cli.StringFlag{ 39 Name: "units", 40 Value: "", 41 Usage: `Which items will be restored, one or more units should be separated as comma. 42 wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`, 43 }, 44 &cli.BoolFlag{ 45 Name: "validation", 46 Usage: "Sanity check the content of the files before trying to load them", 47 }, 48 }, 49 } 50 51 func runRestoreRepository(c *cli.Context) error { 52 ctx, cancel := installSignals() 53 defer cancel() 54 55 setting.MustInstalled() 56 var units []string 57 if s := c.String("units"); s != "" { 58 units = strings.Split(s, ",") 59 } 60 extra := private.RestoreRepo( 61 ctx, 62 c.String("repo_dir"), 63 c.String("owner_name"), 64 c.String("repo_name"), 65 units, 66 c.Bool("validation"), 67 ) 68 return handleCliResponseExtra(extra) 69 }