2022-10-12 11:49:28 +08:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"time"
|
|
|
|
|
2022-10-24 16:51:05 +08:00
|
|
|
"github.com/answerdev/answer/internal/base/data"
|
2022-10-12 11:49:28 +08:00
|
|
|
"xorm.io/xorm/schemas"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DumpAllData dump all database data to sql
|
|
|
|
func DumpAllData(dataConf *data.Database, dumpDataPath string) error {
|
|
|
|
db, err := data.NewDB(false, dataConf)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err = db.Ping(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
name := filepath.Join(dumpDataPath, fmt.Sprintf("answer_dump_data_%s.sql", time.Now().Format("2006-01-02")))
|
|
|
|
return db.DumpAllToFile(name, schemas.MYSQL)
|
|
|
|
}
|