]> source.dussan.org Git - gitea.git/commitdiff
command dump
authorUnknown <joe2010xtmf@163.com>
Mon, 5 May 2014 04:55:17 +0000 (00:55 -0400)
committerUnknown <joe2010xtmf@163.com>
Mon, 5 May 2014 04:55:17 +0000 (00:55 -0400)
cmd/dump.go
cmd/fix.go
cmd/serve.go
cmd/update.go
cmd/web.go
models/models.go
modules/base/tool.go

index c385d586fdb7a9010a64764402b94aa22221ecce..035f7828b8f7c5ce59925699e5bb8146ad8aa16a 100644 (file)
@@ -12,22 +12,23 @@ import (
        "github.com/Unknwon/cae/zip"
        "github.com/codegangsta/cli"
 
+       "github.com/gogits/gogs/models"
        "github.com/gogits/gogs/modules/base"
 )
 
 var CmdDump = cli.Command{
        Name:  "dump",
-       Usage: "Dump Gogs files except database",
-       Description: `
-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`,
+       Usage: "Dump Gogs files and database",
+       Description: `Dump compresses all related files and database into zip file.
+It can be used for backup and capture Gogs server image to send to maintainer`,
        Action: runDump,
        Flags:  []cli.Flag{},
 }
 
 func runDump(*cli.Context) {
        base.NewConfigContext()
+       models.LoadModelsConfig()
+       models.SetEngine()
 
        log.Printf("Dumping local repositories...%s", base.RepoRootPath)
        zip.Verbose = false
@@ -36,6 +37,13 @@ func runDump(*cli.Context) {
                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")
        if err != nil {
                os.Remove("gogs-dump.zip")
@@ -44,9 +52,13 @@ func runDump(*cli.Context) {
 
        execDir, _ := base.ExecDir()
        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.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!")
 }
index 47134cd146498d10765f5b553d1a65cdd746ef00..809c00396f149b131e0513b5fe8f1619de84e3fb 100644 (file)
@@ -14,12 +14,11 @@ import (
 )
 
 var CmdFix = cli.Command{
-       Name:  "fix",
-       Usage: "This command for upgrade from old version",
-       Description: `
-gogs fix provide upgrade from old version`,
-       Action: runFix,
-       Flags:  []cli.Flag{},
+       Name:        "fix",
+       Usage:       "This command for upgrade from old version",
+       Description: `Fix provide upgrade from old version`,
+       Action:      runFix,
+       Flags:       []cli.Flag{},
 }
 
 func runFix(k *cli.Context) {
index 11cf97ad6190d119e09abdadb4ce06e54aee9a67..e881717c3ea052e4ab8a2b4058bbbf11e8a66c69 100644 (file)
@@ -35,12 +35,11 @@ var (
 )
 
 var CmdServ = cli.Command{
-       Name:  "serv",
-       Usage: "This command should only be called by SSH shell",
-       Description: `
-Serv provide access auth for repositories`,
-       Action: runServ,
-       Flags:  []cli.Flag{},
+       Name:        "serv",
+       Usage:       "This command should only be called by SSH shell",
+       Description: `Serv provide access auth for repositories`,
+       Action:      runServ,
+       Flags:       []cli.Flag{},
 }
 
 func newLogger(execDir string) {
index d7efe87f3cdc9061d14812c29aa6645bc6198888..1ab08ca194107d6648f5649d517b74ff2d36e69d 100644 (file)
@@ -17,12 +17,11 @@ import (
 )
 
 var CmdUpdate = cli.Command{
-       Name:  "update",
-       Usage: "This command should only be called by SSH shell",
-       Description: `
-Update get pushed info and insert into database`,
-       Action: runUpdate,
-       Flags:  []cli.Flag{},
+       Name:        "update",
+       Usage:       "This command should only be called by SSH shell",
+       Description: `Update get pushed info and insert into database`,
+       Action:      runUpdate,
+       Flags:       []cli.Flag{},
 }
 
 func newUpdateLogger(execDir string) {
index 1e60501834e85edef3c3a1578a6e0d5199ea8179..87ad908aa8cc91abd3d1ab90c067fbf502236fdb 100644 (file)
@@ -30,8 +30,7 @@ import (
 var CmdWeb = cli.Command{
        Name:  "web",
        Usage: "Start Gogs web server",
-       Description: `
-Gogs web server is the only thing you need to run, 
+       Description: `Gogs web server is the only thing you need to run, 
 and it takes care of all the other things for you`,
        Action: runWeb,
        Flags:  []cli.Flag{},
@@ -153,7 +152,7 @@ func runWeb(*cli.Context) {
                r.Get("/settings/collaboration", repo.Collaboration)
                r.Post("/settings/collaboration", repo.CollaborationPost)
                r.Get("/settings/hooks", repo.WebHooks)
-               r.Get("/settings/hooks/add",repo.WebHooksAdd)
+               r.Get("/settings/hooks/add", repo.WebHooksAdd)
                r.Get("/action/:action", repo.Action)
                r.Get("/issues/new", repo.CreateIssue)
                r.Post("/issues/new", bindIgnErr(auth.CreateIssueForm{}), repo.CreateIssuePost)
index 059435f15ff6e841a11d54b1b329200662dfec62..09b530ced1da37fa5d66278323850842ed7c3411 100644 (file)
@@ -160,3 +160,8 @@ func GetStatistic() (stats Statistic) {
        stats.Counter.Release, _ = orm.Count(new(Release))
        return
 }
+
+// DumpDatabase dumps all data from database to file system.
+func DumpDatabase(filePath string) error {
+       return orm.DumpAllToFile(filePath)
+}
index 9b165b979b9806824887543f8330583aba7af80e..812d7634bf0ed20fc9c387d945592972783342bf 100644 (file)
@@ -140,7 +140,9 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
 
 // AvatarLink returns avatar link by given e-mail.
 func AvatarLink(email string) string {
-       if Service.EnableCacheAvatar {
+       if DisableGravatar {
+               return "/img/avatar_default.jpg"
+       } else if Service.EnableCacheAvatar {
                return "/avatar/" + EncodeMd5(email)
        }
        return "//1.gravatar.com/avatar/" + EncodeMd5(email)