mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	Add --skip-db option to dump cmd
This commit is contained in:
		
							
								
								
									
										62
									
								
								cmd/dump.go
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								cmd/dump.go
									
									
									
									
									
								
							@@ -87,6 +87,10 @@ var CmdDump = &cli.Command{
 | 
				
			|||||||
			Name:  "skip-index",
 | 
								Name:  "skip-index",
 | 
				
			||||||
			Usage: "Skip bleve index data",
 | 
								Usage: "Skip bleve index data",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							&cli.BoolFlag{
 | 
				
			||||||
 | 
								Name:  "skip-db",
 | 
				
			||||||
 | 
								Usage: "Skip database",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		&cli.StringFlag{
 | 
							&cli.StringFlag{
 | 
				
			||||||
			Name:  "type",
 | 
								Name:  "type",
 | 
				
			||||||
			Usage: fmt.Sprintf(`Dump output format, default to "zip", supported types: %s`, strings.Join(dump.SupportedOutputTypes, ", ")),
 | 
								Usage: fmt.Sprintf(`Dump output format, default to "zip", supported types: %s`, strings.Join(dump.SupportedOutputTypes, ", ")),
 | 
				
			||||||
@@ -185,35 +189,41 @@ func runDump(ctx *cli.Context) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tmpDir := ctx.String("tempdir")
 | 
						if ctx.Bool("skip-db") {
 | 
				
			||||||
	if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
 | 
							// Ensure that we don't dump the database file that may reside in setting.AppDataPath or elsewhere.
 | 
				
			||||||
		fatal("Path does not exist: %s", tmpDir)
 | 
							dumper.GlobalExcludeAbsPath(setting.Database.Path)
 | 
				
			||||||
	}
 | 
							log.Info("Skipping database")
 | 
				
			||||||
 | 
					 | 
				
			||||||
	dbDump, err := os.CreateTemp(tmpDir, "gitea-db.sql")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		fatal("Failed to create tmp file: %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer func() {
 | 
					 | 
				
			||||||
		_ = dbDump.Close()
 | 
					 | 
				
			||||||
		if err := util.Remove(dbDump.Name()); err != nil {
 | 
					 | 
				
			||||||
			log.Warn("Unable to remove temporary file: %s: Error: %v", dbDump.Name(), err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	targetDBType := ctx.String("database")
 | 
					 | 
				
			||||||
	if len(targetDBType) > 0 && targetDBType != setting.Database.Type.String() {
 | 
					 | 
				
			||||||
		log.Info("Dumping database %s => %s...", setting.Database.Type, targetDBType)
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		log.Info("Dumping database...")
 | 
							tmpDir := ctx.String("tempdir")
 | 
				
			||||||
	}
 | 
							if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
 | 
				
			||||||
 | 
								fatal("Path does not exist: %s", tmpDir)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := db.DumpDatabase(dbDump.Name(), targetDBType); err != nil {
 | 
							dbDump, err := os.CreateTemp(tmpDir, "gitea-db.sql")
 | 
				
			||||||
		fatal("Failed to dump database: %v", err)
 | 
							if err != nil {
 | 
				
			||||||
	}
 | 
								fatal("Failed to create tmp file: %v", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							defer func() {
 | 
				
			||||||
 | 
								_ = dbDump.Close()
 | 
				
			||||||
 | 
								if err := util.Remove(dbDump.Name()); err != nil {
 | 
				
			||||||
 | 
									log.Warn("Unable to remove temporary file: %s: Error: %v", dbDump.Name(), err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = dumper.AddFile("gitea-db.sql", dbDump.Name()); err != nil {
 | 
							targetDBType := ctx.String("database")
 | 
				
			||||||
		fatal("Failed to include gitea-db.sql: %v", err)
 | 
							if len(targetDBType) > 0 && targetDBType != setting.Database.Type.String() {
 | 
				
			||||||
 | 
								log.Info("Dumping database %s => %s...", setting.Database.Type, targetDBType)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								log.Info("Dumping database...")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if err := db.DumpDatabase(dbDump.Name(), targetDBType); err != nil {
 | 
				
			||||||
 | 
								fatal("Failed to dump database: %v", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if err = dumper.AddFile("gitea-db.sql", dbDump.Name()); err != nil {
 | 
				
			||||||
 | 
								fatal("Failed to include gitea-db.sql: %v", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log.Info("Adding custom configuration file from %s", setting.CustomConf)
 | 
						log.Info("Adding custom configuration file from %s", setting.CustomConf)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user