mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 12:15:43 +01:00
command dump
This commit is contained in:
parent
bb0bc0a240
commit
a641854cad
7 changed files with 43 additions and 28 deletions
24
cmd/dump.go
24
cmd/dump.go
|
@ -12,22 +12,23 @@ import (
|
||||||
"github.com/Unknwon/cae/zip"
|
"github.com/Unknwon/cae/zip"
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/base"
|
"github.com/gogits/gogs/modules/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CmdDump = cli.Command{
|
var CmdDump = cli.Command{
|
||||||
Name: "dump",
|
Name: "dump",
|
||||||
Usage: "Dump Gogs files except database",
|
Usage: "Dump Gogs files and database",
|
||||||
Description: `
|
Description: `Dump compresses all related files and database into zip file.
|
||||||
Dump compresses all related files into zip file except database,
|
It can be used for backup and capture Gogs server image to send to maintainer`,
|
||||||
it can be used for backup and capture Gogs server image to send
|
|
||||||
to maintainer`,
|
|
||||||
Action: runDump,
|
Action: runDump,
|
||||||
Flags: []cli.Flag{},
|
Flags: []cli.Flag{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDump(*cli.Context) {
|
func runDump(*cli.Context) {
|
||||||
base.NewConfigContext()
|
base.NewConfigContext()
|
||||||
|
models.LoadModelsConfig()
|
||||||
|
models.SetEngine()
|
||||||
|
|
||||||
log.Printf("Dumping local repositories...%s", base.RepoRootPath)
|
log.Printf("Dumping local repositories...%s", base.RepoRootPath)
|
||||||
zip.Verbose = false
|
zip.Verbose = false
|
||||||
|
@ -36,6 +37,13 @@ func runDump(*cli.Context) {
|
||||||
log.Fatalf("Fail to dump local repositories: %v", err)
|
log.Fatalf("Fail to dump local repositories: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("Dumping database...")
|
||||||
|
defer os.Remove("gogs-db.sql")
|
||||||
|
if err := models.DumpDatabase("gogs-db.sql"); err != nil {
|
||||||
|
log.Fatalf("Fail to dump database: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Packing dump files...")
|
||||||
z, err := zip.Create("gogs-dump.zip")
|
z, err := zip.Create("gogs-dump.zip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove("gogs-dump.zip")
|
os.Remove("gogs-dump.zip")
|
||||||
|
@ -44,9 +52,13 @@ func runDump(*cli.Context) {
|
||||||
|
|
||||||
execDir, _ := base.ExecDir()
|
execDir, _ := base.ExecDir()
|
||||||
z.AddFile("gogs-repo.zip", path.Join(execDir, "gogs-repo.zip"))
|
z.AddFile("gogs-repo.zip", path.Join(execDir, "gogs-repo.zip"))
|
||||||
|
z.AddFile("gogs-db.sql", path.Join(execDir, "gogs-db.sql"))
|
||||||
z.AddFile("custom/conf/app.ini", path.Join(execDir, "custom/conf/app.ini"))
|
z.AddFile("custom/conf/app.ini", path.Join(execDir, "custom/conf/app.ini"))
|
||||||
z.AddDir("log", path.Join(execDir, "log"))
|
z.AddDir("log", path.Join(execDir, "log"))
|
||||||
z.Close()
|
if err = z.Close(); err != nil {
|
||||||
|
os.Remove("gogs-dump.zip")
|
||||||
|
log.Fatalf("Fail to save gogs-dump.zip: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("Finish dumping!")
|
log.Println("Finish dumping!")
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,7 @@ import (
|
||||||
var CmdFix = cli.Command{
|
var CmdFix = cli.Command{
|
||||||
Name: "fix",
|
Name: "fix",
|
||||||
Usage: "This command for upgrade from old version",
|
Usage: "This command for upgrade from old version",
|
||||||
Description: `
|
Description: `Fix provide upgrade from old version`,
|
||||||
gogs fix provide upgrade from old version`,
|
|
||||||
Action: runFix,
|
Action: runFix,
|
||||||
Flags: []cli.Flag{},
|
Flags: []cli.Flag{},
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,7 @@ var (
|
||||||
var CmdServ = cli.Command{
|
var CmdServ = cli.Command{
|
||||||
Name: "serv",
|
Name: "serv",
|
||||||
Usage: "This command should only be called by SSH shell",
|
Usage: "This command should only be called by SSH shell",
|
||||||
Description: `
|
Description: `Serv provide access auth for repositories`,
|
||||||
Serv provide access auth for repositories`,
|
|
||||||
Action: runServ,
|
Action: runServ,
|
||||||
Flags: []cli.Flag{},
|
Flags: []cli.Flag{},
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@ import (
|
||||||
var CmdUpdate = cli.Command{
|
var CmdUpdate = cli.Command{
|
||||||
Name: "update",
|
Name: "update",
|
||||||
Usage: "This command should only be called by SSH shell",
|
Usage: "This command should only be called by SSH shell",
|
||||||
Description: `
|
Description: `Update get pushed info and insert into database`,
|
||||||
Update get pushed info and insert into database`,
|
|
||||||
Action: runUpdate,
|
Action: runUpdate,
|
||||||
Flags: []cli.Flag{},
|
Flags: []cli.Flag{},
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,7 @@ import (
|
||||||
var CmdWeb = cli.Command{
|
var CmdWeb = cli.Command{
|
||||||
Name: "web",
|
Name: "web",
|
||||||
Usage: "Start Gogs web server",
|
Usage: "Start Gogs web server",
|
||||||
Description: `
|
Description: `Gogs web server is the only thing you need to run,
|
||||||
Gogs web server is the only thing you need to run,
|
|
||||||
and it takes care of all the other things for you`,
|
and it takes care of all the other things for you`,
|
||||||
Action: runWeb,
|
Action: runWeb,
|
||||||
Flags: []cli.Flag{},
|
Flags: []cli.Flag{},
|
||||||
|
|
|
@ -160,3 +160,8 @@ func GetStatistic() (stats Statistic) {
|
||||||
stats.Counter.Release, _ = orm.Count(new(Release))
|
stats.Counter.Release, _ = orm.Count(new(Release))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DumpDatabase dumps all data from database to file system.
|
||||||
|
func DumpDatabase(filePath string) error {
|
||||||
|
return orm.DumpAllToFile(filePath)
|
||||||
|
}
|
||||||
|
|
|
@ -140,7 +140,9 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
|
||||||
|
|
||||||
// AvatarLink returns avatar link by given e-mail.
|
// AvatarLink returns avatar link by given e-mail.
|
||||||
func AvatarLink(email string) string {
|
func AvatarLink(email string) string {
|
||||||
if Service.EnableCacheAvatar {
|
if DisableGravatar {
|
||||||
|
return "/img/avatar_default.jpg"
|
||||||
|
} else if Service.EnableCacheAvatar {
|
||||||
return "/avatar/" + EncodeMd5(email)
|
return "/avatar/" + EncodeMd5(email)
|
||||||
}
|
}
|
||||||
return "//1.gravatar.com/avatar/" + EncodeMd5(email)
|
return "//1.gravatar.com/avatar/" + EncodeMd5(email)
|
||||||
|
|
Loading…
Reference in a new issue